当前位置:网站首页>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
边栏推荐
- Brief analysis of ref nerf
- Summary of common operation and maintenance commands
- Compilation Principle -- syntax analysis
- C 10 new feature [caller parameter expression] solves my confusion seven years ago
- How to handle wechat circle of friends marketing activities and share production and release skills
- Mysql database ----- common commands of database (based on database)
- Analyse de REF nerf
- Basic preprocessing and data enhancement of image data
- [secretly kill little buddy pytorch20 days -day02- example of image data modeling process]
- 阻塞非阻塞和同步异步的区分 参考一些书籍
猜你喜欢

Etcd 基于Raft的一致性保证

内存分析器 (MAT)

19、 MySQL -- SQL statements and queries

Talk about daily newspaper design - how to write a daily newspaper and what is the use of a daily newspaper?

Is it OK for fresh students to change careers to do software testing? The senior answered with his own experience

2022 high voltage electrician examination and high voltage electrician reexamination examination

Custom view incomplete to be continued

leetcode-540. A single element in an ordered array

Research Report on the overall scale, major manufacturers, major regions, products and application segmentation of rotary tablet presses in the global market in 2022

你真的知道自己多大了吗?
随机推荐
Cannot load driver class: com. mysql. cj. jdbc. Driver
[secretly kill little buddy pytorch20 days -day02- example of image data modeling process]
2022 high voltage electrician examination and high voltage electrician reexamination examination
Capture de paquets et tri du contenu externe - - autoresponder, composer, statistiques [3]
Etcd raft Based Consistency assurance
Quickly distinguish slices and arrays
Qualcomm platform WiFi update disconnect end open event
Link aggregation based on team mechanism
Experience summary of database storage selection
浅议.NET遗留应用改造
Summary of common operation and maintenance commands
Kernel symbol table
Pengcheng cup Web_ WP
Transformer structure analysis and the principle of blocks in it
Memory analyzer (MAT)
《ActBERT》百度&悉尼科技大学提出ActBERT,学习全局局部视频文本表示,在五个视频-文本任务中有效!...
Advanced collaboration: coroutinecontext
Qt6 QML Book/Qt Quick 3D/基础知识
How to handle wechat circle of friends marketing activities and share production and release skills
Qualcomm platform WiFi -- P2P issue