[MDEV-7485] ORDER BY DESC and LIMIT produces wrong results Created: 2015-01-21 Updated: 2015-01-28 Resolved: 2015-01-28 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 10.0.9, 10.0.15, 10.1.2 |
| Fix Version/s: | N/A |
| Type: | Bug | Priority: | Major |
| Reporter: | Zhixin Zhang | Assignee: | Sergei Petrunia |
| Resolution: | Not a Bug | Votes: | 0 |
| Labels: | optimizer | ||
| Environment: |
ubuntu 12.04 x64, ubuntu 10.04 x64 |
||
| Description |
|
When SELECT using ORDER BY DESC and LIMIT if the sorting column has the same value would produce unexpected results on MariaDB 10.0 and 10.1 series; Reproducible on MariaDB version: 10.0.15, 10.1.2. I just tested on the above versions. How to reproduce:
2. do the same on MariaDB 5.5.33a( expected results)
|
| Comments |
| Comment by Elena Stepanova [ 2015-01-23 ] | ||
|
Same in MySQL 5.6 and current MariaDB 5.5 tree. | ||
| Comment by Sergei Petrunia [ 2015-01-28 ] | ||
|
The output of each individual query is correct. The ordering of rows that have the same value of ORDER BY column is not defined. If you desire that "...LIMIT 0,6" and "... LIMIT 6,6" queries provided a consistent view of data table zzz, include column a in the ORDER BY list:
| ||
| Comment by Sergei Petrunia [ 2015-01-28 ] | ||
|
I've also debugged to see why it happens. Older versions of MySQL/MariaDB resolve the ORDER BY query using "filesort" strategy. That's basically a quicksort which overflows to disk. Newer versions of MySQL/MariaDB use a Priority Queue for optimizing queries with ORDER BY ... LIMIT: https://mariadb.com/kb/en/mariadb/filesort-with-small-limit-optimization/. If I force priority queue not to be used (this can only be done in debugger), the output becomes consistent again. | ||
| Comment by Sergei Petrunia [ 2015-01-28 ] | ||
|
Because of the above, I think this is not a bug. |