[wp-trac] Re: [WordPress Trac] #9167: query_posts('meta_key=foo')
returns duplicate posts
WordPress Trac
wp-trac at lists.automattic.com
Wed Feb 18 21:20:27 GMT 2009
#9167: query_posts('meta_key=foo') returns duplicate posts
--------------------------+-------------------------------------------------
Reporter: scribu | Owner: anonymous
Type: defect (bug) | Status: new
Priority: normal | Milestone: 2.7.2
Component: General | Version:
Severity: normal | Keywords:
--------------------------+-------------------------------------------------
Comment(by filosofo):
I think this is a good example of why we need to bump the minimum required
MySQL from 4.0 to at least 4.1. MySQL 4.1 introduced sub-queries, which
would handle well situations like this.
Instead of the current behavior, which LEFT JOINs wp_postmeta to wp_posts
and makes duplicate posts (something like this):
{{{SELECT wp_posts.*, wp_postmeta.meta_value FROM wp_posts LEFT JOIN
wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) WHERE
wp_postmeta.meta_key = 'some_key'}}}
instead, we could use a sub-query and eliminate duplicate posts.
{{{SELECT wp_posts.* FROM wp_posts WHERE wp_posts.ID IN (SELECT post_id
FROM wp_postmeta WHERE meta_key = 'some_key')}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/9167#comment:1>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list