当前位置:网站首页>SQL index learning notes
SQL index learning notes
2022-06-26 10:41:00 【MervynLammm】
List of articles
SQL Index essence
Indexes (index) Help MySQL Efficient Access to data data structure .
stay RDBMS in , The index is stored in the hard disk .
Hash - Hash index
AHI-adaptive hash index - adaptive hash index
Calculate on field hash value , take hash The value and the row pointer correspond to each other hash In the table .
Why? innodb The engine does not support manual use hash Indexes :
- In memory , Large amount of data , Memory explodes easily
- hash Query line records , It is not suitable to specify the columns to be checked
- Press hash sorted , Not helpful for range lookup , If there is order, You need a second order
- Hash collision , Calculated hash Same value . One hash Value points to a multiline pointer , You need to find them one by one
memory The engine can be used manually hash Indexes , because memory The engine uses memory .
Generally, the intermediate table uses memory engine .
B+Tree Indexes
Binary search tree
A node can be divided into two nodes at most , The child nodes are small on the left and large on the right .
shortcoming : The limit case , hypothesis 1 Root node , The next nodes are 2、3、4、5 wait , To query 5 need 5 Time .
Balanced binary trees
A node can be divided into two nodes at most , The absolute value of the depth difference between two child nodes cannot be greater than 1.
- IO Too many times , With more data , The depth of the tree grows .
- Too little target data , Cause great IO Waste of resources .
B-Tree Multiple search trees 、 Multi fork balanced lookup tree
- Multiple key numbers
- Multiplexer number
- The depth of each road is the same 、 Absolute balance
Every node , The maximum number of keys = Number of routes - 1.
Assume that the node is :1,5,10
Then the branch is
[ Negative infinity ,1),[1, 5),[5,10),[10, It's just infinite )
Each node has a data area .
B+Tree
Number of key nodes and paths 1:1.
Assume that the node is :1,5,10
Then the branch is
[1, 5),[5, 10),[10, It's just infinite )
The data area is stored in the leaf node , So all queries must find leaf nodes , Although some queries are better than B-Tree More time consuming , But stable .
advantage :
- Strong ability to scan tables based on indexes
- Strong ability to sort based on index
- Query all data to the leaf node , Time stability .
- Cancel the contents of the data area , Better literacy
Clustered index
myisam engine
myi file , Storage index , Leaf node storage address
myd file , Store the data corresponding to the address
innodb engine
ibd file :
primary key : Leaf node mount line record
Non primary key index : The leaf node saves the primary key value
innodb In the engine , Only the primary key is a clustered index , Other indexes are nonclustered indexes .
primary key
If you do not manually create a primary key index , Will automatically use hidden columns _rowid As a primary key index , Occupy 6byte, and int Occupy only 4byte.
And row locks will be upgraded to table locks
Excellent index
Discreteness of columns
count distinct col : count col
Number of non repeating Columns : Number of all columns
The less column repetition the better .
Joint index
Left most matching principle : Any prefix of a federated index enables federated indexing
create index idx_name_ph_age(name,phone,age)
name
name, phone
name, phone, age
All three of the above can enable federated indexing , and
phone
phone, age
phone, name ,age
Cannot enable federated indexing
Whether the following two queries enable union query , Used several :
where name=‘peter’ and phone > 1333333 and age = 18
Union index used ,1 individual .“ After the range, it all fails ”
because phone>1333333 Too much scope , and age=18 High repetition rate .
where phone = 1333333 and name = ‘peter’
Use union index 2 individual ,mysql Optimizer , Will put the last column of selectivity in where On the far left of .
The connector : Manage connections , Authority verification
analyzer : Lexical analysis , Syntax analysis
Optimizer : Execution plan generation , Index selection
actuator : Operate the engine , Return results
Overlay index
Do not trigger the table return operation .
The column of the lock query can be directly returned through the information of the index item , Then the index becomes a query SQL Coverage index of .
Try to use overlay index , Because it can speed up the query .
Back to table operation :
According to the above
innodbengine
- primary key : Leaf node mount line record
- Non primary key index : The leaf node saves the primary key value
Find out the primary key according to the non primary key index , The operation of querying row records according to the primary key index is the back to table operation .
Suppose the table has :
- primary key
- Non primary key index
name- Joint index
name, phonebe :
select * from user where name = 'mervyn'Trigger the table return operation , Through non primary key indexnameQuery outidafter , And find out the row data according to the primary key index .
select id, name from user where name = 'mervyn'Table return operation is not triggered , Through non primary key indexnameYou can directly queryidandname.
select id, phone, name from user where name = 'mervyn'Table return operation is not triggered , Joint index
Samsung index
- where The more index keyword columns you can match, the better , The more accurate the scanned data , The less, the better. .
- Avoid reordering .
- Apply overlay indexes as much as possible . Reduce the return operation .
边栏推荐
- JS reverse | four libraries and one platform response data encryption
- SQL Server 基础介绍整理
- appliedzkp zkevm(8)中的Plookup Table
- Oracle sqlplus query result display optimization
- Notes - simple but adequate series_ KVM quick start
- Blog article index summary -- Software Engineering
- 方法区里面有什么——class文件、class文件常量池、运行时常量池
- 【LeetCode】59. Spiral matrix II
- Swiftui development experience: data layer of application design for offline priority
- MySQL第九次作业-连接查询&子查询
猜你喜欢

MySQL第九次作业-连接查询&子查询

Postman入门教程

Small example of SSM project, detailed tutorial of SSM integration

MySQL job 11 - application de la vue

How to start the learning journey of webrtc native cross platform development?
![Installing MySQL under Linux [details]](/img/38/77be56c3ef3923ce4c4e5df4a96f41.png)
Installing MySQL under Linux [details]

基础-MySQL

MySQL第十二次作业-存储过程的应用

Adaptiveavgpool2d does not support onnx export. Customize a class to replace adaptiveavgpool2d

118. Yanghui triangle
随机推荐
Oracle sqlplus query result display optimization
Linux下安装Mysql【详细】
工程数学概率论统计简明教程第二版复习大纲
MySQL Chapter 4 Summary
Selection of webrtc video codec type VP8 H264 or other? (openh264 encoding, ffmpeg decoding)
利用foreach循环二维数组
MySQL project 8 summary
[untitled]
Postman入门教程
Notes - simple but adequate series_ KVM quick start
MySQL 12th job - Application of stored procedure
How to change the QR code material color of wechat applet
MySQL第五章总结
Renesas electronics launched a complete intelligent sensor solution for Internet of things applications
What is a botnet
Blog article index summary -- Software Engineering
3行3列整形二维数组,求对角之和
Installer MySQL sous Linux [détails]
Tape library simple record 1
AdaptiveAvgPool2D 不支持 onnx 导出,自定义一个类代替 AdaptiveAvgPool2D