mysql sql query optimization optimization

Forever is a small table-driven large tables
optimization principles:
Here Insert Picture Description
2. Optimize the order by statement

  1. order by clause, try to use the Index sort of way, to avoid the use FileSort sort of way. As far as possible to complete a sort operation on the index column, follow the best sort of left index build

  2. Optimization strategies:
    * increase sort_buffer_size parameter settings
    * parameter is set to increase max_length_for_sort_data

    order by Keyword Optimization:
    the SELECT when 1.Order by * is a taboo only Query field required, which is very important, here's influence are:
    (1) When the sum of the Query field size is less than max_length_for_sort_data, but not the sort field TEXT | BLOB type, will use the algorithm ----- single improved sorting, or use the old algorithm ---- multiplex sequencing
    (2) data of the two algorithms are likely to exceed the capacity of sort_buffer, then beyond, tmp file is created to merge sort, resulting in multiple I / O, but with a sort of one-way risk may be considerable, and therefore to improve sort_buffer_size.
    2. Try to improve sort_buffer_size
    ** No matter which algorithm to improve this encroachment will improve efficiency, of course, to increase the capacity of the system according to
    3. try to improve max_length_for_sort_data
    increase this parameter will increase the probability of improved algorithm, but if set too high probability of sort_buffer_size data exceeds the total capacity is increased, obvious symptoms of high disk I / O activity and low processor usage.
    Here Insert Picture Description

3.group by keyword optimization and order by similar:
differences:

  • group by group after the first sort essence, the best left-prefix indexes built in compliance

  • When not using indexed columns to improve sort_buffer_size + increase max_length_for_sort_data

  • Conditions where higher than having, do not write in where having written

     									***帅气的远远啊***
    
Published 39 original articles · won praise 27 · views 10000 +

Guess you like

Origin blog.csdn.net/qq_41585840/article/details/104086610