Make WordPress Core

Opened 18 years ago

Closed 18 years ago

#3681 closed defect (bug) (wontfix)

Lack of forced GROUP BY or DISTINCT in query.php causes duplicate posts when plugins JOIN on wp_posts.ID = wp_post2cat.post_id

Reported by: ajd777's profile ajd777 Owned by: ryan's profile ryan
Milestone: Priority: normal
Severity: normal Version: 2.1
Component: General Keywords:
Focuses: Cc:

Description

In version 2.0.x DISTINCT was automatically added to all queries that weren't in the admin panel (line 593 of classes.php). However, 2.1 took out this section and doesn't automatically us it or GROUP BY except when viewing single categories (lines 811 (808) and 845 (841) of query.php).

This is an easy fix just add a default filter or force it inside the function to either use GROUP BY ID or DISTINCT by default.

Change History (7)

#1 in reply to: ↑ description @ajd777
18 years ago

Replying to ajd777:

In version 2.0.x DISTINCT was automatically added to all queries that weren't in the admin panel (line 593 of classes.php). However, 2.1 took out this section and doesn't automatically us it or GROUP BY except when viewing single categories (lines 811 (808) and 845 (841) of query.php).

This is an easy fix just add a default filter or force it inside the function to either use GROUP BY ID or DISTINCT by default.

As a temporary fix for plugin authors:

function force_groupby ( $groupby ) {

if ( $groupby == ) {

return ' ID';

}

}

add_filter('posts_groupby', force_groupby);

#2 @markjaquith
18 years ago

  • Owner changed from anonymous to ryan

Does this need to be fixed in core, or is it reasonable to expect plugin authors to provide a GROUP BY ?

#3 @ajd777
18 years ago

I think it should be done automatically in the core, but allow it to be removed if needed: mainly because it is rather unexpected for multiple of the same posts to show up by default.

#4 @ryan
18 years ago

It's a back compat break, which sucks, but removing those speeds up our queries.

#5 @ryan
18 years ago

Maybe process the query after the filters have run and add GROUP BY (if not present) if a post/cat JOIN is done.

#6 @foolswisdom
18 years ago

  • Milestone set to 2.1.1

Setting milestone, so ticket is in front of us, but based on most recent comments by Ryan this will be closed as WONTFIX.

#7 @Nazgul
18 years ago

  • Milestone 2.1.1 deleted
  • Priority changed from high to normal
  • Resolution set to wontfix
  • Severity changed from major to normal
  • Status changed from new to closed

There is a limit to how far you should take backwards compatibility.

I think I agree with Ryan that in this case the speed benefits outweigh the backwards compatibility issues.

Note: See TracTickets for help on using tickets.