[MDEV-5049] Unable to fetch correct query Created: 2013-09-21 Updated: 2013-10-03 Resolved: 2013-10-03 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | None |
| Affects Version/s: | 5.5.33 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor |
| Reporter: | Daejuan Jacobs (Inactive) | Assignee: | Elena Stepanova |
| Resolution: | Not a Bug | Votes: | 0 |
| Labels: | None | ||
| Environment: |
Debian Wheezy, PHP 5.4 |
||
| Attachments: |
|
| Description |
|
There's a query that works as designed using MySQL. But trying to utilize MariaDB is doesn't seem to work. No visible error messages, it's as if the query isn't there. The query fetches the "last reply" of a ticket, displaying the date/user. The last reply is calculated on the fly. Link to discussion: http://www.blesta.com/forums/index.php?/topic/614-support-manager-last-reply/ |
| Comments |
| Comment by Elena Stepanova [ 2013-09-21 ] |
|
Hi, If I understand the problem correctly, all complications aside, you have the following: drop table if exists t1; and you rely on the fact that the following query will always return the biggest value of last_reply_date for each id: select temp.* from ( select * from t1 order by last_reply_date desc ) temp group by temp.id; This is a wrong expectation. The MySQL (not MariaDB, but MySQL) manual is very specific about it: <quote> This is what you have in the initial query. You have a select list of non-aggregated columns (`temp`.* ) and only `temp`.`id` in the GROUP BY clause. Thus, your query is subject to this described non-deterministic behavior. It is a pure coincidence that currently MySQL chooses to execute such queries in the way that it does pick a highest value. It can change any time, with any bug fix, and won't even require a new GA version because it would not be a change in the existing functionality. MariaDB 5,5 optimizer is more advanced and attempts to execute the query differently, thus the non-deterministic result turns out to be different. You can try to temporarily switch back to the old behavior by setting the following in your MariaDB config file: To see if it helps, you can try it at runtime first, by running and seeing if you started getting expected results after that. But I can't emphasize it strongly enough, it is just a temporary and highly unreliable solution. Whether you choose MySQL or MariaDB at the end, the non-deterministic behavior will stay such. There have been many things that recently changed in MySQL 5.6 comparing to MySQL 5.5 that made people complain about regressions and incompatibility, while in fact they were legitimate changes touching scenarios where people used to rely on pure luck. |
| Comment by Daejuan Jacobs (Inactive) [ 2013-09-21 ] |
|
Thanks for the fast response. I can verify that your suggestion gives the intended results. I will attempt to discuss with the developers a better way to handle such a query. |
| Comment by Elena Stepanova [ 2013-09-21 ] |
|
There might be some other implicit expectations for this query that i'm of course not aware of, or any other reasons to make it the way it is now; but from a quick look at it it's far from obvious why they would need to use a subquery in the select list at all, since the outer query doesn't seem to filter it out any further. It seems they could at the very least consider removing the outer subquery and order by from the inner one, and applying "GROUP BY id" directly to the inner query instead, and using MAX(`support_replies`.`date_added`) AS `last_reply_date` in the field list. It won't make the query deterministic in regard to other fields that it pulls, but at least it should ensure that it takes the highest last_reply_date indeed. For other fields, it depends on how they are used later. |
| Comment by Elena Stepanova [ 2013-10-03 ] |
|
If I understand correctly from the thread on www.blesta.com, some measures have been taken to resolve the problem on the application side. I am not authorized to download the php file, so I can't see what exactly has been done, but judging by the text, the plan was to do a full group by, which is of course a good plan. |