Interviewer: You talk about the principles of design index

  • Design indexed column is where the best words in the column or columns specified in connection words, rather than those who have been searching out to be as a result of the column

  • , Indexing for those who often need to sort the column grouping and co-operation

  • Use a unique index, but only if fewer duplicate values ​​in the column, the effect of the index was better, so if the column values ​​are unique, the effect is the best, counter-example is indexed to the field of gender, sex and male only female, established the index can not speed up much speed, because no matter what the value of the search, will get about half of the line

  • When the field is too long to build the index, you can create a short index, for example, there is a CHAR (255) column, through observation, that it is not repeated in the first 10 characters of probability, very recognizable, so you can create an index for the first 10 characters of the field, and this also saves space index, query speed may be faster

  • A small amount of data tables, do not be indexed, the index is created in order to optimize the speed of queries, a small amount of data tables, the query would not have been too slow, even though the addition of the index, and will not optimize Obviously, if the data instead, a small amount of the cost of indexing table, maintaining the index structure will be greater

  • The index is not possible, do not over-indexes, each additional index takes up additional disk space, but if the data in the table changes, the index must be adjusted and updated, but this time, more indexes , the longer it takes, it will affect amend speedometer. The argument is a little deeper, Mysql will generate an execution plan, this step will calculate the I / O and CPU costs, and then choose a smaller cost program to be executed because the execution plan is not necessarily very accurate, if coupled with so much index interference is likely to lead to a Mysql select the wrong index

  • Design index to be considered the most left-prefix matching principle

  • If you often use multiple criteria query, it is recommended to use a composite index instead of multiple separate index

  • Instead of creating the index will not need to modify, according to the case, remove the index even those using low frequency is no longer used, so unrelated to modify the index continue to affect the speedometer

  • If you are affected to a large indexed table, try to choose when not busy in the business, avoid online environment updated tables

  • Try the extended index, rather than creating a new index.

Published 297 original articles · won praise 311 · views 50000 +

Guess you like

Origin blog.csdn.net/weixin_38106322/article/details/105215533
Recommended