当前位置:网站首页>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
边栏推荐
- What is the slice flag bit
- JS to determine whether an element exists in the array (four methods)
- @The difference between notempty, @notnull and @notblank
- C simple operation mongodb
- [data visualization application] draw spatial map (with R language code)
- Which of the top ten securities companies has the lowest Commission and is the most safe and reliable? Do you know anything
- Wechat applet authorization login + mobile phone sending verification code +jwt verification interface (laravel8+php)
- [Suanli network] problems and challenges faced by the development of Suanli network
- How two hosts in different network segments directly connected communicate
- Lesson 8: FTP server setup and loading
猜你喜欢

Rhcsa--- day 6 operation

JSON. toJSONString(object, SerializerFeature.WriteMapNullValue); Second parameter action

How to use asemi FET 7n80 and how to use 7n80

How to deploy locally developed SAP ui5 applications to ABAP servers

Distributed solar photovoltaic inverter monitoring

What is VLAN

Location object

Personal blog system graduation project opening report
![[kicad image] download and installation](/img/88/cebf8cc55cb8904c91f9096312859a.jpg)
[kicad image] download and installation

What elements are indispensable for the development of the character? What are the stages
随机推荐
@The difference between notempty, @notnull and @notblank
What is the IP address
Forecast report on output demand and supply scale of global and Chinese structural ceramics market for semiconductor equipment (2022 Edition)
Global and Chinese kaolin market operation scale and investment development proposal report 2022
You can't specify target table for update in from clause error in MySQL
Rational investment and internationalism
Wireless industrial Internet of things data monitoring terminal
Report on strategic suggestions on investment direction and Prospect of global and Chinese marine biological industry (2022 Edition)
Echo command – output a string or extract the value of a shell variable
Aviator an expression evaluation engine
Digitalization, transformation?
Leetcode sword finger offer question brushing - day 27
What is VLAN
C simple operation mongodb
Gavin's insight on transformer live class - line by line analysis and field experiment analysis of insurance BOT microservice code of insurance industry in the actual combat of Rasa dialogue robot pro
After five years of software testing in ByteDance, I was dismissed in December to remind my brother of paddling
Kotlin reflection -- Notes
[short time energy] short time energy of speech signal based on MATLAB [including Matlab source code 1719]
Tail command – view the contents at the end of the file
The "&" character will destroy the data stored in the web The "&" character breaks passwords that are stored in the web config