[wp-trac] Re: [WordPress Trac] #9167: query_posts('meta_key=foo')
returns duplicate posts
WordPress Trac
wp-trac at lists.automattic.com
Thu Feb 19 11:26:08 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 scribu):
Replying to [comment:5 filosofo]:
> Replying to [comment:2 scribu]:
> > Can't this be solved by simply using "SELECT DISTINCT(wp_posts.ID)..."
on all queries?
>
> No, that won't help for queries like this, because each ''row'' is
already distinct. Besides, DISTINCT clauses usually have a performance
penalty, and this is the core query of WP.
If you write ''SELECT DISTINCT(*)'', no, it won't; but if you write
''SELECT DISTINCT(wp_posts.ID), wp_posts.post_author, etc.'' it will work.
The only problem is that you couldn't ''SELECT wp_posts.*'' anymore.
I think a subquery also has a performance penalty. Nothing you can do
about that.
By the way, I see that subqueries are already used in WP 2.7.1 (in
query.php):
{{{
$whichcat .= " AND $wpdb->posts.ID NOT IN ( SELECT tr.object_id FROM
$wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON
tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy = 'post_tag'
AND tt.term_id IN ($tag_string) )";
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/9167#comment:6>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list