Notes on creating indexes for database learning

1. The index should be established on the fields that are frequently selected. This is because if these columns are rarely used, the presence or absence of an index does not significantly change query speed. On the contrary, due to the addition of indexes, the maintenance speed of the system is reduced and the space requirement is increased.

2. The index should be established on the field whose value is unique. Doing so is the best way to get the most out of the index. , such as the id field of the primary key, the unique name field, and so on. If the index is built on fields with few unique values, such as gender gender fields, few category fields, etc., just indexing has almost no meaning

3. When the modification performance is much greater than the retrieval performance, the index should not be created. Modification performance and retrieval performance are contradictory. When increasing the index, the retrieval performance will be improved, but the modification performance will be reduced. When reducing the index, it will improve the modification performance and reduce the retrieval performance. Therefore, indexes should not be created when the modification performance is much greater than the retrieval performance.

4. Columns appearing in WHERE and JOIN need to be indexed.

5. When querying with wildcard characters % and _ at the beginning, MySQL index is invalid. But this index is valid: select * from table where name like 'xxx%', so it is important to write your SQL carefully.

6. Indexes should not be added to columns defined as text, image and bit data types. Because the amount of data in these columns is either quite large or has very few values.

The leftmost matching principle: Zhihu, the great god, is very easy to understand https://www.zhihu.com/question/36996520

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325644346&siteId=291194637