fix(2meet-data-optimizer): join each routed group and drop the redundant GROUP BY
- posts_join joins the flat table of every routed group (a wp_core key next to a post type group no longer fails with "Unknown column") - Flat tables are one row per post (UNIQUE post_id): remove the posts_groupby hook; skip the INNER JOIN status/date copy route for NOT EXISTS, which must match posts without a flat row - Verify: tests/live/run.php router (9/9); qbench Q05 475 == native, no SQL error; price filter EXPLAIN has no Using temporary - PR: PR-061
This commit is contained in:
@@ -214,6 +214,34 @@ class PostQueryRouterTest extends TestCase {
|
||||
$this->assertStringContainsString( 'wpdo_post_wc_product', $join );
|
||||
}
|
||||
|
||||
public function test_posts_join_joins_every_routed_group(): void {
|
||||
$this->set_post_mode( 'aeav_only' );
|
||||
|
||||
$router = new WPDO_Post_Query_Router();
|
||||
$query = $this->make_query( array(
|
||||
'post_type' => 'product',
|
||||
'meta_query' => array(
|
||||
array( 'key' => '_price', 'value' => '50', 'compare' => '>=', 'type' => 'NUMERIC' ),
|
||||
array( 'key' => '_thumbnail_id', 'compare' => 'EXISTS' ),
|
||||
),
|
||||
) );
|
||||
|
||||
$router->pre_get_posts( $query );
|
||||
$join = $router->posts_join( '', $query );
|
||||
$where = $router->posts_where( '', $query );
|
||||
|
||||
$this->assertStringContainsString( 'wpdo_post_wc_product', $join );
|
||||
$this->assertStringContainsString( 'wpdo_post_wp_core', $join );
|
||||
$this->assertStringContainsString( '`wpdoflat_product_wp_core`.`_thumbnail_id` IS NOT NULL', $where );
|
||||
}
|
||||
|
||||
public function test_no_group_by_is_added_for_one_row_per_post_joins(): void {
|
||||
unset( $GLOBALS['_wp_filter_callbacks']['posts_groupby'] );
|
||||
( new WPDO_Post_Query_Router() )->register_hooks();
|
||||
|
||||
$this->assertEmpty( $GLOBALS['_wp_filter_callbacks']['posts_groupby'] ?? array() );
|
||||
}
|
||||
|
||||
public function test_posts_where_appends_condition_for_routed_clause(): void {
|
||||
$this->set_post_mode( 'aeav_only' );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user