当前位置:网站首页>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
边栏推荐
- National economic information center "APEC industry +": economic data released at the night of the Spring Festival | observation of stable strategy industry fund
- 23. Update data
- NFT smart contract release, blind box, public offering technology practice -- contract
- Nacos Development Manual
- Understanding of law of large numbers and central limit theorem
- 你想知道的ArrayList知识都在这
- [research materials] 2021 live broadcast annual data report of e-commerce - Download attached
- MySQL view tablespace and create table statements
- 2.10transfrom attribute
- Migrate data from CSV files to tidb
猜你喜欢
The resources of underground pipe holes are tight, and the air blowing micro cable is not fragrant?
化不掉的钟薛高,逃不出网红产品的生命周期
[Yugong series] February 2022 U3D full stack class 011 unity section 1 mind map
Circular reference of ES6 module
NFT smart contract release, blind box, public offering technology practice -- jigsaw puzzle
Golang DNS write casually
让学指针变得更简单(三)
[research materials] 2022 enterprise wechat Ecosystem Research Report - Download attached
你想知道的ArrayList知识都在这
Asia Pacific Financial Media | "APEC industry +" Western Silicon Valley invests 2trillion yuan in Chengdu Chongqing economic circle to catch up with Shanghai | stable strategy industry fund observatio
随机推荐
[Yugong series] creation of 009 unity object of U3D full stack class in February 2022
Analysis of pointer and array written test questions
Use dumping to back up tidb cluster data to S3 compatible storage
Nft智能合约发行,盲盒,公开发售技术实战--合约篇
Sanzi chess (C language)
Restore backup data on S3 compatible storage with tidb lightning
Nft智能合约发行,盲盒,公开发售技术实战--拼图篇
[research materials] 2021 China online high growth white paper - Download attached
数据治理:数据质量篇
National economic information center "APEC industry +": economic data released at the night of the Spring Festival | observation of stable strategy industry fund
Introduction to backup and recovery Cr
C语言自定义类型:结构体
Asia Pacific Financial Media | female pattern ladyvision: forced the hotel to upgrade security. The drunk woman died in the guest room, and the hotel was sentenced not to pay compensation | APEC secur
String to leading 0
ROS learning (IX): referencing custom message types in header files
[nonlinear control theory]9_ A series of lectures on nonlinear control theory
2.10transfrom attribute
How to use information mechanism to realize process mutual exclusion, process synchronization and precursor relationship
From monomer structure to microservice architecture, introduction to microservices
A Closer Look at How Fine-tuning Changes BERT