[MDEV-5007] wrong order by moving from mysql to mariadb Created: 2013-09-10 Updated: 2013-09-10 Resolved: 2013-09-10 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | None |
| Affects Version/s: | 10.0.4 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major |
| Reporter: | roberto spadim | Assignee: | Sergei Golubchik |
| Resolution: | Not a Bug | Votes: | 0 |
| Labels: | None | ||
| Attachments: |
|
||||||||||||||||
| Issue Links: |
|
||||||||||||||||
| Description |
|
Hi guys, i reported this at the problem is... select from (some select order by xxx) limit 0,100 this occur for myisam / aria / innodb / memory engines, in other words i think it's a problem at temporary table creation or somehting like it... WRONG RETURN: (this query was used in mysql without problems with the right order by result, but in mariadb it return wrong order by)
explain (HERE WE DON'T HAVE USING TEMPORARY / FILESORT!!!)
NICE RETURN: (this query runs nice in mariadb and mysql)
explain (HERE WE HAVE USING TEMPORARY / FILESORT)
the only diference at SQL is the order by not inside the () AS tmp_tbl222 alias, maybe the materializations isn't done using the order by (checked by explain at first and second query)... |
| Comments |
| Comment by Sergei Golubchik [ 2013-09-10 ] |
|
The explanation is in the knowledge base But here it is, again: your ORDER BY clause is ignored by the optimizer. It is not a bug. A "table" (and subquery in the FROM clause too) is — according to the SQL standard — an unordered set of rows. Rows in a table (or in a subquery in the FROM clause) do not come in any specific order. That's why the optimizer can ignore the ORDER BY clause that you have specified. In fact, SQL standard does not even allow the ORDER BY clause to appear in this subquery (we allow it, because ORDER BY ... LIMIT ... changes the result, the set of rows, not only their order). You need to treat the subquery in the FROM clause, as a set of rows in some unspecified and undefined order, and put the ORDER BY on the top-level SELECT. |
| Comment by roberto spadim [ 2013-09-10 ] |
|
wow! thanks sergey, now it's easier to understand, i will contact developer to rewrite this query |
| Comment by roberto spadim [ 2013-09-10 ] |
|
it's easy to allow a order by inside the subquery? |
| Comment by roberto spadim [ 2013-09-10 ] |
|
reading the https://mariadb.com/kb/en/why-is-order-by-in-a-from-subquery-ignored/ the only 'easy' work around is add LIMIT 18446744073709551615 (64bits number-1) inside the subquery thanks sergey about the link to knowledge! SELECT * FROM ( |