MySQL sorting usage

Source: Internet
Author: User

In MySQL sorting, Sort_merge_passes is added, and MySQL stores the sorting results in the memory in a temporary file. After the records are found, they are sorted again.

MySQL sorting usage:

 
 
  1. mysql> show global status like 'sort%';  
  2. +-------------------+------------+  
  3. | Variable_name | Value |  
  4. +-------------------+------------+  
  5. | Sort_merge_passes | 29 |  
  6. | Sort_range | 37432840 |  
  7. | Sort_rows | 9178691532 |  
  8. | Sort_scan | 1860569 |  
  9. +-------------------+------------+ 

Sort_merge_passes consists of two steps. MySQL first tries to sort data in the memory. The memory size is determined by the system variable Sort_buffer_size. If the memory size is insufficient, all the records will be read to the memory, mySQL stores the sorting results in the memory to a temporary file. After MySQL finds all the records, it sorts the records in the temporary file.

Sort_merge_passes will be added when sorting again. In fact, MySQL uses another temporary file to store the result of re-sorting. Therefore, we usually see that the Sort_merge_passes increase by twice the number of created temporary files.

Because temporary files are used, the speed may be slow. Increasing Sort_buffer_size will reduce the number of times Sort_merge_passes and temporary files are created. However, blindly increasing Sort_buffer_size does not necessarily increase the speed.

In addition, adding the value of read_rnd_buffer_size (3.2.3 is record_rnd_buffer_size) also has some advantages for sorting operations.


 

How to enable MySQL slow Query

Mysql multi-Table query implementation

How to modify MySQL character set in Liunx

Take you to understand mysql Variables

How does one forget the MySQL root User Password?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.