[MDEV-12743] Wrong results with ROW_NUMBER OVER Created: 2017-05-09 Updated: 2020-08-25 Resolved: 2017-05-09 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer - Window functions |
| Affects Version/s: | 10.2.5 |
| Fix Version/s: | 10.2.5 |
| Type: | Bug | Priority: | Major |
| Reporter: | Will Fong | Assignee: | Vicențiu Ciorbaru |
| Resolution: | Not a Bug | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Description |
|
Hi, When using ROW_NUMBER() OVER(), I expected the row numbers to be based on the result set, independent of the actual data (please let me know if my assumption is incorrect):
However, I seem to be able to hit this edge state where future results don't show that:
Before this happened, I was running a similar test, but on a much larger table:
And in the above example, 5,6,6 are in the wrong order. Restarting MariaDB seems to help resolve this, but it will eventually return. This was tested with 10.2.5 and bb-10.2-compatibility/build-14023. |
| Comments |
| Comment by Vicențiu Ciorbaru [ 2017-05-09 ] |
|
According to the SQL standard, this is expected behaviour. You need to add ORDER BY in the OVER clause, otherwise no certain ordering is guaranteed. If you only want a sorted result by row_number(), you can append an order by clause to your initial SELECT statement, without adding an order by in the OVER clause. |