[MDEV-20081] INSERT INTO SELECT ignores ORDER Created: 2019-07-17 Updated: 2020-11-03 Resolved: 2020-10-02 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Data Manipulation - Insert |
| Affects Version/s: | 10.3.15, 10.3.16, 10.3.17, 10.3.18, 10.3.20, 10.4.10, 10.4.11, 10.5.0, 10.3, 10.4, 10.5 |
| Fix Version/s: | N/A |
| Type: | Bug | Priority: | Major |
| Reporter: | Alex | Assignee: | Daniel Black |
| Resolution: | Not a Bug | Votes: | 4 |
| Labels: | insert, insert_into, order, rank, value | ||
| Environment: |
Cent OS 7 |
||
| Description |
|
When using ORDER in a INSERT INTO SELECT the ORDER is ignored since 10.3.15, it works in 10.3.14. Example:
Initial data:
When calculating the rank with updating the rank column at the same time with:
Result:
But when only using the inner select the result is correct:
Result:
It looks like the ORDER is completely ignored in the INSERT INTO SELECT. |
| Comments |
| Comment by Alex [ 2019-11-11 ] | ||||||||||||||
|
Bug still available in 10.3.20 | ||||||||||||||
| Comment by Alex [ 2019-11-11 ] | ||||||||||||||
|
Same error in 10.4.10. | ||||||||||||||
| Comment by Alex [ 2020-01-16 ] | ||||||||||||||
|
Same Error on 10.5 and 10.4.11. | ||||||||||||||
| Comment by Daniel Black [ 2020-10-02 ] | ||||||||||||||
|
Well the ORDER BY clause is not ignored
So it does the join first and puts that into a temp table and then sorts the temp table. So i think the results are as expected. With just the SELECT (no INSERT) , it used FILESORT on the table directly, no temp table, hence the results are different.
User variables are numbered as the rows are outputed. | ||||||||||||||
| Comment by Alex [ 2020-10-05 ] | ||||||||||||||
|
If sorting a temp table and filesort produce different results for the same ORDER-statement we are having an other problem. Why has it worked up to 10.3.14? Please reopen this bug. | ||||||||||||||
| Comment by Sergei Golubchik [ 2020-11-03 ] | ||||||||||||||
|
See https://mariadb.com/kb/en/user-defined-variables/
The result of your statement is undefined. So neither outcome is wrong, anything can happen. If you want to count rows use the ROW_NUMBER window function: https://mariadb.com/kb/en/row_number/ |