当前位置:网站首页>What are the precautions for using MySQL index? (answer from six aspects)
What are the precautions for using MySQL index? (answer from six aspects)
2022-07-26 00:12:00 【Orange ꦿ. ๓】
1. What is index
Index is a special database structure , There are one or more columns in the data table , You can quickly query the values in the data table , The equivalent of a catalogue of books , Quickly find the required content according to the page number of the table of contents
2. The principles of indexing
Queries are faster , Small footprint
1. To define the data column of the primary key, it is necessary to establish the index
2. Defining data columns with foreign keys requires indexing
3. Index the frequently queried data columns
4. For data columns that need to be queried quickly or frequently within a specified range
5. Frequently used where The data column in the sentence
6. It often appears in keywords order by、group by、distinct Later fields , Index . If you build a composite index , The order of the fields in the index should be the same as the order of the fields after these keywords , Otherwise the index will not be used .
7. Columns rarely involved in queries , Do not index columns with more duplicates
8. For the definition of text、image and bit、 Do not index columns of data type
9. Do not create columns that are accessed frequently
10. Limit the number of indexes , The index number generally does not exceed 3 individual , Not more than 5 individual . Indexing improves access speed , But too many indexes will affect the update of data
3. There are those indexes , Explain separately
1. General index : Ordinary index is the most basic index , It has no restrictions , The value can be empty , Only speed up queries
2. Uniqueness index : A unique index is similar to a normal index , Different : The value of the index column must be unique , Null value allowed . If it's a composite index , Then the combination of column values must be unique
3. Full-text index : Mainly used to find keywords in text , Rather than directly comparing the values in the index .fulltext Index is very different from other indexes , It's more like a search engine , Not simply where The parameters of the statement match
4. Single index ( Primary key ): Is a special unique index , A table can only have one primary key , No vacancy is allowed .
5. Multi column index ( Combine ): 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
4. In those cases, indexing doesn't work
1. Calculate columns or use functions , Then the column index is invalid
2. Does not match the data type
3.where Use in statement IS NULL perhaps IS NOT NULL
4. Reverse operation is used
5. Use link operation
6. stay where Use in OR when , One column has no index , Then all the other columns will not work
5. Notes on using index
1. Stop using functions and operations on columns , Cause failure
2. Avoid using or To join the conditions , Cause the index to fail and perform a full table scan
3.in Go to the index ,not in Index failure
4. Single column index and composite index . Try to use composite indexes , Use less single column indexes
5. If mysql Evaluation uses indexes more slowly than full tables . Index is not used
6. Range query right column , Index cannot be used
7. Try to use overlay index , avoid select * Try to use overlay index ( Queries that only access the index ( The citation column completely contains the query column )), Reduce select *. If the query column exceeds the index column, the efficiency will also be reduced
8. Leftmost prefix rule if multiple columns are indexed , Follow the leftmost prefix rule . It means that the query starts from the top left of the index , And don't skip columns in the index
9.is Null,is Not NULL Sometimes the index fails
10. With % At the beginning Like Fuzzy query , Index failure . If it's just tail blur matching , The index will not fail . If it's a fuzzy head match , Induced failure .
11. Full match , Specify specific values for all columns in the index . Under modified circumstances , The index works , High execution efficiency .
6. When you need to use an index
(1) Columns are often used for where In the condition
(2) There are a lot of null values in the column
(3) The table has hardly been modified
(4) Large amount of data , Only 2-4% The data is selected
边栏推荐
猜你喜欢

二叉树——404. 左叶子之和

二叉树——222. 完全二叉树的节点个数

The GUI interface of yolov3 (3) -- solve the out of memory problem and add camera detection function

Piziheng embedded: the method of making source code into lib Library under MCU Xpress IDE and its difference with IAR and MDK

YoloV4-tiny网络结构

J9 number theory: what is Dao mode? Obstacles to the development of Dao

bond网卡模式配置

Module II operation

二叉树——226. 翻转二叉树

GUI interface of yolov3 (2) -- beautify the page + output the name and quantity of the identified object
随机推荐
【一库】mapbox-gl!一款开箱即用的地图引擎
“群魔乱舞”,牛市是不是结束了?2021-05-13
Unity—欧拉角,四元数
Compile live555 with vs2019 in win10
二叉树——617. 合并二叉树
初阶C语言 - 分支语句(if、switch)
Getaverse,走向Web3的远方桥梁
@The underlying principle of Autowired annotation
最近随感,关于牛市和DeFi 2021-05-17
"Demons dance", is the bull market over? 2021-05-13
牛市还将继续,拿好手里的币 2021-05-08
URL address mapping configuration
拼多多根据ID取商品详情 API 的使用说明
MySQL——数据库日志
服务器如何搭建虚拟主机?
Binary tree - 110. Balanced binary tree
What does it mean that the web server stops responding?
Yes, UDP protocol can also be used to request DNS server
牛客/洛谷——[NOIP2003 普及组]栈
YoloV4-tiny网络结构