当前位置:网站首页>Interview shock 60: what will cause MySQL index invalidation?
Interview shock 60: what will cause MySQL index invalidation?
2022-06-27 11:02:00 【InfoQ】

- id — Select the identifier ,id The higher the priority, the higher , The first to be executed ;
- select_type — Represents the type of query ;
- table — Output result set table ;
- partitions — Matching partition ;
- type — Indicates the connection type of the table ;
- possible_keys — When representing a query , Possible indexes ;
- key — Indicates the index actually used ;
- key_len — Length of index field ;
- ref— Comparison of columns and indexes ;
- rows — Approximate estimated number of lines ;
- filtered — Percentage of rows filtered by table criteria ;
- Extra — Description and description of implementation .
- all — Scan the full table data ;
- index — Traverse index ;
- range — Index range lookup ;
- index_subquery — Use... In subqueries ref;
- unique_subquery — Use... In subqueries eq_ref;
- ref_or_null — Yes null To optimize the index ref;
- fulltext — Use full text indexing ;
- ref — Find data using a non unique index ;
- eq_ref — stay join Use primary key or unique index association in query ;
- const — Put a primary key in where The following is used as a conditional query , MySQL The optimizer can turn this query optimization into a constant , How and when to transform , It depends on the optimizer , This ratio eq_ref Be more efficient .
Create test tables and data
- In order to demonstrate and test that situation will lead to index invalidation , Let's create a test table and corresponding data :
-- Create table
drop table if exists student;
create table student(
id int primary key auto_increment comment ' Primary key ',
sn varchar(32) comment ' Student number ',
name varchar(250) comment ' full name ',
age int comment ' Age ',
sex bit comment ' Gender ',
address varchar(250) comment ' Home address ',
key idx_address (address),
key idx_sn_name_age (sn,name,age)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- Add test data
insert into student(id,sn,name,age,sex,address)
values(1,'cn001',' Zhang San ',18,1,' Gao Laozhuang '),
(2,'cn002',' Li Si ',20,0,' Huaguoshan '),
(3,'cn003',' Wang Wu ',50,1,' Waterfall cave ');

Index failure 1: Non leftmost match

- A+B+C
- A+B
- A+C
- among :A Equals field sn,B Equals field name,C Equals field age.
Index failure 2: Error fuzzy query
- Fuzzy match followed by any character :like ' Zhang %'
- Fuzzy match any preceding character :like '% Zhang '
- Fuzzy matching before and after any character :like '% Zhang %'

Index failure 3: Column operation

Index failure 4: Using functions

Index failure 5: Type conversion

Index failure 6: Use is not null

summary
- The union index does not satisfy the leftmost matching principle .
- The first fuzzy query is an indefinite matching character .
- The index column is involved in the operation .
- The index column uses the function .
- Index column has type conversion .
- Index columns use is not null Inquire about .
边栏推荐
- [tcapulusdb knowledge base] tcapulusdb cluster management introduction
- 【TcaplusDB知识库】TcaplusDB-tcapsvrmgr工具介绍(一)
- 基于swiftadmin极速后台开发框架,我制作了菜鸟教程[专业版]
- JS client storage
- Oracle group statistics query
- 直播電子商務應用程序開發需要什麼基本功能?未來發展前景如何?
- 【TcaplusDB知识库】TcaplusDB单据受理-创建游戏区介绍
- Metadata of database
- Experiment notes - Convert Carmen (.Log.Clf) file to rosbag
- 【值得收藏】Centos7 安装mysql完整操作命令
猜你喜欢

Oracle trigger stored procedure writes at the same time
![[tcapulusdb knowledge base] Introduction to tmonitor stand-alone installation guidelines (II)](/img/6d/8b1ac734cd95fb29e576aa3eee1b33.png)
[tcapulusdb knowledge base] Introduction to tmonitor stand-alone installation guidelines (II)

21:第三章:开发通行证服务:4:进一步完善【发送短信,接口】;(在【发送短信,接口】中,调用阿里云短信服务和redis服务;一种设计思想:BaseController;)

Working at home is more tiring than going to work at the company| Community essay solicitation

【TcaplusDB知识库】TcaplusDB Tmonitor模块架构介绍

How to deploy jupyterlab in methodot?

If you find any loopholes later, don't tell China!

Oracle-分组统计查询

直播电子商务应用程序开发需要什么基本功能?未来发展前景如何?

Codeforces Round #786 (Div. 3) ABCDE
随机推荐
【TcaplusDB知识库】TcaplusDB业务数据备份介绍
【TcaplusDB知识库】TcaplusDB机器初始化和上架介绍
【TcaplusDB知识库】TcaplusDB单据受理-建表审批介绍
杰理之一直喂狗会频繁开关中断导致定时器【篇】
deep learning statistical arbitrage
Proe/Creo家电产品结构设计规范-电煎锅
If you find any loopholes later, don't tell China!
【TcaplusDB知识库】TcaplusDB运维单据介绍
深入理解 happens-before 原则
go-zero微服务实战系列(七、请求量这么高该如何优化)
软交换呼叫中心系统的支撑系统
【TcaplusDB知识库】TcaplusDB机型管理介绍
Eureka core source code analysis
杰理之睡眠以后定时唤醒系统继续跑不复位【篇】
“互联网+”大赛命题火热对接中 | 一图读懂百度38道命题
Cross cluster deployment of helm applications using karmada [cloud native open source]
Evolution of software system architecture
[tcapulusdb knowledge base] Introduction to tcapulusdb data import
中科院微生物所招聘青年PI 20位,2百万安家费,千万启动经费(长期有效)
Deep learning in finance in cross sectional sectional predictions for random forests