当前位置:网站首页>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 (*^__^*)边栏推荐
- Nuc980 open source project 16- start from SPI flash (w25q128)
- The last 48 hours! The cloud XR theme competition invites you to bloom together. See you at the competition!
- The Chinese Computational Linguistics Conference and the national knowledge atlas and Semantic Computing Conference are in full swing
- MySQL 索引失效的几种类型以及解决方式
- Shell 引号和转义从来很少被人注意,但平时写脚本又经常用
- (JS) imitate the indexof method to find the position of a character in the string
- 期未课程设计:基于SSM的产品销售管理系统
- BS-GX-018 基于SSM实现在校学生考试系统
- Spark - Task 与 Partition 一一对应与参数详解
- How to test the performance of container platform, including stability, expansion efficiency and component performance
猜你喜欢

【每日3题(1)】判断国际象棋棋盘中一个格子的颜色

【数字信号调制】基于 AM+FM+DSB+SSB实现信号调制解调含Matlab源码

How to test the performance of container platform, including stability, expansion efficiency and component performance
![LeetCode 535 TinyURL的加密与解密[map] HERODING的LeetCode之路](/img/76/709bbbbd8eb01f32683a96c4abddb9.png)
LeetCode 535 TinyURL的加密与解密[map] HERODING的LeetCode之路

非凸联合创始人李佐凡:将量化作为自己的终身事业

西门子S7-200SMART控制步进电机的具体方法及示例程序

在日本的 IT 公司工作是怎样一番体验?
![[digital signal modulation] realize signal modulation and demodulation based on am+fm+dsb+ssb, including Matlab source code](/img/76/bcf0118c8eea2b45b47eda4a68d3fd.png)
[digital signal modulation] realize signal modulation and demodulation based on am+fm+dsb+ssb, including Matlab source code

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

ModbusTCP协议WIFI无线学习型单路红外模块(小壳版)
随机推荐
Specific method and example program of Siemens s7-200smart control stepping motor
The first "cyborg" in the world died, and he only transformed himself to "change his life against the sky"
The necessary operation for those big guys to fly 666 inadvertently at the bash command line terminal
多线程实现客户端与服务端通信(初级版本)
(JS)数组方法:slice和splice
Nuc980 open source project 16- start from SPI flash (w25q128)
[various * * question series] what are OLTP and OLAP?
Reids设计与实现
斐波那锲数列与冒泡排序法在C语言中的用法
Course design for the end of the semester: product sales management system based on SSM
After 22 years in office, the father of PowerShell will leave Microsoft: he was demoted by Microsoft for developing PowerShell
MySQL 索引失效的几种类型以及解决方式
[untitled] I am plotting a big event
VI exit exit VIM applicable novice
TTL serial port learning infrared remote control module can be extended to network control
如何识别出轮廓准确的长和宽
Today in history: musk was born; Microsoft launches office 365; The inventor of Chua's circuit was born
Multithreaded high concurrency server: three problems
(JS) isnan() method determines the reason why undefined is true
在Clion中使用EasyX配置