Index Tuning in MySQL

Excessive use of the index will lead to abuse. Therefore, the index also has its disadvantages. While the index greatly increased query speed, while it will reduce the speed of updating the table, such as table INSERT, UPDATE, and DELETE greater than the number of queries, give up the index. Because when you update table, MySQL is not only to save the data, but also save about index file. Indexing files index takes up disk space. Normally this problem is not too serious, but if you're in a big table on a variety of combinations to create the index, the index file will be expanded soon. Index only increases the efficiency of a factor, if your MySQL tables have a large amount of data, we need to take the time to study the establishment of the best index, or optimize the query.

An index does not contain a NULL value in the column
as long as the column contains a NULL value will not be included in the index, as long as there is a combination of an index containing a NULL value, then this column index for this composition is not valid. So we do not let the default fields of the database design value is NULL. create table table_name (c1 varchar (32

2 use a short index
of serial index, if possible, should specify a prefix length. For example, if there is a CHAR (255) column, if the 10 or 20 characters in the front, the only multi-value, then do not index the entire column. Short index can not only speed up the search and save disk space and I / O operations.
CREATE INDEX index_name ON table_name (column (

3 index column sort
MySQL query to use only one index where clause so if the index has been used, then order by the column will not use the index. So do not use the default database sorting operation to sort the case may meet the requirements; try not to sort multiple columns contain, if necessary to create the best composite index to these columns.

4 like statement operation
Generally does not encourage the use of like operations, if not non-use, how to use is also a problem. like "% aaa%" will not use the index, like "aaa%" can use the index.

5 Do not carry out operations in the column
, for example: select * from users where YEAR (will be in operation on each line, which will lead to failure while the index for full table scan, so we can change: select * from users where adddate < '2007-01-01'

 

To sum up, MySQL used only for the following operators index: <, <=, =,>,> =, between, in, and sometimes the like (not begin with wildcard characters% or _ in the case). Theoretically each table which can create up to 16 index, but the amount of data unless it is really a lot, or excessive use of the index is not so fun.

Recommendation: index number of a table is best not more than six, if too much you should consider some of the less frequently used to build the index of the column if necessary.

 

Guess you like

Origin www.cnblogs.com/yucongblog/p/11126803.html