当前位置:网站首页>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
边栏推荐
- Introduction to golang garbage collection
- [secretly kill little buddy pytorch20 days -day02- example of image data modeling process]
- [postgresql]postgresql custom function returns an instance of table type
- Sightseeing - statistics of the number of shortest paths + state transfer + secondary small paths
- For in, foreach, for of
- Transformation between yaml, Jason and Dict
- [Yugong series] February 2022 Net architecture class 004 ABP vNext used in WPF project
- Haven't expressed the artifact yet? Valentine's Day is coming. Please send her a special gift~
- 电子科技大学|强化学习中有效利用的聚类经验回放
- Analysis of gas fee setting under eip1559
猜你喜欢

JVM JNI and PVM pybind11 mass data transmission and optimization

Interval product of zhinai sauce (prefix product + inverse element)

Discussion Net legacy application transformation

The global industrial design revenue in 2021 was about $44360 million, and it is expected to reach $62720 million in 2028. From 2022 to 2028, the CAGR was 5.5%

Software testing skills, JMeter stress testing tutorial, obtaining post request data in x-www-form-urlencoded format (24)

设计电商秒杀系统

Scientific research document management Zotero

Hcie security Day12: supplement the concept of packet filtering and security policy

MySQL——数据库备份

thrift go
随机推荐
设计电商秒杀系统
Study diary: February 14th, 2022
Borui data and Sina Finance released the 2021 credit card industry development report
How to handle wechat circle of friends marketing activities and share production and release skills
Service discovery and load balancing mechanism -service
Basic number theory -- Chinese remainder theorem
Scientific research document management Zotero
同花顺开户注册安全靠谱吗?有没有风险的?
MySQL 8.0 data backup and recovery
JVM JNI and PVM pybind11 mass data transmission and optimization
What is the maximum number of concurrent TCP connections for a server? 65535?
Basic knowledge of dictionaries and collections
thrift go
Qualcomm platform WiFi update disconnect end open event
leetcode-540. A single element in an ordered array
Capturing and sorting out external articles -- autoresponder, composer, statistics [III]
内存分析器 (MAT)
Design e-commerce seckill system
Xai+ network security? Brandon University and others' latest "interpretable artificial intelligence in network security applications" overview, 33 page PDF describes its current situation, challenges,
Cesiumjs 2022 ^ source code interpretation [7] - Analysis of the request and loading process of 3dfiles