当前位置:网站首页>MySQL Index & execution plan
MySQL Index & execution plan
2022-07-23 11:27:00 【_ Leaf1217】
Catalog
Two 、 Classification of indexes
3、 ... and 、 Use cases of index creation
One 、 What is index
1.1 What is index ?
An index is a combination of one or more columns in a database table , Its function is to improve the query speed of data in the table .
A catalogue similar to a book , Easy and fast positioning , Find the specified content .
1.2 Advantages and disadvantages of index ?
advantage : Speed up data query .
shortcoming : The time to create and maintain indexes has increased , At the same time, it takes up hard disk space .
Two 、 Classification of indexes
2.1 Five indexes
1) General index : Is the most basic index , It has no restrictions ;
2) unique index : Value must be unique , But you can have an empty value . If it's a composite index , The combination of column values must be unique ;
3) primary key : A table can only have one primary key , No null values are allowed ;
4) Composite index : An index created on multiple fields , Only the first field that created the index is used in the query criteria , Indexes are used . When using a composite index, follow the leftmost prefix set ;
5) Full-text index ;
2.2 modify & Delete index
Modify the index
ALTER TABLE Table name ADD [UNIQUE|FULLTEXT] INDEX Index name ( Field name [( length )][ASC|DESC]);Delete index
DROP INDEX Index name ON Table name ;3、 ... and 、 Use cases of index creation
3.1 General index
Common query Single table :

Build index :
-- Build index
create index idx_moduleid on t_log(moduleid);
Query again : Speed up

3.2 unique index : The corresponding column value cannot be repeated
create unique index idx_url on t_log(url);
3.3 primary key : The fastest

3.4 Composite index :
create index idx_userid_moduleid_url on t_log(userid,moduleid,url);
The leftmost segment matching principle :


Four 、 Implementation plan
3.1 Execution plan syntax :
MySQL tuning :
# Example 1 :explain
explain select * from t_user;


# notes : adopt left join and right join verification ;id equally ( Pay attention to the implementation of the plan table Column ),left join Scan first a surface , Scan again b surface ;right join Scan first b surface , Scan again a surface

3.2 id The bigger it is , priority .

3.3 select_type
#1)SIMPLE( Simple SELECT, Don't use UNION Or subquery, etc )

3.4 PRIMARY( If the query contains any complex sub parts , The outermost select Marked as PRIMARY)
# SUBQUERY( First in subquery SELECT)

3.5 Use index correctly
#1) Use like When the sentence is ,% The index is only used on the right .
# It works

# Invalid

#2)or The index will become invalid only if there is an unindexed column in the condition
# Invalid

#3) The type of condition is inconsistent
# Invalid

# It works

#4)!= Number ( exception : If it's a primary key , The index will go )
# It works
order by
Be careful :MySQL5.7 Invalid version

OK, These are the Leaf Today I bring some information about MySQL Knowledge sharing , If you like, you can focus on learning and progress together , I'll see you next time !!!
边栏推荐
- 高阶函数的应用:手写Promise源码(二)
- NepCTF 2022 MISC <签到题>(极限套娃)
- [untitled]
- 通用查询&分页代码
- Simple implementation of rectangular area block
- js的继承方式
- Application of higher-order functions: handwritten promise source code (4)
- Pyspark learning notes
- Points for attention when using El table to lazy load tree tables
- [pytho-flask筆記5]藍圖簡單使用
猜你喜欢
![[C language] what is a function? Classification and emphasis of functions (help you quickly classify and remember functions)](/img/3b/39be991aa30b31ff5fb49905de36cf.jpg)
[C language] what is a function? Classification and emphasis of functions (help you quickly classify and remember functions)

Error handling of "listener not started or database service not registered" in Oracle database creation

自定义公式输入框

MySQL索引&&执行计划

upload-lab第1~4关

laravel api接口+令牌认证登录

The problem that GBK codec cannot decode may be caused by the file name

渗透测试基础

基于el-table的树形表格及js-xlsx实现下载excel功能(二)

TypeScript介绍
随机推荐
Cell sends SMS asynchronously
Anti shake and throttling of JS
D2dengine edible tutorial (1) -- the simplest program
Sorting out common SQL interview questions and answers
Keras saves the best model in the training process
【6.28】
Simple implementation of rectangular area block
使用el-table懒加载树形表格时的注意点
JS class array objects and methods of class array conversion (ES6, Es5)
[untitled]
Flex+js realizes that the height of the internal box follows the maximum height
Some operations of composer
pycharm如何正确打包ocr且让打包出来的exe尽量小
Large factory interview machine learning algorithm (0): Feature Engineering | data preprocessing
Resizeobserver ignoring buried point records - loop limit exceeded
[C language] what is a function? Classification and emphasis of functions (help you quickly classify and remember functions)
Paging and filtering
[untitled]
自定义MVC(上)
The problem that GBK codec cannot decode may be caused by the file name