当前位置:网站首页>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 .
边栏推荐
- Installation manuelle de MySQL par UBUNTU
- istio相关资料
- Exception in Chinese character fuzzy query of MySQL database
- 【TcaplusDB知识库】TcaplusDB数据导入介绍
- Code for structural design of proe/creo household appliances - electric frying pan
- “全班29人24人成功读研”冲上热搜!剩下的5个人去哪了?
- VPT Model Video Explanation
- 如何在 Methodot 中部署 JupyterLab?
- Oracle-分组统计查询
- [tcapulusdb knowledge base] Introduction to tmonitor stand-alone installation guidelines (I)
猜你喜欢
![[tcapulusdb knowledge base] Introduction to tmonitor background one click installation (I)](/img/0a/3eae294b335c120c4aabd05e4230c3.png)
[tcapulusdb knowledge base] Introduction to tmonitor background one click installation (I)

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

【TcaplusDB知识库】Tmonitor后台一键安装介绍(二)

15+城市道路要素分割应用,用这一个分割模型就够了!

Imeta: a collection of imagegp+ video tutorials of high-value drawing websites, which has been cited 360 times (220625 updates)

Leetcode 729. My schedule I (awesome, solved)

Go zero micro Service Practice Series (VII. How to optimize such a high demand)

NAACL 2022 | TAMT:通过下游任务无关掩码训练搜索可迁移的BERT子网络

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

【TcaplusDB知识库】TcaplusDB单据受理-创建业务介绍
随机推荐
Deep learning in finance in cross sectional sectional predictions for random forests
LeetCode 522 最长特殊序列II[枚举 双指针] HERODING的LeetCode之路
Tcp/ip explanation (version 2) notes / 3 link layer / 3.4 bridge and switch / 3.4.1 spanning tree protocol (STP)
VPT Model Video Explanation
[tcapulusdb knowledge base] tcapulusdb cluster management introduction
[tcapulusdb knowledge base] Introduction to tmonitor background one click installation (I)
Openpyxl table reading instance
Evolution of software system architecture
Future & CompletionService
【TcaplusDB知识库】Tmonitor后台一键安装介绍(二)
Change PIP mirror source
One copy ten, CVPR oral is accused of plagiarizing a lot
[learn FPGA programming from scratch -47]: Vision - current situation and development trend of the third generation semiconductor technology
Native JS implements page scroll bar loading data and page drop-down loading content
Uniform Asymptotics by Alexei
直播电子商务应用程序开发需要什么基本功能?未来发展前景如何?
VPT模型视频讲解
Dimitt's law
深入理解 happens-before 原则
Queue, two-way queue, and its application