�PNG  IHDR22?�� pHYs  �� OiCCPPhotoshop ICC profilexڝSgTS�=���BK���KoR RB���&*! J�!��Q�EEȠ�����Q, � ��!���������{�kּ������>���� �H3Q5� �B�������.@� $p�d!s�#�~<<+"��x� �M��0���B�\���t�8K�@z�B�@F���&S�`�cb�P-`'������{[�!�� e�Dh;��V�EX0fK�9�-0IWfH���� � 0Q��){`�##x��F�W<�+��*x��<�$9E�[-qWW.(�I+6aa�@.�y�2�4���������x����6��_-��"bb���ϫp@�t~��,/��;�m��%�h^ �u��f�@����W�p�~<�5�j>{�-�]c�K'Xt����o��(�h���w��?�G�%�fI�q^D$.Tʳ?�D��*�A��,���� �`6�B$��BB d�r`)��B(�Ͱ*`/�@4�Qh��p.�U�=p�a��(�� A�a!ڈb�X#����!�H�$ ɈQ"K�5H1R�T UH�=r9�\F��;�2����G1���Q=� �C��7�F� �dt1�����r�=�6��Ыhڏ>C�0��3�l0.��B�8, �c˱"� ���V����cϱw�E� 6wB aAHXLXN�H� $4� 7 �Q�'"��K�&���b21�XH,#��/{�C�7$�C2'��I��T��F�nR#�,��4H#���dk�9�, +ȅ����3��!�[ �b@q��S�(R�jJ��4�e�2AU��Rݨ�T5�ZB���R�Q��4u�9̓IK�����hh�i��t�ݕN��W���G���w ��Ljg(�gw��L�Ӌ�T071���oUX*�*|�� �J�&�*/T����ު U�U�T��^S}�FU3S� Ԗ�U��P�SSg�;���g�oT?�~Y��Y�L�OC�Q��_�� c�x,!k ��u�5�&���|v*�����=���9C3J3W�R�f?�q��tN �(���~���)�)�4L�1e\k����X�H�Q�G�6������E�Y��A�J'\'Gg����S�Sݧ �M=:��.�k���Dw�n��^��Lo��y���}/�T�m���G X� $� �<�5qo</���QC]�@C�a�a�ᄑ��<��F�F�i�\�$�m�mƣ&&!&KM�M�RM��)�;L;L���͢�֙5�=1�2��כ߷`ZxZ,����eI��Z�Yn�Z9Y�XUZ]�F���%ֻ�����N�N���gð�ɶ�����ۮ�m�}agbg�Ů��}�}��= ���Z~s�r:V:ޚΜ�?}����/gX���3��)�i�S��Ggg�s�󈋉K��.�>.���Ƚ�Jt�q]�z���������ۯ�6�i�ܟ�4�)�Y3s���C�Q��? ��0k߬~OCO�g��#/c/�W�װ��w��a�>�>r��>�<7�2�Y_�7��ȷ�O�o�_��C#�d�z����%g��A�[��z|!��?:�e����A���AA�������!h�쐭!��Α�i�P~���a�a��~ '���W�?�p�X�1�5w��Cs�D�D�Dޛg1O9�-J5*>�.j<�7�4�?�.fY��X�XIlK9.*�6nl������� �{�/�]py�����.,:�@L�N8��A*��%�w%� y��g"/�6ш�C\*N�H*Mz�쑼5y$�3�,幄'���L Lݛ:��v m2=:�1����qB�!M��g�g�fvˬe����n��/��k���Y- �B��TZ(�*�geWf�͉�9���+��̳�ې7�����ᒶ��KW-X潬j9�������(�x��oʿ�ܔ���Ĺd�f�f���-�[����n �ڴ �V����E�/��(ۻ��C���<��e����;?T�T�T�T6��ݵa��n��{��4���[���>ɾ�UUM�f�e�I���?�������m]�Nmq����#�׹���=TR��+�G�����w- 6 U����#pDy��� �� :�v�{���vg/jB��F�S��[b[�O�>����z�G��499�?r����C�d�&����ˮ/~�����јѡ�򗓿m|������������x31^�V���w�w��O�| (�h���SЧ��������c3-� cHRMz%������u0�`:�o�_�F5IDATx��ytUս�?�;���fN$$��@B�!�k��� -*�gE���j�O�kQ�ʠ`U�B_ �AÐ0%�Ȕ�@r3ޛ;߳��$�@��v����^�s����������$��ߢ !�W��5�̱'-٘������4�>�Rƫ$�G��0U�H}�_ _� #��k�MJ/=�9Du *ڲ�k�PQ;0��j|�*�$�^컂脛y���>�z×� B��� ��(�:$�ʔ_�6��C!B����MVx��a��ζyY����j��ƋY2�9�F�{r��r�딟F��Q��hY6��� x��[l��RC��������nt@��;P��3��� F�w��7��:�P���ɋ'���mj���Bƪ�$�Q�L��y��߷g��\���z����v5�p�v$�v櫻�`6~K �Y�X����,�:��"�o�e0II"(��,������l_�C���/4�+f�E�!q��:����u����c��樼.UE�@� �]K�W���$-�h]�JG���Dz)�`��.�A/ ���mᏣc�3jK� �!�>���$�Q�!�_�? \�C2(E �M$Z I{�U���s�ǣ���=��@Բe ޻��W�����@ �w����}�9v,)��.}*|"�s��di���,���G�]W�AC�������|<����[��ߕ������K�*�G nߴ!��‹��J�!��6(L�a)��Am��������;adf��:�xm��nh�;֦I��(���o�C~ډa?�=��s����h��E������xp����)���_���t��W�����´;8���`dz=(��@@�+,�;�`�fhl��XȌ�3,uI�~z(J����� �ZX�A����H'�À�㜦�82|��a�n�z2��I���� ���EY�h�ε<�0�q�{��C��v�˅��?"@��χ�x�WS+��N�~�KQ�J�8ل�� _.W��� !TU{�����,��"�� �;�������HI S� ��))�o�1�H�D� ���� (� ;����"Ҕ��,���� �F=���O��&�Ph>�`���y��߲ &S��P�<��'��1s�1cĂ�N����2)����@�u��tv��<�+�-&�����h��[!FSG���' � z z0��<����8d&�����E0�,��<��"!P�b4��� �{S�����X����.�囤���T��hEF��X�q0"-<����h���]�Py*����F⩍��@v�˂�Y08�� .q��a��s����(!<̫1�3�L�H��7sYW�`��qtu�\7��?�@�Y�� %Ka�x�GZ�*W�P��y�����N0r9��Z�c�%���q,��k�����!!,��>���IB��� �x1�Xu�Y���v-���ֺ��N������JP��a�2`�e5��w��u;�6�i���̃��(K���ťa��(l51��JL��O'%���]���ٖ뿉!��{*�p+f ���i8��D�ȑ���ܩ�M��V��ӟz��x�7Z�1i}�^͜���6e����x��)u�d�ˏ�V�eG�\�X1�����=n�U'�~Y����L�\,�(d!x ,�:�TW8� M`r���@��r+v�Q0��>^;˴�VbF��('����� �*O��i��j�Ӆ����^�S3&� ���{������.ی�� N;��NU%d0�Ce\r"�C�b��&t7N�7��� �ȪD�[%l�۪�$��'m?�A9tI�9>��NVL ��� 6v~M�����ъ�B���0����9$&=ώm��W�0���L���&��E���f�f��'+�9��hv��7,���M��6�D�&�^� �����8 D֮�����o��k^z��O��hP�8q�5d*��YVq3�{��������#LX4�?��jP=3�~�؅c�ݰ�̱�ұ��8̲��2�G�����j��έ�9��w7���U�X�w�85C��?!I&���o&����L���I#�^�eV�,�^t5�k� �xs˛\��U�8��."���{���ǵ�l4��ݼ�;��r"���G�/~���gJV�N糦��ZZ^k+NN�D��I$�=OE�z����|*�*{��%k���G��>�`9��b;�s���8,�qs��c��.b��q�%�>r��n�R�Ƨ�%�,�A��le#�8���}; 21�0�b�&�QX�f���q�00����$>�h�N�'�a3��A���/�r ��L5�8�GԲ'�����w;��c#�q1���h$*��V^�k��QĽ�b:i������� ����H F#�_���,��]g����Ը����`RUU���� ��"�qD���>-��ϤI�~��3�̴�����NZ[[555�eeek7�m����YF#[��Đ��R��i��L�H�r ��@��J-�Pŝ��_|�-��6y��ks�V�U~��6���w.����(��0A� 4��f��� /���C�xŊ�ٳ����z=6�����rg���mKo��o�/����a�g���?'9%9��P��斓��~���L{�� �H��{AW��B��$����v�1b�&Mb�ر��ر#�0`�`xMBp! )Z�Nmo�mZ�g�}�eذaWTVV ���'99��C5��&�&+5�bT>|8��PUUETT����&���t��~TE%��'������b�tEGG;RSS�S�N�v��ѯ��t����u1@�ޚ"f��͈���r'L�Ph��m��ƌ�74o��`�x�q�P���NRSS�X,�����l&&&��MFFA!-��`��ҷ�n��Yuu�����x<I�LB%����KԒ50�!�3�bz�����ʸKL���;---�l6[��`��������Ȏ;�����egg4��!D�T��jWujyZ��������K����%����p�^���X,6��sV=�ܖ����6�3�X ���4ҿ��A2�&����_k�;d�� �VfOIEND�B`�
Warning: session_start(): Session cannot be started after headers have already been sent in /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php on line 124

Warning: Cannot modify header information - headers already sent by (output started at /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php:1) in /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php on line 130

Warning: Cannot modify header information - headers already sent by (output started at /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php:1) in /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php on line 131

Warning: Cannot modify header information - headers already sent by (output started at /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php:1) in /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php on line 132

Warning: Cannot modify header information - headers already sent by (output started at /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php:1) in /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php on line 133

Warning: Cannot modify header information - headers already sent by (output started at /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php:1) in /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php on line 134

Warning: Cannot modify header information - headers already sent by (output started at /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php:1) in /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php on line 135
0x0x
PHP 8.2.31
Preview: OrdersTableStatusUnionQuery.php Size: 11.24 KB
/home/mciraet/www/wp-content/plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableStatusUnionQuery.php
<?php
/**
 * OrdersTableStatusUnionQuery class file.
 */

declare( strict_types=1 );

namespace Automattic\WooCommerce\Internal\DataStores\Orders;

use Automattic\WooCommerce\Utilities\OrderUtil;

defined( 'ABSPATH' ) || exit;

/**
 * Rewrites a "multiple statuses, ordered by creation date" order query (such as the default order admin list
 * screen query) as a UNION ALL of single-status queries.
 *
 * `status IN (...)` prevents the `type_status_date` index from serving a global `date_created_gmt` ordering, so on
 * large stores the optimizer may pick a plan that scans millions of rows for a single page. One branch per (type,
 * status) pair is fully served — filter and order — by `type_status_date`, leaving the outer query to merge a few
 * pre-sorted rows.
 *
 * Eligibility (exact clause match) and the store-size gate are documented at the methods that enforce them
 * (get_sql() and is_enabled()).
 */
class OrdersTableStatusUnionQuery {

	/**
	 * Maximum number of UNION branches (one per type/status pair). Queries needing more branches than this are
	 * left untouched.
	 */
	private const MAX_BRANCHES = 24;

	/**
	 * Maximum row depth (offset + row count). Each UNION branch must fetch up to this many rows, so deeply
	 * paginated queries are left untouched.
	 */
	private const MAX_ROWS = 2_000;

	/**
	 * Minimum number of orders (per the order count cache) matching the queried types and statuses for the rewrite
	 * to be enabled by default. A rough threshold for where a mis-planned query gets user-visible, not a measured
	 * crossover.
	 */
	private const MIN_ORDER_COUNT = 500_000;

	/**
	 * The query being rewritten.
	 *
	 * @var OrdersTableQuery
	 */
	private OrdersTableQuery $query;

	/**
	 * The orders table name.
	 *
	 * @var string
	 */
	private string $orders_table;

	/**
	 * Constructor.
	 *
	 * @param OrdersTableQuery $query The query to rewrite.
	 *
	 * @since 11.0.0
	 */
	public function __construct( OrdersTableQuery $query ) {
		$this->query        = $query;
		$this->orders_table = $query->get_table_name( 'orders' );
	}

	/**
	 * Returns the rewritten SQL query, or NULL when the query is not eligible for the rewrite.
	 *
	 * @param string[] $clauses          Associative array with the final 'fields', 'join', 'where', 'groupby',
	 *                                   'orderby' and 'limits' clauses (the latter four including their keywords).
	 * @param bool     $suppress_filters Whether the query is running with filters suppressed.
	 * @return string|null The rewritten SQL query, or NULL if the query is not eligible.
	 *
	 * @since 11.0.0
	 */
	public function get_sql( array $clauses, bool $suppress_filters ): ?string {
		// Each step either extracts a validated piece of the rewrite or bails out (returns null) when the query
		// isn't the plain "type + status, ordered by creation date" shape we can safely rewrite. The UNION is only
		// assembled once every piece is in place.
		if ( ! $this->has_rewritable_clause_shape( $clauses ) ) {
			return null;
		}

		$direction = $this->extract_order_direction( $clauses['orderby'] ?? '' );
		if ( null === $direction ) {
			return null;
		}

		$limit = $this->extract_limit( $clauses['limits'] ?? '' );
		if ( null === $limit ) {
			return null;
		}

		$types_and_statuses = $this->extract_types_and_statuses();
		if ( null === $types_and_statuses ) {
			return null;
		}
		list( $types, $statuses ) = $types_and_statuses;

		if ( ! $this->is_enabled( $types, $statuses, $suppress_filters ) ) {
			return null;
		}

		if ( ! $this->where_matches_type_status_args( $clauses['where'] ?? '' ) ) {
			return null;
		}

		list( $offset, $row_count ) = $limit;

		return $this->build_union_sql( $types, $statuses, $direction, $offset + $row_count, $clauses['limits'] ?? '' );
	}

	/**
	 * Checks the fixed clauses (selected fields, join, group by) are exactly those of the plain order id list
	 * query. Any join, grouping or extra selected field means the query isn't a candidate for the rewrite.
	 *
	 * @param string[] $clauses The query clauses (see get_sql()).
	 * @return bool Whether the clause shape is rewritable.
	 */
	private function has_rewritable_clause_shape( array $clauses ): bool {
		return '' === ( $clauses['join'] ?? '' )
			&& '' === ( $clauses['groupby'] ?? '' )
			&& "{$this->orders_table}.id" === ( $clauses['fields'] ?? '' );
	}

	/**
	 * Extracts the sort direction from the ORDER BY clause, or NULL when it isn't an ORDER BY on date_created_gmt
	 * alone (the only ordering the type_status_date index can satisfy within each branch).
	 *
	 * @param string $orderby The ORDER BY clause, including the keyword.
	 * @return string|null 'ASC', 'DESC', or NULL when ineligible.
	 */
	private function extract_order_direction( string $orderby ): ?string {
		foreach ( array( 'ASC', 'DESC' ) as $direction ) {
			if ( "ORDER BY {$this->orders_table}.date_created_gmt {$direction}" === $orderby ) {
				return $direction;
			}
		}

		return null;
	}

	/**
	 * Extracts the offset and row count from the LIMIT clause, or NULL when the query is unlimited or too deeply
	 * paginated to benefit (each branch would have to fetch offset + row count rows). The offset + row count cap
	 * also rejects the "unlimited" sentinel row count.
	 *
	 * @param string $limits The LIMIT clause, including the keyword.
	 * @return int[]|null Array of [ offset, row count ], or NULL when ineligible.
	 */
	private function extract_limit( string $limits ): ?array {
		if ( ! preg_match( '/^LIMIT (\d+), (\d+)$/', $limits, $limit_parts ) ) {
			return null;
		}

		$offset    = (int) $limit_parts[1];
		$row_count = (int) $limit_parts[2];

		if ( $row_count < 1 || ( $offset + $row_count ) > self::MAX_ROWS ) {
			return null;
		}

		return array( $offset, $row_count );
	}

	/**
	 * Extracts the queried order types and statuses, or NULL when they don't form a rewritable set: the 'type' and
	 * 'status' args must both be set and contain only non-empty strings, cover at least two statuses (a single
	 * status is already served by the type_status_date index), and stay within the branch cap.
	 *
	 * @return array[]|null Array of [ types, statuses ] (each a list of unique strings), or NULL when ineligible.
	 */
	private function extract_types_and_statuses(): ?array {
		if ( ! $this->query->arg_isset( 'type' ) || ! $this->query->arg_isset( 'status' ) ) {
			return null;
		}

		$types    = array_values( array_unique( (array) $this->query->get( 'type' ) ) );
		$statuses = array_values( array_unique( (array) $this->query->get( 'status' ) ) );

		foreach ( array_merge( $types, $statuses ) as $value ) {
			if ( ! is_string( $value ) || '' === $value ) {
				return null;
			}
		}

		if ( count( $statuses ) < 2 || ( count( $types ) * count( $statuses ) ) > self::MAX_BRANCHES ) {
			return null;
		}

		return array( $types, $statuses );
	}

	/**
	 * Checks the WHERE clause is exactly the one the 'type' and 'status' args generate (same order as
	 * OrdersTableQuery::process_orders_table_query_args()). Any other contribution — other query args or filters —
	 * disqualifies the query. Both columns are of the 'string' type per the OrdersTableDataStore column mappings.
	 *
	 * @param string $where The WHERE clause (without the WHERE keyword).
	 * @return bool Whether the WHERE clause is exactly the type/status one.
	 */
	private function where_matches_type_status_args( string $where ): bool {
		$expected_where = '1=1';
		foreach ( array( 'status', 'type' ) as $arg_key ) {
			$clause          = $this->query->where( $this->orders_table, $arg_key, '=', $this->query->get( $arg_key ), 'string' );
			$expected_where .= " AND ({$clause})";
		}

		return $where === $expected_where;
	}

	/**
	 * Assembles the UNION ALL rewrite from the validated pieces. Each branch is wrapped in a derived table (instead
	 * of using parenthesized UNION members) so that the per-branch ORDER BY + LIMIT is honored across MySQL,
	 * MariaDB and SQLite.
	 *
	 * @param string[] $types       Queried order types.
	 * @param string[] $statuses    Queried order statuses.
	 * @param string   $direction   Sort direction ('ASC' or 'DESC').
	 * @param int      $branch_rows Number of rows each branch must fetch (offset + row count).
	 * @param string   $limits      The outer LIMIT clause, including the keyword.
	 * @return string The rewritten SQL query.
	 */
	private function build_union_sql( array $types, array $statuses, string $direction, int $branch_rows, string $limits ): string {
		global $wpdb;

		$branches = array();

		foreach ( $types as $type ) {
			foreach ( $statuses as $status ) {
				$branch = $wpdb->prepare(
					"SELECT id, date_created_gmt FROM {$this->orders_table} WHERE type = %s AND status = %s ORDER BY date_created_gmt {$direction} LIMIT {$branch_rows}", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
					$type,
					$status
				);

				$branches[] = 'SELECT id, date_created_gmt FROM ( ' . $branch . ' ) union' . count( $branches );
			}
		}

		return 'SELECT id FROM ( ' . implode( ' UNION ALL ', $branches ) . " ) candidates ORDER BY date_created_gmt {$direction} {$limits}";
	}

	/**
	 * Returns whether the rewrite should be used for the given types and statuses.
	 *
	 * Enabled by default once the matching order count reaches MIN_ORDER_COUNT. Counts come from
	 * OrderUtil::get_count_for_type() — the same facade the order admin list screen uses for its status counts —
	 * which reads the order count cache and computes (and caches) the counts on a miss.
	 *
	 * @param string[] $types            Queried order types.
	 * @param string[] $statuses         Queried order statuses.
	 * @param bool     $suppress_filters Whether the query is running with filters suppressed.
	 * @return bool Whether the rewrite should be used.
	 */
	private function is_enabled( array $types, array $statuses, bool $suppress_filters ): bool {
		$orders_count = 0;

		foreach ( $types as $type ) {
			$counts = OrderUtil::get_count_for_type( $type );

			foreach ( $statuses as $status ) {
				$orders_count += $counts[ $status ] ?? 0;
			}
		}

		$enabled = $orders_count >= self::MIN_ORDER_COUNT;

		if ( $suppress_filters ) {
			return $enabled;
		}

		/**
		 * Filters whether a query for multiple order statuses ordered by creation date may be rewritten as a
		 * UNION ALL of single-status queries for performance. The rewrite produces the same results and, even
		 * when enabled here, only applies to queries generated purely from the 'type' and 'status' query args
		 * (no search, meta or field filters), such as the default order admin list screen query.
		 *
		 * Hosts that know their database benefits from the rewrite regardless of store size (or that don't want
		 * to depend on the order count cache being warm) can force-enable it with
		 * add_filter( 'woocommerce_orders_table_query_status_union_optimization', '__return_true' ); the
		 * structural eligibility checks above still apply.
		 *
		 * @param bool             $enabled Whether the rewrite is enabled. Defaults to TRUE only when the cached
		 *                                  number of orders matching the queried types and statuses is at least
		 *                                  500,000; FALSE otherwise (including when the order count cache is cold).
		 * @param OrdersTableQuery $query   The OrdersTableQuery instance.
		 *
		 * @since 11.0.0
		 */
		return (bool) apply_filters( 'woocommerce_orders_table_query_status_union_optimization', $enabled, $this->query );
	}
}

Directory Contents

Dirs: 0 × Files: 13
Name Size Perms Modified Actions
30.17 KB lrw-r--r-- 2026-08-11 10:05:48
Edit Download
36.03 KB lrw-r--r-- 2026-08-11 10:05:48
Edit Download
7.93 KB lrw-r--r-- 2026-08-11 10:05:48
Edit Download
7.45 KB lrw-r--r-- 2026-08-11 10:05:48
Edit Download
20.93 KB lrw-r--r-- 2026-08-11 10:05:48
Edit Download
122.92 KB lrw-r--r-- 2026-08-11 10:05:48
Edit Download
7.67 KB lrw-r--r-- 2026-08-11 10:05:48
Edit Download
8.51 KB lrw-r--r-- 2026-08-11 10:05:48
Edit Download
18.69 KB lrw-r--r-- 2026-08-11 10:05:48
Edit Download
50.00 KB lrw-r--r-- 2026-08-11 10:05:48
Edit Download
6.31 KB lrw-r--r-- 2026-08-11 10:05:48
Edit Download
14.48 KB lrw-r--r-- 2026-08-11 10:05:48
Edit Download
11.24 KB lrw-r--r-- 2026-08-11 10:05:48
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).
© 2026 0xNothings — Secure File Manager. All rights reserved. Built with ❤️ & Tailwind x Dark UI