当前位置:网站首页>Brief introduction to clustered index, secondary index, index push down
Brief introduction to clustered index, secondary index, index push down
2022-07-25 17:42:00 【Suddenly】
Catalog
1、 Cluster index
InnoDB There are two kinds of indexes :
- Cluster index : Generally, the primary key when creating a table will be mysql As cluster index , If there is no primary key, select a non empty unique index as the cluster index , If none, an index is implicitly created as a clustered index
- Secondary index : That is, non clustered index or secondary index , Usually, the index we add is the auxiliary index ;
Cluster index Not a single index type , It's a kind of Data storage mode , It is to construct one according to the primary key of each table B+ Trees , At the same time, the leaf node stores the row record data of the whole table , therefore primary key The default is to use Cluster index .
2、 Secondary indexes ( Secondary index )
When creating a table, the primary key will be created by default Cluster index , Clustering ( Primary key ) The leaf node of the index stores the whole row of data .
Except clustering ( Primary key ) All indexes other than indexes are called secondary indexes, that is, non primary key indexes , The leaf node content of the secondary index is the value of the primary key , The smaller the primary key length , The smaller the leaf node of the secondary index , The less space it takes up ;
The secondary index needs to scan one more index tree in the query , That is to say, back to the table , adopt Overlay index and Default index push down The mechanism can avoid returning tables ;
3、 Back to the table
Back to the table : Is to scan the row where the data is located through the index , Then get other field data through the row primary key index .
In short, it is : There are existing index fields in the query fields , If there are non indexed fields, it will happen back to the table .
For example, the index field is name
# The query uses an index , And there are only name The data of , But all the fields are queried , At this time, you will go back to the table to get the values of other fields
# Through the index name Find the data row , Then find other field values through the primary key
select * from table where name = '';
Primary key index query : Cluster index is used as primary key , All column data is saved in the index , You can directly locate the data through the primary key and return ;
Auxiliary index query : The auxiliary index includes the field value corresponding to the index and the primary key value , If the query fields are all index fields , Just return the data directly through the index ; If the field of the query is other than the index field , It also contains other fields , Find the primary key through the secondary index , Then find the corresponding data in the cluster index through the primary key ==( That is to say, back to the table )==
Can pass Overlay index and Default index push down The mechanism can avoid returning tables ;
4、 Index push down (CIP)
ICP Is to combine index scanning and index filtering , An index optimization strategy after the filtered record data is pushed down to the storage engine .
Push is enabled by default under index conditions , You can use system parameters optimizer_switch To check whether the controller is on .
The advantages of index push down are as follows :
1. Reduce the number of operations back to the table .
2. Reduce uploading to MySQL SERVER Layer data .
Index push down usage conditions :
It can only be used for
range、ref、eq_ref、ref_or_nullAccess method ;It can only be used for
InnoDBandMyISAMStorage engine and its partition table ;Yes
InnoDBFor storage engines , Index push down is only applicable to secondary indexes ( Non primary key index );Conditions that reference subqueries cannot be pushed down ;
A condition that references a storage function cannot be pushed down , Because the storage engine cannot call the storage function .
MySQL Service layer : Used to resolve SQL The grammar of 、 semantics 、 Generate query plan 、 Take over from MySQL Secondary filtering of data pushed on the storage engine layer, etc .
MySQL Storage engine layer : according to MySQL Requests from the service layer , Upload data to by indexing or full table scanning MySQL Service layer .
MySQL An index scan : Filter according to the specified index , Traverse the index, find the primary key value corresponding to the index key, and return to the table to filter the remaining filter conditions .
MySQL Index filtering : After index scanning and secondary conditional filtering based on the index, return to the table .
边栏推荐
猜你喜欢

吴恩达机器学习编程作业无法暂停pause问题解决

Tkinter module advanced operations (I) -- transparent buttons, transparent text boxes, custom buttons and custom text boxes

Installation steps and usage of NVM under windows10 system

Highlights

Calculation date or date formatting

11. Camera and lens

Automated test Po design model

Redis源码与设计剖析 -- 15.RDB持久化机制

【硬件工程师】元器件选型都不会?

Thesis reading_ Multi task learning_ MMoE
随机推荐
Notes on Flickr's dataset
网上开期货账户安全吗?手续费怎么申请才低?
Postdoctoral recruitment | West Lake University Machine Intelligence Laboratory recruitment postdoctoral / Assistant Researcher / scientific research assistant
postgreSQL 密码区分大小写 ,有参数控制吗?
How to fix the first row title when scrolling down in Excel table / WPS table?
I2C communication - sequence diagram
WPF 实现用户头像选择器
8 年产品经验,我总结了这些持续高效研发实践经验 · 研发篇
PostgreSQL passwords are case sensitive. Is there parameter control?
四六级
[cadence Allegro PCB design] error: possible pin type conflict gnd/vcc power connected to output
Boring post roast about work and life
Thesis reading_ Multi task learning_ MMoE
Redis源码与设计剖析 -- 16.AOF持久化机制
MySQL数据库中去重与连接查询的方法
Stm32 paj7620u2 gesture recognition module (IIC communication) program source code explanation
【无标题】
stm32F407------SPI
01.两数之和
How to install govendor and open a project