当前位置:网站首页>Query process of MySQL secondary index
Query process of MySQL secondary index
2022-06-25 06:27:00 【JavaEdge.】
The cluster index is innodb The default primary key based index structure is created , And the data in the table is directly placed in the cluster index , Data pages as leaf nodes :

Data search based on primary key : The binary search starts from the root node of the cluster index , Find the corresponding data page all the way , Based on the page directory, you can directly locate the primary key target data .
If you want to index other fields , Even a joint index based on multiple fields , What is the index structure at this time ?
Suppose you index other fields , Such as name、age And so on , It's all the same principle . For example, when you insert data :
- Insert the complete data into the data page of the leaf node of the cluster index , At the same time, maintain the cluster index
- Index your other fields , Rebuild another B+ Trees
For example, you are based on name Fields create an index , When inserting data , Will make another one B+ Trees ,B+ The leaf node of the tree is also a data page , But only the primary key field and... Are placed in the data page name Field :

This is another index independent of clustering name Field B+ Tree index , The data page of its leaf node only stores the primary key and name field value .
The overall sorting rule is the same as that of the cluster index according to the primary key , namely :
- In the data page of the leaf node name Values are sorted
- In the next data page name All field values > In the previous data page name field value
name Index of field B+ The tree will also build multi-level index pages , In the index page :
- The page number of the next layer
- Minimum name field value , according to name Sort field values .
So if you follow name Field query data , The process is the same , from name The root node of the index tree starts , Look down one layer at a time , Keep finding the data page of the leaf node , Locate the name The primary key value corresponding to the field value .
And then for
select * from t where name='xx'
This kind of sentence , First, according to name Values in name Look in the index tree , Find the leaf node , You can only find the corresponding primary key value , And can't find all the fields of this row of data .
So I need to return the form : It also needs to be based on the primary key value , Then go to the cluster index, starting from the root node , Find the data page of the leaf node , Locate the complete data row corresponding to the primary key value , Only then can select * All field values to be taken out .
Joint index
such as name+age, The operation process is the same , Building an independent B+ Trees , The data pages of leaf nodes are stored id+name+age after , Press default name Sort ,name Just press the same age row , Between different data pages name+age The same goes for sorting values .
And then this name+age Joint index of B+ The index page of the tree stores :
- The page number of the next layer node
- The smallest name+age Value
So when you're based on name+age When searching , Will go name+age Union index tree , Search for primary key , Then search the cluster index according to the primary key .
summary
That's all InnoDB The realization principle of index , It's about building B+ Trees , Layer by layer binary search . Different indexes create different B+ Trees , Then add, delete and modify :
- Update the data in the data page
- Maintain all your indexes
边栏推荐
- RM command – remove file or directory
- How to chain multiple different InputStreams into one InputStream
- 十大券商公司哪个佣金最低,最安全可靠?有知道的吗
- The sum problem
- C simple operation mongodb
- Methods for obtaining some information of equipment
- PHP and WMI – explore windows with PHP
- Large funds support ecological construction, and Plato farm builds a real meta universe with Dao as its governance
- Investment opportunities and operational risk assessment report of China's engineering consulting industry during the 14th Five Year Plan period 2022-2028
- How two hosts in different network segments directly connected communicate
猜你喜欢
![[speech discrimination] discrimination of speech signals based on MATLAB double threshold method [including Matlab source code 1720]](/img/36/ad86f403b47731670879f01299b416.jpg)
[speech discrimination] discrimination of speech signals based on MATLAB double threshold method [including Matlab source code 1720]

How to deploy locally developed SAP ui5 applications to ABAP servers

Brief introduction and use of JSON

Gb28181 protocol -- timing

Rhcsa--- day 6 operation

Wechat applet authorization login + mobile phone sending verification code +jwt verification interface (laravel8+php)

Understanding the dynamic mode of mongodb document

At the age of 26, I was transferred to software testing with zero foundation. Now I have successfully entered the job with a monthly salary of 12K. However, no one understands my bitterness

Uni app wechat applet customer service chat function
![[data visualization application] draw spatial map (with R language code)](/img/2d/04e5015573d10bdd6325ae497bfeb3.jpg)
[data visualization application] draw spatial map (with R language code)
随机推荐
Mongodb delete data
Tablespace free space
[short time average zero crossing rate] short time average zero crossing rate of speech signal based on MATLAB [including Matlab source code 1721]
Vegetables sklearn - xgboost (2)
Why study discrete mathematics
Rhcsa day 4
John
PHP and WMI – explore windows with PHP
Arm instructions and others
MV command – move or rename files
How to use asemi FET 7n80 and how to use 7n80
Forecast report on output demand and supply scale of global and Chinese structural ceramics market for semiconductor equipment (2022 Edition)
What is the slice flag bit
SAP QM executes the transaction code qp01, and the system reports an error -material type food is not defined for task list type Q-
Find command – find and search for files
Tencent and China Mobile continued to buy back with large sums of money, and the leading Hong Kong stocks "led" the market to rebound?
Large funds support ecological construction, and Plato farm builds a real meta universe with Dao as its governance
[Suanli network] problems and challenges faced by the development of Suanli network
The perfect presentation of Dao in the metauniverse, and platofarm creates a farm themed metauniverse
Wechat applet authorization login + mobile phone sending verification code +jwt verification interface (laravel8+php)