perf(2meet-data-optimizer): route status and date ordering to entity tables
- TMDO_Post_Query_Router: when a group's post_status / post_date copies are ready and none is NULL (one index probe per group per request), a single-post-type search with explicit statuses and date ordering INNER JOINs the flat table, filters the copied status, orders by the copied post_date and skips GROUP BY. Otherwise the query keeps its old shape. - New posts_orderby filter; bench gains an `entity+copy` variant. - Bench (1M, with SQL_CALC_FOUND_ROWS): scenario 1 p95 3,739 -> 773 ms (p50 670 -> 770); scenario 2 p50 356 -> 448 ms. Without found-rows the same shape runs in 8 ms (PR-030). - Verify: core unit 659 / integration 471 green, phpcs clean - PR: PR-029
This commit is contained in:
@@ -76,6 +76,12 @@ function flat_search( string $table, string $alias, string $conditions ): string
|
||||
. " WHERE 1=1 AND p.post_type = 'hp_listing' AND ((p.post_status = 'publish')){$conditions} GROUP BY p.ID ORDER BY p.post_date DESC LIMIT 0, 20";
|
||||
}
|
||||
|
||||
/** TMDO router shape with post_status / post_date copies (PR-029): INNER JOIN, no GROUP BY. */
|
||||
function flat_copy_search( string $table, string $alias, string $conditions ): string {
|
||||
return 'SELECT SQL_CALC_FOUND_ROWS p.ID FROM `' . P . "posts` p INNER JOIN `" . P . "{$table}` AS `{$alias}` ON (p.ID = `{$alias}`.`post_id`)"
|
||||
. " WHERE 1=1 AND p.post_type = 'hp_listing' AND ((p.post_status = 'publish')){$conditions} AND `{$alias}`.`post_status` IN ('publish') ORDER BY `{$alias}`.`post_date` DESC LIMIT 0, 20";
|
||||
}
|
||||
|
||||
function random_ids( int $count, int $offset, int $max ): string {
|
||||
$ids = array();
|
||||
for ( $i = 0; $i < $count; $i++ ) {
|
||||
@@ -105,6 +111,10 @@ $scenarios = array(
|
||||
[ $lo, $hi ] = $price();
|
||||
return array( flat_search( 'wpdo_post_hp_listing_core', 'e', " AND `e`.`hp_price` BETWEEN '{$lo}' AND '{$hi}'" ), 'SELECT FOUND_ROWS()' );
|
||||
},
|
||||
'entity+copy' => function () use ( $price ) {
|
||||
[ $lo, $hi ] = $price();
|
||||
return array( flat_copy_search( 'wpdo_post_hp_listing_core', 'e', " AND `e`.`hp_price` BETWEEN '{$lo}' AND '{$hi}'" ), 'SELECT FOUND_ROWS()' );
|
||||
},
|
||||
),
|
||||
'2. 價格區間 + verified=1' => array(
|
||||
'native' => function () use ( $price ) {
|
||||
@@ -127,6 +137,10 @@ $scenarios = array(
|
||||
[ $lo, $hi ] = $price();
|
||||
return array( flat_search( 'wpdo_post_hp_listing_core', 'e', " AND `e`.`hp_price` BETWEEN '{$lo}' AND '{$hi}' AND `e`.`hp_verified` = '1'" ), 'SELECT FOUND_ROWS()' );
|
||||
},
|
||||
'entity+copy' => function () use ( $price ) {
|
||||
[ $lo, $hi ] = $price();
|
||||
return array( flat_copy_search( 'wpdo_post_hp_listing_core', 'e', " AND `e`.`hp_price` BETWEEN '{$lo}' AND '{$hi}' AND `e`.`hp_verified` = '1'" ), 'SELECT FOUND_ROWS()' );
|
||||
},
|
||||
),
|
||||
'3. 某 vendor 名下 listing' => array(
|
||||
'post_parent' => fn() => array( 'SELECT SQL_CALC_FOUND_ROWS p.ID FROM `' . P . "posts` p WHERE p.post_parent = " . mt_rand( 1, $vendors ) . " AND p.post_type = 'hp_listing' AND ((p.post_status = 'publish')) ORDER BY p.post_date DESC LIMIT 0, 20", 'SELECT FOUND_ROWS()' ),
|
||||
|
||||
Reference in New Issue
Block a user