当前位置:网站首页>MySQL - index
MySQL - index
2022-07-03 21:03:00 【Can't learn java】
List of articles
1、 brief introduction
MySQL The official definition of index is : Indexes (Index) Help MySQL Data structure for efficient data acquisition .
Index in a small amount of data , Not very useful , But when it comes to big data , The difference is obvious .
2、 Classification of indexes
2.1、 primary key (PRIMARy KEY)
- The only sign , The primary key cannot be repeated , A table can only have one primary key .
2.2、 unique index (UNIQUE KEY)
- Avoid duplicate data , The unique index can be repeated , A table can have multiple unique indexes
2.3、 General index (KEY/INDEX)
- default ,index,key Keyword to set
2.4、 Full-text index (FullText)
- Only under the specific database engine ,MySAM
- Quickly locate data
3、 Test index
3.1、 establish 100 Ten thousand data
CREATE TABLE `app_user` (
`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(50) DEFAULT'' COMMENT' The user nickname ',
`email` VARCHAR(50) NOT NULL COMMENT' User mailbox ',
`phone` VARCHAR(20) DEFAULT'' COMMENT' cell-phone number ',
`gender` TINYINT(4) UNSIGNED DEFAULT '0'COMMENT ' Gender (0: male ;1: Woman )',
`password` VARCHAR(100) NOT NULL COMMENT ' password ',
`age` TINYINT(4) DEFAULT'0' COMMENT ' Age ',
`create_time` DATETIME DEFAULT CURRENT_TIMESTAMP,
`update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=INNODB DEFAULT CHARSET=utf8 COMMENT = 'app User table '
-- Insert 100 Play data
DELIMITER $$ -- Before you write a function, you have to write , sign
CREATE FUNCTION mock_data()
RETURNS INT
BEGIN
DECLARE num INT DEFAULT 1000000;
DECLARE i INT DEFAULT 0;
WHILE i<num DO
INSERT INTO app_user(`name`,`email`,`phone`,`gender`,`password`,`age`)
VALUES(CONCAT(' user ',i),'[email protected]',CONCAT('15',FLOOR(RAND()*(999999999-100000000)+100000000)),
FLOOR(RAND()*2),UUID(),FLOOR(RAND()*100));
SET i=i+1;
END WHILE;
RETURN i;
END;
SELECT mock_data()
- Query the first 999999 Data :SELECT * FROM app_user WHERE
name
=‘ user 999999’;
3.2、 Add index
-- id_ Table name _ Field name
CREATE INDEX id_app_user_name ON app_user(`name`)
- Query the first 999999 Data :SELECT * FROM app_user WHERE
name
=‘ user 999999’;
4、 Indexing principles
- More indexes is not better
- Don't index frequently changing data
- A table with a small amount of data does not need to be indexed
- The index is usually added to the fields commonly used for query
边栏推荐
- University of Electronic Science and technology | playback of clustering experience effectively used in reinforcement learning
- XAI+网络安全?布兰登大学等最新《可解释人工智能在网络安全应用》综述,33页pdf阐述其现状、挑战、开放问题和未来方向
- TLS environment construction and plaintext analysis
- 淺析 Ref-NeRF
- 浅议.NET遗留应用改造
- 浅析 Ref-NeRF
- Phpexcel import export
- Interval product of zhinai sauce (prefix product + inverse element)
- Measurement fitting based on Halcon learning -- Practice [1]
- Thread, thread stack, method stack, the difference of creating thread
猜你喜欢
Sightseeing - statistics of the number of shortest paths + state transfer + secondary small paths
【愚公系列】2022年7月 Go教学课程 002-Go语言环境安装
Memory analyzer (MAT)
Do you really know how old you are?
Baohong industry | good habits that Internet finance needs to develop
Task of gradle learning
Basic preprocessing and data enhancement of image data
如临现场的视觉感染力,NBA决赛直播还能这样看?
Gee calculated area
强化學習-學習筆記1 | 基礎概念
随机推荐
Basic preprocessing and data enhancement of image data
Strange way of expressing integers (expanding Chinese remainder theorem)
Q&A:Transformer, Bert, ELMO, GPT, VIT
It is discussed that the success of Vit lies not in attention. Shiftvit uses the precision of swing transformer to outperform the speed of RESNET
leetcode-540. A single element in an ordered array
Baohong industry | good habits that Internet finance needs to develop
[Tang Laoshi] C -- encapsulation: member variables and access modifiers
Getting started with postman -- environment variables and global variables
Quickly distinguish slices and arrays
JVM JNI and PVM pybind11 mass data transmission and optimization
For in, foreach, for of
Qtablewidget control of QT
"Designer universe" APEC safety and health +: environmental protection Panda "xiaobaobao" Happy Valentine's Day 2022 | ChinaBrand | Asia Pacific Economic media
Analysis of gas fee setting under eip1559
How to modify the network IP addresses of mobile phones and computers?
Interval product of zhinai sauce (prefix product + inverse element)
@Transactional注解失效的场景
Single page application architecture
Task of gradle learning
你真的知道自己多大了吗?