当前位置:网站首页>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 .
边栏推荐
- 居家办公竟比去公司上班还累? | 社区征文
- “全班29人24人成功读研”冲上热搜!剩下的5个人去哪了?
- Queue, two-way queue, and its application
- Learning notes - data set generation
- 【TcaplusDB知识库】TcaplusDB分析型文本导出介绍
- Codeforces Round #786 (Div. 3) ABCDE
- How to deploy jupyterlab in methodot?
- 【TcaplusDB知识库】TcaplusDB系统用户组介绍
- Privacy computing fat offline prediction
- Tcp/ip explanation (version 2) notes / 3 link layer / 3.4 bridge and switch / 3.4.1 spanning tree protocol (STP)
猜你喜欢

Oracle trigger stored procedure writes at the same time

Codeforces Round #786 (Div. 3) ABCDE

ci/cd自动化测试_CI / CD管道加快测试自动化的16种最佳实践

“互联网+”大赛命题火热对接中 | 一图读懂百度38道命题

Future & CompletionService

go-zero微服务实战系列(七、请求量这么高该如何优化)

【TcaplusDB知识库】TcaplusDB常规单据介绍

一篇抄十篇,CVPR Oral被指大量抄袭

政策关注 | 加快构建数据基础制度,维护国家数据安全

如何在 Methodot 中部署 JupyterLab?
随机推荐
【值得收藏】Centos7 安装mysql完整操作命令
Ubuntu手動安裝MySQL
【TcaplusDB知识库】Tmonitor系统升级介绍
【TcaplusDB知识库】Tmonitor单机安装指引介绍(一)
Eureka core source code analysis
Error im002 when Oracle connects to MySQL
21: Chapter 3: develop pass service: 4: further improve [send SMS, interface]; (in [send SMS, interface], call Alibaba cloud SMS service and redis service; a design idea: basecontroller;)
Analysis of mobile ar implementation based on edge computing (Part 2)
Audiotrack and audiolinker
【TcaplusDB知识库】TcaplusDB业务数据备份介绍
[tcapulusdb knowledge base] tcapulusdb machine initialization and launch introduction
Future & CompletionService
隐私计算FATE-离线预测
【TcaplusDB知识库】TcaplusDB机型管理介绍
[tcapulusdb knowledge base] tcapulusdb business data backup introduction
直播电子商务应用程序开发需要什么基本功能?未来发展前景如何?
深入理解 happens-before 原则
[tcapulusdb knowledge base] Introduction to tcapulusdb table data caching
Metadata of database
Future & CompletionService