Index is help MySQL Data structure for efficient data acquisition .
The purpose of indexing is to improve query efficiency , Similar to dictionary , It can be understood as “ Arrange order well Of Quick search data structure ”.
Database besides data itself , It also maintains a data structure that satisfies a specific query algorithm , These data structures point to data in some way , In this way, advanced search algorithms can be implemented on the basis of these data institutions , This data structure is the index .
What we usually call index , Generally speaking, it means B+ Trees （ Multiple search trees ） Index of structural organization .
Index structure example
Above picture , In order to speed up Col2 Lookup , You can maintain a binary tree as shown in the figure on the right , Each node contains an index key value and a pointer to the physical address of the corresponding data record , In this way, we can quickly get the physical address of the data record through binary search , To find the corresponding data .
The advantages of indexing
Improve the efficiency of data search , Reduce the IO cost .
Improve the efficiency of data sorting , Reduce the CPU Consume .
Disadvantages of indexes
Indexes are actually data tables , Too many indexes take up more disk space .
Index will reduce the speed of addition, deletion and modification , Because every time you operate the data, you need to maintain the index file .