High Performance MySQL study notes (under Chapter V)

High-performance indexing strategy (how efficient and practical index)

  1. Separate columns: an index column can not be part of the expression, or function parameter. To form good habits, and always will be alone on one side of the comparison index column breaks.

    示例:select * from xxtable where xxindex +110 =;
    xxindex column is indexed, but the use of the expressions, resulting in failure of the index;

  2. Prefix index and index selectivity:
    premise: when the index long string of great efficiency index also becomes very low .
    Such Remedy: first is to use analogue hash index (understand not introduced), the second is the prefix of the index . As the name suggests, the prefix, the longer the string is taken back from the front part, then as an index, the index reduces the space so as to enhance the efficiency index. The question is, how much appropriate intercept it? At this proposed new term selectivity index , the book also shows, the higher the selectivity of the query index higher efficiency! So what is a selective index it? In fact, very simple, but this new term more difficult to understand, but the actual idea is very popular, that is, when the prefix selection may represent only a record as possible.
    Selective Index is a ratio (for example 5/10, selective index is 0.5), the dividend (5) is not repeated the number of records, the divisor (10) represents the total number of records so we understood unique index index selectivity is 1, the best performance.

    Popular understand: If you want to index: abc, abd, adf, if the prefix index select a (key (1)) is a, you can not distinguish between good three indexes, if you select ab (key (2)), abc and abd indistinguishable, which is equal to 2/3 of the selective index, if the select key (3), is a unique index.
    Create a prefix command: ALTER TABLE pre_index_demo ADD KEY (city (2));

  3. Multi-column index: a future to improve the efficiency of query errors, the column where conditions are indexed and create a separate index on multiple columns, and can not improve query performance MySQL. Sometimes doing so is not a good efficiency, the best efficiency is only a one star index. Better to forget the where clause, focus on optimizing the index order or create a full coverage index. (Practice version 5.6, seems to have been optimized, EXPLAIN extra time did not prompt an index union or intersection)
  4. Select the appropriate index column order: a rule of thumb, when not considering sorting and grouping, the selectivity index (remember how to calculate it?) Up on the front row.
  5. Clustered index : index clustered index is not alone type, but a data storage. The term "cluster" represents key value data rows stored together and compact, a table can have a clustered index, as a data storage only. InnoDB clustered index is actually preserved B-tree index and data lines, a leaf page in the same configuration in the entire data actually stored. InnoDB by the primary key aggregated data, and B-Tree is sequentially stored characteristic, it is inserted into the performance impact Clustered indexes, index. General recommendations a primary key value is independent of the automatic growth of data, but if you use UUID similar as the primary key, clustered index will generate a lot of debris and paging, and very recommended . InnoDB's secondary index, contains the address of the primary key, so the need to use back to the table , which means the primary key is to find based on secondary index, and then query the data line according to the primary key, you need to query twice, is a lack of support.
  6. Covering indexes: If an index containing all the values ​​needed for the query fields and become a covering index.
  7. Redundancy and duplication index: find the index of redundancy and duplication, delete it.

Rationality index can be used to determine the response time, and the index to optimize the actual SQL query.

发布了5 篇原创文章 · 获赞 2 · 访问量 186

Guess you like

Origin blog.csdn.net/qq_15392269/article/details/104578263