perf(2meet-data-optimizer): drive flat-sorted searches from the flat table
- A filtered search ordered by a flat column is rewritten to SELECT STRAIGHT_JOIN … FROM flat INNER JOIN wp_posts, with posts.ID tie-breaks (ours and plugin-appended) read as the equal flat post_id, so MariaDB sorts one table instead of looking every post up and sorting in a temporary table - Only when the routed conditions already require a flat row on the sort group, without the copy route or a selective post filter; filter tmdo_router_flat_first turns it off; split_the_query compares with the same rewrite - Verify: tests/live/run.php router (13/13); integration 522; dev36 page SQL Q07 263→147 ms, Q15 250→142 ms; fe.sh hourly_rate__desc 850→367 ms, ids == native - PR: PR-062c
This commit is contained in:
@@ -381,3 +381,45 @@ TMDO_Live::test(
|
||||
tmdo_live_assert_true( 1 === preg_match( '/^\s*SELECT\s+' . preg_quote( $wpdb->posts, '/' ) . '\.ID\s/', $routed->request ), 'IDs first: ' . $routed->request );
|
||||
}
|
||||
);
|
||||
|
||||
TMDO_Live::test(
|
||||
'a filtered search ordered by a flat column drives from the flat table and matches native',
|
||||
static function () {
|
||||
foreach ( array( 'hp_price', 'hp_hourly_rate' ) as $key ) {
|
||||
TMDO_Live_Fixtures::field( 'post', $key, 'hp_listing' );
|
||||
}
|
||||
TMDO_Live_Fixtures::use_modes( array( 'post' => 'shadow_read' ) );
|
||||
// A price band no seeded listing uses keeps the result to the fixtures.
|
||||
tmdo_live_router_posts(
|
||||
'hp_listing',
|
||||
array(
|
||||
'A' => array( 'hp_price' => '9876501', 'hp_hourly_rate' => '12' ),
|
||||
'B' => array( 'hp_price' => '9876502', 'hp_hourly_rate' => '15' ),
|
||||
'C' => array( 'hp_price' => '9876503' ),
|
||||
)
|
||||
);
|
||||
$args = array(
|
||||
'post_type' => 'hp_listing',
|
||||
'post_status' => 'any',
|
||||
'posts_per_page' => 10,
|
||||
'fields' => 'ids',
|
||||
'suppress_filters' => false,
|
||||
'meta_query' => array( array( 'key' => 'hp_price', 'value' => array( 9876500, 9876510 ), 'compare' => 'BETWEEN', 'type' => 'NUMERIC' ) ),
|
||||
'meta_key' => 'hp_price',
|
||||
'orderby' => 'meta_value_num',
|
||||
'order' => 'DESC',
|
||||
);
|
||||
$native = new WP_Query( $args );
|
||||
$router = new TMDO_Post_Query_Router();
|
||||
$router->register_hooks();
|
||||
try {
|
||||
$routed = new WP_Query( $args );
|
||||
} finally {
|
||||
tmdo_live_router_unhook( $router );
|
||||
}
|
||||
|
||||
tmdo_live_assert_same( array_map( 'intval', $native->posts ), array_map( 'intval', $routed->posts ), 'ids' );
|
||||
tmdo_live_assert_same( $native->found_posts, $routed->found_posts, 'found_posts' );
|
||||
tmdo_live_assert_true( 0 === strpos( ltrim( $routed->request ), 'SELECT STRAIGHT_JOIN' ), 'flat-first: ' . $routed->request );
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user