Home > database >  SQL optimization - mysql
SQL optimization - mysql

Time:10-02

1, optimizing query, indexing, should try to avoid a full table scan, or in conditions where the order by involving field index,
2, try to avoid using inequality sign conditions!=or & lt;> ,
3, reduce the subquery,
5, as far as possible with caution or not in or in the or (can use query merge the union), otherwise it will lead to a full table scan, affect the efficiency,
6, to minimize the associated query, not more than five above the join, consider using a temporary table or table variable for intermediate results,
.

Index creation rules:
Table's primary key, foreign key will be indexed;
A large quantity of data table will be indexed;
Connected to the other table field index;
Often in conditions where fields in the index;
Index based on small fields, text field/super long don't indexed field;
Frequently for database operation table don't build too many indexes;
Reduce the composite index number field;
A large number of duplicate values field don't index;
.
  • Related