Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#16812 closed defect (bug) (wontfix)

Taxonomy queries without joins ignore order by

Reported by: Chad Killingsworth Owned by: scribu
Milestone: Priority: normal
Severity: normal Version: 3.1
Component: Query Keywords:
Focuses: Cc:


Using a category exclusion term on a query causes the posts to be ordered ascending. Example


I was able to work around the problem by not including a GROUP BY clause when $join variable is empty. I've attached the patch but I'm not sure this is the best solution.

Attachments (1)

query.patch (403 bytes) - added by Chad Killingsworth 4 years ago.
Query.php patch for group by/order by conflict

Download all attachments as: .zip

Change History (17)

@Chad Killingsworth4 years ago

Query.php patch for group by/order by conflict

comment:1 @scribu4 years ago

  • Owner set to scribu
  • Status changed from new to reviewing

(yes, I'm actually reviewing this time)

comment:2 @hakre4 years ago

Thanks for reporting and scribu thanks a lot for your support, please fix if you can for 3.1.1.

comment:3 @scribu4 years ago

Related: #16814

comment:4 @scribu4 years ago

  • Keywords reporter-feedback added

$groupby doesn't affect $orderby in any way, so this is really strange.

Please add the following lines of code somewhere after The Loop and paste here what you get when you go to ?cat=-1

echo '<pre>';

comment:5 @scribu4 years ago

Also, make sure this is not caused by a plugin.

comment:6 @Chad Killingsworth4 years ago

  • Cc chadkilllingsworth@… added

I have a test instance setup and I disabled all plugins before I began testing/debugging the issue. I agree with your statement about the strangeness of the group by/order by conflict. The SQL Statement including the group by clause looks perfectly valid to me and I don't understand why it would affect post ordering in any way.

Here's the query variables and request output:

    [cat] => -1
    [feed] => atom
    [error] => 
    [m] => 0
    [p] => 0
    [post_parent] => 
    [subpost] => 
    [subpost_id] => 
    [attachment] => 
    [attachment_id] => 0
    [name] => 
    [static] => 
    [pagename] => 
    [page_id] => 0
    [second] => 
    [minute] => 
    [hour] => 
    [day] => 0
    [monthnum] => 0
    [year] => 0
    [w] => 0
    [category_name] => 
    [tag] => 
    [tag_id] => 
    [author_name] => 
    [tb] => 
    [paged] => 0
    [comments_popup] => 
    [meta_key] => 
    [meta_value] => 
    [preview] => 
    [s] => 
    [sentence] => 
    [fields] => 
    [category__in] => Array

    [category__not_in] => Array
            [0] => 1

    [category__and] => Array

    [post__in] => Array

    [post__not_in] => Array

    [tag__in] => Array

    [tag__not_in] => Array

    [tag__and] => Array

    [tag_slug__in] => Array

    [tag_slug__and] => Array

    [meta_query] => Array

    [ignore_sticky_posts] => 
    [suppress_filters] => 
    [cache_results] => 1
    [update_post_term_cache] => 1
    [update_post_meta_cache] => 1
    [post_type] => 
    [posts_per_page] => 10
    [nopaging] => 
    [comments_per_page] => 50
    [no_found_rows] => 
    [order] => DESC
    [orderby] => wp_1_posts.post_date DESC
 SELECT SQL_CALC_FOUND_ROWS  wp_1_posts.* FROM wp_1_posts  WHERE 1=1  AND ( wp_1_posts.ID NOT IN (
					SELECT object_id
					FROM wp_1_term_relationships
					WHERE term_taxonomy_id IN (1)
				) ) AND wp_1_posts.post_type = 'post' AND (wp_1_posts.post_status = 'publish' OR wp_1_posts.post_status = 'private') GROUP BY wp_1_posts.ID ORDER BY wp_1_posts.post_date DESC LIMIT 0, 10

comment:7 @scribu4 years ago

It works ok for me.

Try running that query directly through phpMyAdmin and see if it still happens.

comment:8 @Chad Killingsworth4 years ago

On my SQL Server, the results returned in reverse order (i.e. the problem still occurs). I'm running 5.0.51b-community-nt on a 64bit windows server.

comment:9 @Chad Killingsworth4 years ago

It looks like it may be this MySql bug: http://bugs.mysql.com/bug.php?id=32202

I can simply upgrade our MySql server, but since this is a supported version for Word Press, you may want to still work around the issue.

comment:10 @scribu4 years ago

Please try the patch on #16826 and let me know if the bug still occurs.

comment:11 @Chad Killingsworth4 years ago

That patch does indeed fix the issue.

comment:12 @scribu4 years ago

  • Keywords reporter-feedback removed

Cool; two bird with one stone. :)

comment:13 @scribu4 years ago

  • Milestone changed from Awaiting Review to Future Release

comment:14 @scribu4 years ago

  • Milestone changed from Future Release to 3.2

Seems we can't rely on #16826.

comment:15 @ryan4 years ago

Unless we have a simple workaround, this might be wontfix since it is apparently due to a bug in a particular version of MySQL.

comment:16 @scribu4 years ago

  • Keywords has-patch removed
  • Milestone 3.2 deleted
  • Resolution set to wontfix
  • Status changed from reviewing to closed

I've tried some variations on the current patch, but it didn't help.

I think those affected will just have to wait for the next minor release of MySQL or upragrade to MySQL 5.1.

Version 0, edited 4 years ago by scribu (next)
Note: See TracTickets for help on using tickets.