max_length_for_sort_data mysql Sort length limit of two kinds of sorting algorithm and mysql

SET max_length_for_sort_data = 1024

SHOW VARIABLES LIKE '%max_length_for_sort_data%';

查询:SELECT * FROM CS_COLUMNS ORDER BY table_name,column_name LIMIT 0,100

错误代码: 1815
Internal error: IDB-2015: Sorting length exceeded. Session variable max_length_for_sort_data needs to be set higher.

Time-consuming: 7.171 sec

There are two file mysql sorting algorithms (sorting and two-way one-way sorting), if you need to sort the total size of columns plus the order by column exceeds the max_length_for_sort_data defined byte, mysql will use dual sort, when any the columns need not even use (text.blob time) order by the column will use two-way sorting, (you can use substtring () to convert these columns to be single sorted column).

Mysql algorithm can be influenced by changing the value max_length_for_sort_data selected variables. Because a single fixed sorting buffer is created for each row to be sorted, varchar column max_length_for_sort_data predetermined value is the maximum length, not the actual size of the sort data.

When mysql had to text. When the column is sorted blob, it will ignore the prefix and the remaining values, which is due to allocate a fixed size and configuration to receive data from a copy back to the prefix in the structure of the external memory can be defined using the prefix should be much max_sort_length .

mysql does not really show what kind of algorithm used, if the increased value max_length_for_sort_data, and disk usage rises, cpu usage dropped, the value of sort_merge_passes increased faster than before, perhaps the single use of force order Sorting Algorithm.


Dual sort:
reading order by column and row pointers, sort them, and then the scan list has been sorted, re-read data output from the corresponding list according to the values in the list.
Dual sort of overhead can be tremendous, because he reads the table twice, the second reading will lead to a lot of random IO, for myisam Lai said that in particular, the cost of expensive, myisam use the system call table to extract each row The data.

Single Sort:
read all the columns query needs, according to the order by columns to sort them, and then sort the list after a scan output, its efficiency faster and avoid a second reading. And put into a sequence of random IO IO, but it will use more space because it treats each row stored in the memory.

Guess you like

Origin www.cnblogs.com/zhjh256/p/11605192.html