当前位置:网站首页>MySQL-02. Understanding of indexes at work
MySQL-02. Understanding of indexes at work
2022-06-23 10:24:00 【cfcoolya】
Indexes
1. What is index ?
- help MySQL Data structure for efficient data acquisition
- It's equivalent to a catalog , It's a document , Need to occupy physical space
2. Use scenarios
- where Back field , Index this field (alter table Table name add index( Field name )).
- order by Later fields , If there is no index , The execution plan will use external sorting for all the queried data , Affect performance , After using sorting , The index itself is ordered , Therefore, the data can be extracted one by one according to the index order and mapping relationship .
- Yes join Statement matching relationship on The involved fields are indexed to improve efficiency .
- As much as possible in select Write only the necessary query fields after , Increase the probability of index coverage .
3. Three ways to create indexes
3.1 In execution CREATE TABLE Create index
CREATE TABLE user_index2 (
id INT auto_increment PRIMARY KEY,// primary key
first_name VARCHAR (16),
last_name VARCHAR (16),
id_card VARCHAR (18),
information text,
KEY name (first_name, last_name),// General index
FULLTEXT KEY (information),// Full-text index
UNIQUE KEY (id_card)// unique index
);
3.2 Use ALTER TABLE Command to add index
ALTER TABLE table_name ADD INDEX index_name (column_list);
3.3 Use CREATE INDEX Command to create
CREATE INDEX index_name ON table_name (column_list);
3.4 Delete index
alter table user_index drop KEY name;
alter table user_index drop KEY id_card;
alter table user_index drop KEY information;
4. Avoid index invalidation
- Contrary to " The best left prefix rule ", Leading brother can't die , The middle brother can't break
- Do nothing on the index column ( Calculation 、 function )
- Use != perhaps <> Causes a full table scan
- is null,is not null You can't use indexes
- String without single quotes
边栏推荐
- 大作业合集
- 2021-05-07 constructor
- Different methods of PivotTable in SQL tutorial
- R和RStudio下载安装详细步骤
- NOI OJ 1.4 01:判断数正负 C语言
- Multithreaded exercises
- RPC kernel details you must know (worth collecting)!!!
- NOI OJ 1.3 05:计算分数的浮点数值 C语言
- sql编写问题,求出当月和上月的环比值
- 135137138445 unable to remotely connect to the database due to disabling
猜你喜欢

Numerical calculation method

Successful experience of postgraduate entrance examination in materials and Chemical Engineering (metal) of Beijing University of Aeronautics and Astronautics in 2023

Several practical software sharing

Gorm advanced query

线程池在项目中使用的心得体会

sql根据比较日期新建字段

JVM简单入门-01

Copilot免费时代结束!正式版67元/月,学生党和热门开源项目维护者可白嫖

个人博客系统毕业设计开题报告

Mathematical analysis_ Notes_ Chapter 2: real and plural numbers
随机推荐
2021-04-27类和对象
2021-04-12 the first implementation of linked list!!!
What is JSX in the JS tutorial? Why do we need it?
The era of copilot free is over! The official version is 67 yuan / month, and the student party and the defenders of popular open source projects can prostitute for nothing
MySQL-01.工作中数据库优化和explain字段知识的总结
文件IO(1)
验证码redis实践总结
Tencent tangdaosheng: practice "science and technology for the good" and promote sustainable social value innovation
2021-05-12 interface definition and Implementation
Go unit test
JS教程之 什么是 JSX?为什么我们需要它?
Simple understanding of quick sort
NOI OJ 1.4 01:判断数正负 C语言
Liujinhai, architect of zhongang Mining: lithium battery opens up a Xintiandi for fluorine chemical industry
Musk's 18-year-old son petitioned to change his name to sever the father son relationship
Distributed common interview questions
谷贱伤农,薪贱伤码农!
laravel8 beanstalk 使用说明
Five SQL functions for operation date that must be known in SQL tutorial
NOI OJ 1.3 11:计算浮点数相除的余数 C语言