当前位置:网站首页>Talking about MySQL index
Talking about MySQL index
2022-07-05 22:00:00 【The sea of waves】
List of articles
- Talking about MYSQL Index performance
- The essence of index
- myIsam Storage engine index
- innodb Storage engine index
- ( Interview questions ) Why suggest Innob A table must have a primary key , And it is recommended to use the auto increasing primary key of integer type
- ( Interview questions ) Compared with storing row pointers in leaf nodes , The secondary index will take up more space to store the primary key value , Then why do we design it like this ?
- ( Interview questions ) that InnoDB With clustering index , Why should there be a secondary index ?
- mysql Explanation of the leftmost prefix optimization principle
Talking about MYSQL Index performance
The essence of index
Index is help MYSQL A well ordered data structure for efficient data acquisition .
Index data structure
- Binary tree It will become a linear linked list , Low efficiency
- Red and black trees When there is a large amount of data ,IO Low disk efficiency
- hash surface
- Evaluation of index key Do it once. hash Calculation can locate the location of data storage
- A lot of time Hash Index is better than B+ Tree indexing is more efficient
- Can only satisfy “=”,“IN”, Range query is not supported
- hash The question of conflict
B-tree
Leaf nodes have the same depth , The pointer to the leaf node is null
All index elements are not duplicate
The data indexes in the node are incrementally arranged from left to right
B+tree
- Non leaf nodes do not store data, Store index only , More indexes can be placed
- The leaf node contains all index fields
- The leaf node is connected with a pointer , Improve the performance of interval access , Support range lookup (20<col<50)
- The height is about 3 To 4, Leaf nodes can store 2kw An index
lookup 30 The process of this element , First load the root node into memory , According to the idea of binary search, we can find 15~56 The index of this piece
Then according to the idea of binary search Find the 20~49 This index , Finally find 30 This element .
myIsam Storage engine index
The data in the table is stored on disk . Each row of data has a disk file address
All elements in the table are stored in files .
frm file : Definition and structure of table
MYD file : Table all data
MYI file : Table all indexes
innodb Storage engine index
frm file : Definition and structure of table
ibd file : Table data and index , Disk read ahead , The data near the searched records will be queried .
Clustered index : The leaf node contains the index and other data fields of the row
Nonclustered indexes : Search across multiple files according to the index , such as myIsam In the storage engine , Need from MYI File to MYD file Find data in ( Also called return table )
Secondary index : The leaf node stores the primary key value , Every time you look up data , Find the primary key value in the leaf node according to the index , According to the primary key value, we can get a complete row of records in the cluster index
Joint index : Union index is also called compound index . For composite indexes :Mysql Use the fields in the index from left to right , A query can use only a part of the index , But only the far left part . For example, the index is key index (a,b,c). Can support a | a,b| a,b,c 3 Combination of search , But does not support b,c Search for . When the leftmost field is a constant reference , The index is very efficient .
( Interview questions ) Why suggest Innob A table must have a primary key , And it is recommended to use the auto increasing primary key of integer type
If not built , The database will automatically find a column of unique data as the primary key index , If no unique data is found , Will build a fake hidden column , This will cause mysql Resources are tight , Bring a great burden .
Integer index and string or UUID Compared with , More efficient , Take up less space .
Auto increment :UUID Not auto increment , There may be node splitting , It is efficient to build nodes without self increment .
( Interview questions ) Compared with storing row pointers in leaf nodes , The secondary index will take up more space to store the primary key value , Then why do we design it like this ?
InnoDB When moving rows , There is no need to maintain a secondary index , Because the leaf node stores the primary key value , Instead of Pointers .
( Interview questions ) that InnoDB With clustering index , Why should there be a secondary index ?
The leaf node of the cluster index stores a row of complete data , The secondary index only stores the primary key value , Compared with clustered index , Take up less space . When we need to build multiple indexes for a table , If they are clustered indexes , That will take up a lot of memory space , therefore InnoDB The primary key in is a clustered index , And the only index 、 General index 、 Prefix indexes are secondary indexes .
mysql Explanation of the leftmost prefix optimization principle
Skip in composite index name after ,age Is chaotic , So a full scan will be performed .
The list of articles to be completed later
- Business
- MVCC
- lock
- Sub database and sub table
There is something wrong , Welcome to the discussion .
Last , Welcome to pay attention to my wechat , What do you like , Collection , Forwarding is my greatest encouragement .
边栏推荐
- HYSBZ 2243 染色 (树链拆分)
- Poj 3237 Tree (Tree Chain Split)
- ESP32
- Kingbasees v8r3 data security case - audit record clearing case
- 从零开始实现lmax-Disruptor队列(四)多线程生产者MultiProducerSequencer原理解析
- Livelocks and deadlocks of concurrency control
- Summary of El and JSTL precautions
- 华为游戏多媒体调用切换房间方法出现异常Internal system error. Reason:90000017
- Dbeaver executes multiple insert into error processing at the same time
- Oracle检查点队列–实例崩溃恢复原理剖析
猜你喜欢
"Chris Richardson microservices series" uses API gateway to build microservices
EBS Oracle 11g 克隆步骤(单节点)
AD637使用筆記
Emotional analysis of wechat chat records on Valentine's day based on Text Mining
MySQL连接断开报错MySQLdb._exceptions.OperationalError 4031, The client was disconnected by the server
QML reported an error expected token ";", expected a qualified name ID
How to view Apache log4j 2 remote code execution vulnerability?
Kingbasees v8r3 cluster maintenance case -- online addition of standby database management node
Analysis and test of ModbusRTU communication protocol
Installation of VMware Workstation
随机推荐
PyGame practical project: write Snake games with 300 lines of code
2.2.5 basic sentences of R language drawing
CRM creates its own custom report based on fetch
How to view Apache log4j 2 remote code execution vulnerability?
DataGrid directly edits and saves "design defects"
Getting started with microservices (resttemplate, Eureka, Nacos, feign, gateway)
让开发效率提升的跨端方案
Concurrency control of performance tuning methodology
Server optimization of performance tuning methodology
The solution to the problem that Oracle hugepages are not used, causing the server to be too laggy
Installation of VMware Workstation
MMAP learning
资深电感厂家告诉你电感什么情况会有噪音电感噪音是比较常见的一种电感故障情况,如果使用的电感出现了噪音大家也不用着急,只需要准确查找分析出什么何原因,其实还是有具体的方法来解决的。作为一家拥有18年品牌
【愚公系列】2022年7月 Go教学课程 004-Go代码注释
华为游戏多媒体调用切换房间方法出现异常Internal system error. Reason:90000017
Advantages of robot framework
Matlab | app designer · I used Matlab to make a real-time editor of latex formula
Cold violence -- another perspective of objective function setting
Image editor for their AutoLayout environment
MySQL disconnection reports an error MySQL ldb_ exceptions. OperationalError 4031, The client was disconnected by the server