当前位置:网站首页>Summary of MySQL index failure scenarios
Summary of MySQL index failure scenarios
2022-07-06 08:17:00 【Big fish eating cats】
Preface
mysql The tuning aspects of include Table structure optimization 、 Index optimization 、sql Statements to optimize 、 Multiple dimensions such as table and database optimization , This article mainly summarizes the scenarios and causes of index failure .
Blogging is to sort out your knowledge , At present, it is written for yourself , It's my homework after study , Also to form a good habit .
One 、 Does not satisfy the leftmost matching principle
First review the leftmost matching principle :
1. Create a federated index index(a,b,c) Relative to creating idx_a(a)、idx_a_b(a,b)、idx_a_b_c(a,b,c) 3 An index .
-------------------------------------------------------
select * from table where a='a' and c='c';
This kind of city will go idx_a Indexes , and Field c The index will not go .
-------------------------------------------------------
select * from table where b='b' and c='c';
This kind can scan the whole table ,index Index failure .
-------------------------------------------------------
2. The index of the field will be invalidated after the joint index encounters the range query .
-------------------------------------------------------
select * from table where a like 'a%' and b='b';
This kind can go idx_a Index range retrieval , Field b Don't go by index .
-------------------------------------------------------
Two 、 Frequent table return
Let's first analyze the following sql stay mysql Next is how to implement :
select * from table where age > 20 ; -- among Field age Create index
Will be in the index first age Field b+tree I found the information about the qualified id, Then, on the cluster index, pass id Return to the table to query the complete data .
be select * There must be a table returning operation , When the result of the query is more than half of the total and the total is large , At this time, the cost of returning to the table is greater than that of full table scanning , be mysql The optimizer will perform a full table scan , That is, the index is invalid .
3、 ... and 、 There are calculations on the index column
give an example :select * from t_user where age+1=10;
This kind of index will fail directly .
Four 、 There is a function on the index column
give an example :select * from user where SUBSTR(height,1,2)=17;
This kind of index will fail directly .
5、 ... and 、 Field types are different
give an example :select * from user where type = '5';
type It's an integer type , Query with string ,mysql Can do implicit conversion , The index will fail directly .
-------------------------------------------------------
give an example :select oi.*,ui.name from order_info oi left join user_info ui on oi.user_id = ui.id;
among order_info Of user_id It's a string type ,user_info Of id It's an integer type , Even if order_info Of user_id Creating an index also makes implicit conversion due to different field types , The index will fail .
6、 ... and 、 Column comparison
give an example :select * from user where id=height;
The column comparison index will fail directly .
7、 ... and 、 Common index failures
Such as index column Used not in、 like ‘%x’ 、or All indexes fail
边栏推荐
- Mobile Test Engineer occupation yyds dry goods inventory
- 07- [istio] istio destinationrule (purpose rule)
- 图像融合--挑战、机遇与对策
- Migrate data from SQL files to tidb
- Upgrade tidb with tiup
- Online yaml to CSV tool
- 1202 character lookup
- Wireshark grabs packets to understand its word TCP segment
- 数据治理:误区梳理篇
- 从 CSV 文件迁移数据到 TiDB
猜你喜欢
C language - bit segment
Zhong Xuegao, who cannot be melted, cannot escape the life cycle of online celebrity products
"Designer universe": "benefit dimension" APEC public welfare + 2022 the latest slogan and the new platform will be launched soon | Asia Pacific Financial Media
Leetcode question brushing record | 203_ Remove linked list elements
将 NFT 设置为 ENS 个人资料头像的分步指南
Summary of phased use of sonic one-stop open source distributed cluster cloud real machine test platform
The resources of underground pipe holes are tight, and the air blowing micro cable is not fragrant?
wincc7.5下载安装教程(Win10系统)
22. Empty the table
Step by step guide to setting NFT as an ens profile Avatar
随机推荐
指针和数组笔试题解析
ROS learning (IX): referencing custom message types in header files
NFT smart contract release, blind box, public offering technology practice -- jigsaw puzzle
Erc20 token agreement
Data governance: misunderstanding sorting
Golang DNS write casually
File upload of DVWA range
CAD ARX gets the current viewport settings
Data governance: metadata management
Summary of phased use of sonic one-stop open source distributed cluster cloud real machine test platform
C language custom type: struct
Tidb backup and recovery introduction
Learn Arduino with examples
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Golang DNS 随便写写
Wincc7.5 download and installation tutorial (win10 system)
CAD ARX 获取当前的视口设置
08- [istio] istio gateway, virtual service and the relationship between them
leetcode刷题 (5.29) 哈希表
Secure captcha (unsafe verification code) of DVWA range