当前位置:网站首页>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 .
边栏推荐
- Adaptiveavgpool2d does not support onnx export. Customize a class to replace adaptiveavgpool2d
- What is a botnet
- MySQL第九次作业-连接查询&子查询
- Problems encountered in the application and development of Hongmeng and some roast
- 創建對象的時候堆內存的分配
- Using foreach to loop two-dimensional array
- 六月集训(第26天) —— 并查集
- 118. Yanghui triangle
- 哪些PHP开源作品值得关注
- US President signs community safety act to deal with gun issue
猜你喜欢

Which PHP open source works deserve attention

How to start the learning journey of webrtc native cross platform development?

工程数学概率论统计简明教程第二版复习大纲
![Installer MySQL sous Linux [détails]](/img/38/77be56c3ef3923ce4c4e5df4a96f41.png)
Installer MySQL sous Linux [détails]

Renesas electronics launched a complete intelligent sensor solution for Internet of things applications

Write data to local file

Basic string operations in C

Appium automation test foundation - mobile end test environment construction (II)

String constant pool, class constant pool, and runtime constant pool

See how I store integer data in the map < string, string > set
随机推荐
Solution to the problem of compilation error due to repeated third-party package names
What is LSP
創建對象的時候堆內存的分配
appliedzkp zkevm(8)中的Plookup Table
Linux下安裝Mysql【詳細】
【Leetcode】76. Minimum covering substring
Swiftui development experience: data layer of application design for offline priority
Searchview click failure
Basic MySQL
MySQL项目7总结
About multi table query of MySQL
When will JVM garbage collection enter the older generation
SQL Server 基础介绍整理
June training (the 26th day) - collective search
AIX basic operation record
Oracle11g reports an error when starting the database ora-27154: post/wait create failed
基础-MySQL
Threading model in webrtc native
MySQL第六次作业-查询数据-多条件
The IE mode tab of Microsoft edge browser is stuck, which has been fixed by rolling back the update