当前位置:网站首页>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
边栏推荐
- How often should you refactor- How often should you refactor?
- Notes on dashboard & kuboard installation in kubernetes cluster
- 证券如何在线开户?在线开户是安全么?
- Curl command – file transfer tool
- Rhcsa--- day 6 operation
- How to create a handy vs Code?
- Go language library management restful API development practice
- Mount command - file system mount
- Advantages and disadvantages of using SNMP and WMI polling
- Tail command – view the contents at the end of the file
猜你喜欢
Monitoring access: how to grant minimum WMI access to the monitoring service account
Personal blog system graduation project opening report
Cannot activate inspection type when SAP retail uses transaction code mm41 to create commodity master data?
What is VLAN
Wireless industrial Internet of things data monitoring terminal
Brief introduction and use of JSON
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
Methods for obtaining some information of equipment
Day22 send request and parameterization using JMeter
[Suanli network] problems and challenges faced by the development of Suanli network
随机推荐
Socket, network model notes
DNS domain name system
Location object
Global and Chinese medical protective clothing market supply and demand research and investment value proposal report 2022-2028
Cnpm installation
Microsoft issued a document to celebrate Net 20th anniversary!
Understanding the dynamic mode of mongodb document
We cannot activate inspection type for article master in transaction code MM41?
The elephant turns around and starts the whole body. Ali pushes Maoxiang not only to Jingdong
How to create a handy vs Code?
Netstat command – displays network status
2022-02-19: fence installation. In a two-dimensional garden, there are some trees represented by (x, y) coordinates. As the installation cost is very expensive, your task is to enclose all the trees w
ARM processor operating mode
Tail command – view the contents at the end of the file
BigDecimal. Summary of setscale usage
Face++ realizes face detection by flow
Advantages and disadvantages of using SNMP and WMI polling
Research Report on brand strategic management and marketing trends in the global and Chinese preserved fruit market 2022
Which of the top ten securities companies has the lowest Commission and is the most safe and reliable? Do you know anything
[short time average zero crossing rate] short time average zero crossing rate of speech signal based on MATLAB [including Matlab source code 1721]