当前位置:网站首页>Several types of MySQL index invalidation and their solutions
Several types of MySQL index invalidation and their solutions
2022-06-29 11:18:00 【Migrant worker brother】
Click below “Java Programming duck ” Follow and mark the stars
More exciting First time direct
What are the conditions of index failure ?
Index columns are not independent
Left blur is used
Use or Some fields in the query do not use an index
String conditions are not used ''
Queries that do not conform to the leftmost prefix principle
Index field not added not null constraint
Implicit conversion leads to index invalidation
Index column independence means that the indexed column cannot be part of an expression , Cannot be an argument to a function , For example, the following situation
select id,name,age,salary from table_name where salary + 1000 = 6000;salary The column is evaluated by the user expression , In this case, the index will fail , The solution is to calculate the condition value in advance , Don't let the index column participate in the evaluation .
The index field is used as the parameter of the function
select id,name,age,salary from table_name where substring(name,1,3)= 'luc';What is the solution , You can calculate the conditions in advance , Do not use indexes , Or you can use other sql Replace the above , such as , above sql have access to like Instead of
select id,name,age,salary from table_name where name like 'luc%';Left blur is used
select id,name,age,salary from table_name where name like '%lucs%';Avoid using left blur as much as possible , It can be written like this
select id,name,age,salary from table_name where name like 'lucs%';If you can't avoid left fuzzy query , Consider search engines such as ES
or Some fields in the query do not use an index
select id,name,age,salary from table_name where name ='lucs' and age >25This situation , It can be for name and age All indexed , Otherwise, it will take a full scan .
String conditions are not used ''
select id,name,age,salary from table_name where phone=13088772233The one above sql phone The field type is String type , But it's not used '13088772233 ', SQL Just scan the whole table , So the string index should use ‘’
select id,name,age,salary from table_name where phone='13088772233 'Queries that do not conform to the leftmost prefix principle
For example, there is such a composite index index(a,b,c)
select * from table_name where b='1'and c='2'
select * from table_name where c='2'
// The top two SQL Can't run the index The principle of left , Is to have the leftmost priority , In my absence , You can't play by yourself , Unless you create your own index , Here are a few SQL You can execute the index
select * from table_name where a = 'asaa' and b='1'and c='2'
select * from table_name where a = 'asda' and b='1231'
// The above two items are indexed , But how do you think the index should go , Yes, all go , Or partial indexing ?
select * from table_name where a = 'asda' and c='dsfsdafsfsd'Index field not added not null constraint
select * from table_name where a is null;
// This article sql You can't go index execution ,is null Conditions Index cannot be used , Can only scan the whole table
// mysql The official suggestion is to set the field to not nullSo in this case , stay mysql When creating table fields , You can set the string to be indexed to not null default '' The default is an empty string
Implicit conversion
Implicit conversion will occur if the two field types of the associated table are inconsistent
select * from table_name t1 left join table_name2 t2 on t1.id=t2.tid;
// In the above sentence , If t1 Tabular id The type and t2 Tabular tid When the types are inconsistent , Can not
// Executed by index .
// The solution is to set the field types uniformly .END
After reading this article, there are gains ? Please forward to share with more people
Focus on 「Java Programming duck 」, promote Java Skill
Focus on Java Programming duck WeChat official account , The background to reply : Yard farm gift bag A copy of the latest technical data can be obtained . cover Java Frame learning 、 Architect learning, etc !
If the article helps , Looking at , Forward! .
Thank you for your support (*^__^*)边栏推荐
- 嵌入式驱动开发之uboot---uboot 中的常见命令参数参数
- Course design for the end of the semester: product sales management system based on SSM
- [various * * question series] what are OLTP and OLAP?
- MySQL get table information
- (JS)手写深比较
- (JS) array de duplication
- misc3~7
- Xiaomi mobile phone - Unlock BL + open root permission
- EasyDSS部署在C盘,录像回看无法正常播放该如何解决?
- [3 questions per day (2)] minimum operand for generating alternate binary strings
猜你喜欢

Online sql to htmltable tool

(JS) filter out keys with value greater than 2 in the object

Modbustcp protocol network learning single channel infrared module (double-layer board)

Course design for the end of the semester: product sales management system based on SSM

Spark - one to one correspondence between task and partition and detailed explanation of parameters

Modbus RTU 协议485学习型2路红外模块

多线程高并发服务器:3个问题

Modbustcp protocol WiFi wireless learning single channel infrared module (small shell version)

The first "cyborg" in the world died, and he only transformed himself to "change his life against the sky"

Modbus RTU protocol 485 learning 2-way infrared module
随机推荐
Map merges the same keys and values into a list
Pipeline aggregations管道聚合- parent-2
Bs-gx-018 student examination system based on SSM
(JS) isnan() method determines the reason why undefined is true
(JS) handwriting depth comparison
The use of variables in shell that you have to be familiar with
(JS) handwritten bind function
Online text filter less than specified length tool
LeetCode 535 TinyURL的加密与解密[map] HERODING的LeetCode之路
(JS) handwritten deep copy
Easydss is deployed on Disk C, and the video playback cannot be played normally. How to solve this problem?
(JS)数组方法:slice和splice
中国计算语言学大会、全国知识图谱与语义计算大会赛题火热进行中
(JS) array flat
5. migrate uboot set default environment variables, crop, and partition
期未课程设计:基于SSM的产品销售管理系统
Uber前安全主管面临欺诈指控 曾隐瞒数据泄露事件
(JS)迭代器模式
Modbustcp protocol network learning single channel infrared module (medium shell version)
Mastering the clever use of some shell wildcards will make us write with half the effort