当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
DSPE-PEG-Aldehyde,DSPE-PEG-CHO,磷脂-聚乙二醇-醛基MW:1000
Selenium - 如何用xpath快速定位路径?
约束性统计星号‘*’
Analysis: Which method is used to build a stock quantitative trading database?
redis6在centos7的安装
DBCO-PEG-DSPE,磷脂-聚乙二醇-二苯并环辛炔,在无铜离子的催化下反应
职业量化交易员对量化交易有什么看法?
Servlet的生命周期
Regular Expressions for Shell Programming
How can I know if quantitative programmatic trading is effective?
[ERR] 1273 - Unknown collation: ‘utf8mb4_0900_ai_ci‘
MySQL 原理与优化:Limit 查询优化
JVM简学笔记
如何让你的量化交易系统具有概率优势,具有正向收益预期呢?
生产者/消费者问题(线程信号)
分析:通过哪种方法来建立股票量化交易数据库?
shell之函数和数组
如何将List<Map>进行分组数值计算合并排序
常见的数学物理方程
常见自动化测试工具及框架的选用