MYSQL query optimization script

Business needs, optimize the period of multi-table query script.
To conclude, take the following steps.

Analysis Statement

  1. Analysis statements to understand the logic, is it possible to optimize the logic.
  2. Query query range, whether it is full-table query, and if so, to try to optimize the query by index.
  3. Check the number of statements, if there are duplicate sub-queries can be combined to see if there are redundant connection table.
  4. Try to use temporary tables can significantly improve query performance.
DROP TABLE IF EXISTS TEMP_NAME;
CREATE TEMPORARY TABLE TEMP_NAME(
 COLUMN1 COLUMN_TYPE,
 COLUMN2 COLUMN_TYPE
);
INSERT INTO TEMP_NAME
SELECT COLUMN1,COLUMN2 FROM DATATABLE;

Guess you like

Origin www.cnblogs.com/mlocvery/p/11599007.html