当前位置:网站首页>What is an index in MySql?What kinds of indexes are commonly used?When does an index fail?
What is an index in MySql?What kinds of indexes are commonly used?When does an index fail?
2022-08-09 16:14:00 【Ran959】
I. What is an index
In a relational database, an index is a storage structure that separates and physically sorts the values of one or more columns in a database table.A list of logical pointers to the data pages in the table that physically identify these values.The function of the index is equivalent to the directory of the book, which can quickly find the desired content according to the page number in the directory.
Index (index): like the directory of a book, used to speed up the search efficiency;
The role of index: speed up search efficiency. Slow down insertion and deletion, modification efficiency. (Need to adjust index results synchronously)
Second, common index types
1. Primary key index
The primary key is a unique index and must be specified as PRIMARY KEY (ie primary key)
alter table table name add primary key (`field name`);
2. Unique index
All values of the index column can only appear once (that is, must be unique), and the value can be null
alter table table name add primary key (`field name`);
3. Ordinary index
The basic index type, the value can be null, there is no unique constraint
alter table table name add index (`field name`);
4. Full-text index
The index of full-text index is FULLTEXT type.Full-text indexes can be created on columns of type varchar, char, and text.Can be created via ALTER TABLE or CREATE INDEX
alter table table name add FULLTEXT(`field name`);
Three, under what circumstances does the index fail
1.Improper use of the like query will cause the index to fail
Wildcard % at the beginning will cause the index to fail
select * from table name where field name like '%__';
2. The best left prefix rule
If there are multiple indexes in a table, the best left prefix rule should be followed, that is, the query starts from the leftmost front column of the index and does not skip the columns in the index.
3. The data types on both sides of the query condition are inconsistent
边栏推荐
猜你喜欢
随机推荐
Mysql two engines comparison
生产者/消费者问题(线程信号)
流程控制学习
一种基于视频帧差异视频卡顿检测方案
量化投资者是如何获取实时行情数据的呢?
Servlet的生命周期
量化程序化交易如何去使用以及执行?
经典面试题 之 SQL优化
在量化交易过程中,散户可以这样做
FilenameFilter filters filenames
注解与反射
【基础版】整数加减乘除计算器
22岁测试工程师上来就内卷,起薪居然就18k,这谁顶得住?
【Qt5 + OpenGL】glPointSize(10); error: undefined reference to `__imp_glPointSize‘
相似图像的检测方法
OpenCV - matchTemplate image template matching
对于程序化交易,重在预测还是重在对策呢?
A Preliminary Study on Baidu Open Source e-chart
Selenium - 如何用xpath快速定位路径?
Swift中的Error处理





![[MySql]实现多表查询-一对一,一对多](/img/7e/8f1af4422a394969b28a553ead2c42.png)



