MySQL's high-performance reading notes

1. B-Tree index (When you create multiple indexes, the index column order is very important, the first is the most important index of the column)

a. B-Tree index value for full-match (and all index string matching), leftmost prefix matching (using only the first row entry index), the prefix match column (column matches the beginning part of an index, such as lookup in J the beginning of the name of person), the matching value range (the range of the index column from xx to xx), and a column match exactly matches a column range

. B some limitations: the leftmost index column must start looking from, or can not use the index, such as if you do not use the first row and column index using only the second and third column of the index, will not work; if the query has an index Find a range of columns rather than precise match, it can not be indexed columns to the right of use of the index

2. The hash index hash index

a. corresponding to the index itself simply stored hash value, so the structure of the index is very compact, so the speed is very fast hash lookup

. B restrictions: hash index and contains only a pointer to the hash value which line, field values ​​are not stored, but it is not directly value pointer value according to find, but the speed of accessing memory in a row very quickly, so no serious problem; not in accordance with the hash index data stored in index order, it can not be used for sorting; hash index column index portion match lookup is not supported, such as the establishment hash index in the two a, B, if only a column with, you can not use the index; hash indexes only support the equivalent comparative inquiry, does not support any range queries; many hash collisions, then you need to delete a line to traverse each line corresponds to the hash worth a linked list to find and delete the line , the cost of maintenance operations do

c. InnoDB engine has a special feature "adaptive hash index", when the engine is noted that some index values ​​are used so often, it will then create a hash index in memory based on the B-Tree index. This is a fully automated, internal behavior, the user can not control or configuration, but there needs to be shut down

3. Benefits Index

a. greatly reduce the amount of data to scan server

b. Index servers can help avoid sorts and temporary tables

c. index can be random I / O becomes sequential I / O

4. Some indexing strategy

. A prefix index (the index column may consider if the data are very long), indexed only the first few characters of a column of data, such as indexing the first seven characters of the city name: ALTER TABLE sakila.city_demo ADD KEY (city (7)); drawback is that do not use the prefix index ORDER BY and GROUP BY, can not do the scanning coverage

b. If you want to index more than one column, the index column order is very important. A rule of thumb: the highest selective index of the column into the forefront of most (selective calculation see P155)

c. InnoDB's primary key index is clustered, each of which holds the primary key column, the transaction ID, and other rollback pointer of the remaining columns, we can say InnoDB primary key index itself is a "table." InnoDB index and secondary (i.e., non-primary key index) non-clustered, which contains only the primary key and the secondary index value columns, so the first time been looking for the primary key value, and then according to the primary key values primary key index lookup data inside the target row, a B-Tree to find two

d. MyISAM primary key index and a secondary index are non-clustered, MyISAM itself comes with a line number, and the primary key index is stored in a secondary index line number plus the value of a primary key column / two row index column value

 

Guess you like

Origin www.cnblogs.com/LittleMike/p/11779473.html
Recommended