当前位置:网站首页>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 .
边栏推荐
猜你喜欢

Beyond convnext, replknet | look 51 × 51 convolution kernel how to break ten thousand volumes!

我也是醉了,Eureka 延迟注册还有这个坑!

ACL 2022 | comparative learning based on optimal transmission to achieve interpretable semantic text similarity

Hcip first day experiment

面试官:说说 log.Fatal 和 panic 的区别

"Digital security" alert NFT's seven Scams

EDI 对接CommerceHub OrderStream

Highlights

Take you to a preliminary understanding of multiparty secure computing (MPC)

stm32F407------SPI
随机推荐
What is an IP SSL certificate and how to apply for it?
论文阅读_多任务学习_MMoE
OSPF综合实验
Several implementations of PHP to solve concurrency problems
一篇文章了解超声波加湿器
服务器端架构设计期末复习知识点总结
Redis源码与设计剖析 -- 18.Redis网络连接库分析
Summary of 80 domestic database operation documents (including tidb, Damon, opengauss, etc.)
交友活动记录
go语言context控制函数执行超时返回
ROS学习笔记(四)ros 无法rosdep init 或者update解决方法
I2C communication - sequence diagram
ROS learning notes (IV) ROS cannot solve rosdep init or update
【Cadence Allegro PCB设计】永久修改快捷键(自定义)~亲测有效~
stm32F407------SPI
如何看一本书
03. Longest substring without repeated characters
带你初步了解多方安全计算(MPC)
How to fix the first row title when scrolling down in Excel table / WPS table?
PostgreSQL里有只编译语句但不执行的方法吗?