Lecture 8---mysql 5.6 order by limit sorting and paging data duplication problem

Foreword:

        Last month, a colleague from the department discovered a bug in the code, which is to use order by limit when querying by paging. Since there is no index added after order by, the found data will be duplicated. This is a problem with versions after MYSQL 5.6 and will not appear in versions before MYSQL 5.5.

 

text:

        I found relevant explanations on the Internet, but I don't quite understand the content in the red box here. According to my understanding, the main advantage is that only a small amount of memory needs to be buffered (I don't know if it's right or not, I need to investigate it later):

        The reason why the instability of heap sorting can lead to "the same value may be sorted out and the order of the data read out is inconsistent" is:

For example: 3 27 36 27

                                                             

If the top of the heap is "3" and output first, then the "27" of the third layer will run to the top of the heap, and then the heap will be stable and continue to output the top of the heap. In this case, the fourth "27" will output the top of the heap before the second "27", so the heap sort is unstable.

                                                        

 

Reference link:

1. MySQL 5.6 order by limit sorting and paging data duplication problem:
http://blog.csdn.net/qq_27317147/article/details/76474624
http://bbs.csdn.net/topics/392190327?page=1
2. Table The disadvantages of too many indexes:
https://zhidao.baidu.com/question/298099003.html
3. The instability of heap sorting:
https://zhidao.baidu.com/question/589205766.html
http://blog .csdn.net/fjqcyq2/article/details/47086769
http://bbs.csdn.net/topics/200016696
4. Introduction to priority queue:
http://blog.csdn.net/stand1210/article/details/52464922
http://blog.csdn.net/stand1210/article/details/52464922 ://blog.csdn.net/u013309870/article/details/71189189
5. MYSQL sort buffer:
http://imysql.cn/2008_09_27_deep_into_mysql_sort_buffer

6. Mysql official website explanation:
https://dev.mysql.com/doc/refman/5.6/en/limit-optimization.html

 

Recommended Books:

"High Performance MYSQL"

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324945243&siteId=291194637