[MDEV-18740] ORDER BY DESC + LIMIT x,1 on same columns' values are wrong Created: 2019-02-26  Updated: 2019-02-26  Resolved: 2019-02-26

Status: Closed
Project: MariaDB Server
Component/s: N/A
Affects Version/s: 10.2.22
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Angel T Assignee: Unassigned
Resolution: Not a Bug Votes: 0
Labels: None


 Description   

ASC is correct:
select ID from GAMES order by RateUp АSC limit 0,1
=>ID=1
select ID from GAMES order by RateUp АSC limit 1,1
=>ID=3

DESC is wrong (#2):
select ID from GAMES order by RateUp DESC limit 0,1
=>ID=3 (correct)
select ID from GAMES order by RateUp DESC limit 1,1
=>ID=3 (wrong: must be ID=1 but it isn't)

How to repeat:
Table with two columns ID and RateUp
ID=1,RateUp=0
ID=3,RateUp=0



 Comments   
Comment by Alice Sherepa [ 2019-02-26 ]

The results are correct, as the value of the RateUp is the same, so there is no guarantee which of those 2 rows will be the first and which is the second in the results.

Comment by Angel T [ 2019-02-26 ]

MySQL innodb_version 5.7.12 or innodb_version 5.7.24 are correct, not MariaDB
you tell that their db is wrong and yours is right? is that correct?
And by your words ASC is correct and DESC is correct, but they are different. DO you understand what shi...s you are saying?

Comment by Alice Sherepa [ 2019-02-26 ]

"If multiple rows have identical values in the ORDER BY columns, the server is free to return those rows in any order, and may do so differently depending on the overall execution plan. In other words, the sort order of those rows is nondeterministic with respect to the nonordered columns." https://dev.mysql.com/doc/refman/8.0/en/limit-optimization.html

Comment by Angel T [ 2019-02-26 ]

In MySQL ASC and DESC work as expected.
Here only ASC works, but DESC can return random value which is other word of UNTRUSTED operation in critical situations (including security scenarious)!
=>So if you want your db to be used by serious players, you MUST clean all possibilities of random returning of values (at least).
I am sorry if you can't understand that basic rule.
And I am sorry that you can't see this as bug.
Good luck

Generated at Thu Feb 08 08:46:23 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.