Mysql finishing the study notes index

The concept of the index:

A dispersion index is stored in a data structure (search) the value of a database table in one or more columns to sort

Why use an index ?

  1. The amount of data indexing can greatly reduce the storage engine to be scanned
  2. The index may become the order of random IO IO
  3. When the index can help us grouping, sorting operation, avoid the use of temporary table

Clustered index:

The physical order of rows in a database table with the logical data (index) is the same as the sequence key

End of the secondary index to the primary key index, and then look for the primary key index values

If innodb not indexed by default will create an implicit primary key index 6bit

As long as the index is continuous, the data storage location on the storage medium is also continuous

 

Joint index

For example, index creation is [name, phone]

  1. Often used in column-major [ leftmost matching principle ]
  2. Selective high priority [ discrete high principles ]
  3. Small column-width [ a minimum of space principles ]

Discrete columns:

 count(distinct column):count(column)

The larger the ratio the better the dispersion, the better the better the selectivity discrete

Leftmost matching principle : 

Keyword index is calculated, must be carried out once from left to right, and can not be skipped

Covering indexes:

If the query returns directly lek by the inode keywords can reduce database IO , the random IO becomes Shun order IO , improve query

Index specifications:

  1. The data length of the index column as little less.
  2. The index is not necessarily better, the more complete the better, we must build a suitable, not too big field, for example, is 11 to phoneNum
  3. Construction of the index, does not allow the field is empty
  4. Available to the prefix matched to the index Like 999%
  5. Where conditions Not in and <> can not use the index
  6. Matching range of values, order by can also be used in the index
  7. Multi-purpose specified column query that returns only the data columns you want, use less select *

 

 

 

 

Guess you like

Origin www.cnblogs.com/weijianxing/p/11586703.html