EE 1.6.4 and the behavior of ORDER BY SQL generation
Posted: 02 July 2008 03:57 PM   [ Ignore ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1320
Joined  02-12-2003

I have a pretty high profile site we run off of EE and we have been using the sort on multiple columns ability of EE for quite some time.  After upgrading to EE 1.6.4 (from 1.6.3) this afternoon we immediately noticed the sorting was all goofy. 

Here are the details…

Example weblog tag:

{exp:weblog:entries weblog="main" status="open" limit="10" disable="member_data|pagination|trackbacks" orderby="weight|date" sort="asc|desc"}
    {title}
- {entry_date format="%D %d %M %Y %h:%i %A"} PST
{
/exp:weblog:entries}

We would expect from that to get would be any articles marked as Important or Featured first as per the custom field then any articles marked regular after that.  Then those articles should be sorted by date with the most recent ones at the top.  This is the behavior we got previous to 1.6.4.

Instead we got entries from 2003 (our earliest date) all of which are marked as Regular and thus we would expect to not even show since they wouldn’t show if things are being sorted by entry_date desc as we expect.

I turned on the SQL Query display and saw that this query was being used to grab the entries:

SELECT t.entry_id, t.title FROM exp_weblog_titles AS t LEFT JOIN exp_weblogs ON t.weblog_id = exp_weblogs.weblog_id LEFT JOIN exp_weblog_data AS wd ON t.entry_id = wd.entry_id LEFT JOIN exp_members AS m ON m.member_id = t.author_id WHERE t.entry_id !='' AND t.site_id IN ('1') AND t.entry_date < 1215047855 AND (t.expiration_date = 0 || t.expiration_date > 1215047855) AND exp_weblogs.is_user_blog = 'n' AND (t.weblog_id = '1' OR t.weblog_id = '7' ) AND t.status = 'open' AND t.status != 'closed' ORDER BY t.sticky desc, wd.field_id_26 asc, t.entry_id desc, t.entry_date desc, t.entry_id desc LIMIT 0, 10

The issue is obviously the ORDER BY portion:

ORDER BY t.sticky desc, wd.field_id_26 asc, t.entry_id desc, t.entry_date desc, t.entry_id desc LIMIT 0, 10

When I remove the t.entry_id desc but from behind the custom field being sorted by we get the expected results from the query.  If I put it back in we don’t.  So I chased that down to line 2602 of mod.weblog.php.

I changed this:

$end .= " {$sort_array[$key]}, t.entry_id {$sort_array[$key]}";

To this:

$end .= " {$sort_array[$key]}";

And problem solved.  Except that I’m sure you guys made that change for a reason.  smile So while this solves our immediate issue I’d love to get it solved officially or be corrected in terms of how I’m using this so I don’t have to worry about future upgrades.

Jamie

Profile
 
 
Posted: 02 July 2008 05:32 PM   [ Ignore ]   [ # 1 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  11140
Joined  04-29-2002

Hi, Jamie.

I’ll forward this thread off to the guys, and let you know what I find out.

 Signature 

Quick Reference - EE Trial Options - EE Wiki - Docs for updating a build

Profile
MSG
 
 
Posted: 02 July 2008 05:44 PM   [ Ignore ]   [ # 2 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1320
Joined  02-12-2003

Thanks Sue.

Jamie

Profile
 
 
Posted: 03 July 2008 03:43 PM   [ Ignore ]   [ # 3 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  13102
Joined  05-15-2004

Still working on this. We’re trying to replicate it.

 Signature 

Everything will be good in the end. If it’s not good, it’s not the end.

Profile
MSG
 
 
Posted: 07 July 2008 12:16 PM   [ Ignore ]   [ # 4 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1320
Joined  02-12-2003

Thanks for the update Ingmar.

I’m happy to provide a test ground for it if you are unable to replicate it.

I’m wondering if it might be due to the version of MySQL that we are running?  I’m just not sure.  We are on a custom server setup from EngineHosting and I do believe we are running slightly older version of PHP and MySQL than the shared hosting at EngineHosting is now running on.

Jamie

Profile
 
 
Posted: 07 July 2008 12:56 PM   [ Ignore ]   [ # 5 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  13102
Joined  05-15-2004

Certainly a possibility, yes. Do you know which version you are on? phpinfo() should be able to tell you.

 Signature 

Everything will be good in the end. If it’s not good, it’s not the end.

Profile
MSG
 
 
Posted: 07 July 2008 01:38 PM   [ Ignore ]   [ # 6 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1320
Joined  02-12-2003

Ingmar looks like we are running: 4.1.20

Jamie

Profile
 
 
Posted: 07 July 2008 02:08 PM   [ Ignore ]   [ # 7 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  13102
Joined  05-15-2004

Well, that’s not too bad. I might have that still running somewhere, let me check.

 Signature 

Everything will be good in the end. If it’s not good, it’s not the end.

Profile
MSG
 
 
Posted: 08 July 2008 04:55 PM   [ Ignore ]   [ # 8 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  13102
Joined  05-15-2004

Jamie, I had some issues with ORDER BY as well. I am still testing, and have pinged the devs. I’ll post when we know more.

 Signature 

Everything will be good in the end. If it’s not good, it’s not the end.

Profile
MSG
 
 
Posted: 08 July 2008 07:15 PM   [ Ignore ]   [ # 9 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1320
Joined  02-12-2003

Thanks for the update.  Good to hear you were able to get some ORDER BY weirdness as well.

Jamie

Profile
 
 
Posted: 09 July 2008 11:46 AM   [ Ignore ]   [ # 10 ]  
Administrator
Avatar
RankRankRankRankRankRank
Total Posts:  6507
Joined  03-23-2006

Thanks for reporting Jamie.  This will be fixed up in our next build release.  Closing the thread.

 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design

Profile
MSG
 
 
Posted: 09 July 2008 11:48 AM   [ Ignore ]   [ # 11 ]  
Administrator
Avatar
RankRankRankRankRankRank
Total Posts:  6507
Joined  03-23-2006

closing

 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design

Profile
MSG
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 10:33 AM
Total Registered Members: 61011 Total Logged-in Users: 18
Total Topics: 73782 Total Anonymous Users: 13
Total Replies: 398031 Total Guests: 418
Total Posts: 471813    
Members ( View Memberlist )
Newest Members:  furqiekohyeaHRAFFAndrew Doranphantom-am0azamblituxh-nakamurasensakillakynatro