[wp-trac] [WordPress Trac] #24093: WP_Meta_Query is inefficient when referencing the same keys in "OR" query

WordPress Trac noreply at wordpress.org
Sun Apr 13 06:32:00 UTC 2014


#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:  needs-refresh meta-query needs-      |  Resolution:
  unit-tests needs-patch                         |     Focuses:
-------------------------------------------------+-------------------------

Comment (by Mr.Defi):

 kevinfodness Your modification works fantastic when You need to query thru
 multiply meta_keys but it breaks order_by meta_key statment.

 Here is my $args fot WP_Query


 {{{
 $args = array(
         'post_type' => 'szkolenia',
         'posts_per_page' => -1,
         'meta_key' => 'crs_date_from',
         'orderby'  => 'meta_value',
         'order' => 'ASC'
 );
 }}}

 This is how mysql query looks after Your patch:


 {{{
 wp_posts.* FROM wp_posts  WHERE 1=1  AND wp_posts.post_type = 'szkolenia'
 AND (wp_posts.post_status = 'publish' OR wp_posts.post_author = 18 AND
 wp_posts.post_status = 'private') AND (wp_postmeta.meta_key =
 'crs_date_from' ) GROUP BY wp_posts.ID ORDER BY wp_postmeta.meta_value ASC
 }}}

 and before patch:


 {{{
 wp_posts.* FROM wp_posts  INNER JOIN wp_postmeta ON (wp_posts.ID =
 wp_postmeta.post_id) WHERE 1=1  AND wp_posts.post_type = 'szkolenia' AND
 (wp_posts.post_status = 'publish' OR wp_posts.post_author = 18 AND
 wp_posts.post_status = 'private') AND (wp_postmeta.meta_key =
 'crs_date_from' ) GROUP BY wp_posts.ID ORDER BY wp_postmeta.meta_value ASC
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/24093#comment:14>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list