Bug #91641 | Using RAND() in SELECT query in huge table makes the next query result wrong | ||
---|---|---|---|
Submitted: | 15 Jul 2018 14:41 | Modified: | 18 Jul 2018 13:00 |
Reporter: | jinkli Josin | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server | Severity: | S3 (Non-critical) |
Version: | 5.7.21 | OS: | Any |
Assigned to: | CPU Architecture: | x86 (Mac OSX 10.13.6) |
[15 Jul 2018 14:41]
jinkli Josin
[16 Jul 2018 8:16]
Hartmut Holzgraefe
While this behavior is weird in an interesting way, it is not really wrong. As you did not specify any ORDER the server is free to return rows in any order. Usually this would be the primary key order in this case, but there's no guarantee. What would be interesting now would be the EXPLAIN plan for the "wrong" 2nd query after the first one had been run.
[18 Jul 2018 13:00]
MySQL Verification Team
Hi, I have to agree with my friend Hartmut regarding this report. To quote from the SQL definitions, a relational entity, such as a result set, is an unordered set of tuples, consisting of the unordered set of attributes. This is also addressed in SQL standard from 2011, in the chapter 4.15. This means that a query: SELECT * FROM table WHERE ......; can return rows in any order. If columns are not specified, their sequence is left up to the SQL server. If you specify SELECT id FROM table, then you will get a result set, only with column `id`, but in any order of rows. In order to get rows that are ordered, you have to use ORDER BY clause. That is basic SQL.