[wp-trac] [WordPress Trac] #24093: WP_Meta_Query is inefficient when referencing the same keys in "OR" query
WordPress Trac
noreply at wordpress.org
Wed Jul 31 15:45:19 UTC 2013
#24093: WP_Meta_Query is inefficient when referencing the same keys in "OR" query
-------------------------------------------------+-------------------------
Reporter: sc0ttkclark | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting
Component: Query | Review
Severity: normal | Version: 3.5.1
Keywords: has-patch needs-testing dev- | Resolution:
feedback |
-------------------------------------------------+-------------------------
Comment (by F J Kaiser):
Stumbled upon this patch/ticket while updating Codex on
[http://codex.wordpress.org/Class_Reference/WP_Meta_Query WP_Meta_Query].
Nice patch! Finally.
Just one note: If you use a {{{meta_query}}} array
{{{
$query_args = array( 'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'foo_key',
// 'value' => 'foo',
// 'compare' => 'LIKE',
),
array(
'key' => 'bar_key',
),
) );
$meta_query = new WP_Meta_Query();
$meta_query->parse_query_vars( $query_args );
$mq_sql = $meta_query->get_sql(
'post',
$wpdb->posts,
'ID',
null
);
}}}
that only searches for two key/value pairs (so two subarrays), then it
will '''still''' do a join on the native table names like
{{{
INNER JOIN wp_postmeta ON wp_post.ID = wp_postmeta.post_id
}}}
and then do an additional
{{{
INNER JOIN wp_postmeta AS mt{$i} ON (wp_posts.ID = {$alias}{$i}.post_id)
}}}
so the result will look like:
{{{
'join' => string ' INNER JOIN wp_postmeta ON wp_posts.ID =
wp_postmeta.post_id INNER JOIN wp_postmeta AS mt1 ON (wp_posts.ID =
mt1.post_id)'
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/24093#comment:2>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list