For example with MySQL
- How to locate and optimize the SQL query slow
- Causes leftmost matching principle of joint index
- The index is established the better it
First, how to locate and optimize SQL query slow
Specific scenarios detailed analysis, presented here only a general idea
- According slow slow query log positioning SQL
- Explain the use of tools such as analysis sql
- Modify SQL or SQL as far as possible take the index
According slow slow query log positioning SQL
Use the command show variables like '% quer%'; to query related system variables;
- show_query_log: log slow state, off is off, on open; using set global show_query_log = on; open
- show_query_log_file: Slow logging file
- long_query_time: each execution of SQL is that time has slow SQL, as a seconds; use set global long_query_time = 1; Set length
These commands only temporarily change these environment variables, if you want long-term use, you need to modify the configuration file my.ini
Use show status like '% show_queries%'; see the number of slow queries of this session, the session will be open once again cleared.