当前位置:网站首页>Database index
Database index
2022-04-22 19:06:00 【Lingqiu, baigeiwang】
zero 、 Use navicat Of “ explain ” Button to view the execution plan , Click again every time , Otherwise, the explanation page is the previous implementation plan .
One 、 The design principle of index
1) Often used as query criteria 、 Fields that are used more frequently , Can be set as index column ;
2) Index , Try to use unique fields in the whole table , Build unique index , This is the most efficient way to query ;
3) When building a composite index , Pay attention to the field order ;
4) The more indexes, the better , Too many indexes will reduce DML( Database operation language ) The speed of , Need frequent increase 、 Delete 、 The changed table is greatly affected , Because every time you operate the database, you have to maintain the index . For less data 、 Try not to build indexes on tables with few queries .
Two 、 Composite index
1) Set up composite index , Pay attention to the order ; Because the pre index , Will also hit the composite index , So don't waste , Put the fields that are often used as query criteria first

2) As long as the leading index is included, the index will be combined in the name , It has nothing to do with order

3) The combined index columns are all in where in , You can hit the index . It's not about order .

4)where The condition only applies to the non leading columns of the composite index , Unable to hit index .

3、 ... and 、 Several situations that cause index failure
1、 When there are too many data rows in the query result ( More than the total number of rows in the table 30%), No index , Direct full table scan ;
2、where After the query , Use
> perhaps >=
< perhaps <=
!=
not in
is null
Don't go with the index
3、 There are operations on the column
Here are two sql The result is the same , But if there are operations on the column, do not go to the index
select * from test where object_id + 1 > 20000; // Full table
select * from test where object_id > 20000 - 1; // Indexes
4、 There is a function on the column
select * from test where to_char(CREATED, 'yyyy-mm-dd hh24:mi:ss') = '2021-04-01 22:24:03'; // Full table
select * from test where CREATED = to_date('2021-04-01 22:24:03', 'yyyy-mm-dd hh24:mi:ss'); // Indexes
5、 Implicit conversion
When Character type and When comparing numeric types ,Oracle Will convert character type to numeric type , namely TO_NUMBER(“STR_ID”)=3 , Then compare .
Suppose there is a field in the table STR_ID Is a string type , Then it will cause the following situations
a. select * from test where str_id = '3'; // Indexes
b. select * from test where str_id = 3; // Full table
b Missed Index , Because the database implicitly converts the fields , namely TO_NUMBER(“STR_ID”), This is equivalent to using functions on fields .
So what if the column is numeric ? Here are two sql They all go by the index , This is because ’3’ Will become 3, There is no implicit conversion of columns
a. select count(*) from test where data_object_id = 3; // 1 That's ok
b. select * from test where data_object_id = 3; // Full table
6、 Plan to use composite indexes , But no pre index columns , No index hits
版权声明
本文为[Lingqiu, baigeiwang]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204221901206067.html
边栏推荐
- Small LED screen / digital alarm clock display screen / LED billboard / temperature digital display and other LED nixie tube display driver ic-vk1640 / 1640B sop28 / ssop24 package
- 2019-11-19 solve the problem that go test executes a single test file and prompts undefined
- Cvpr2022 𞓜 collaborative dual stream visual language pre training model for cross modal retrieval
- What happens when you run the NPM install command?
- C#之委托
- RHCE-ansible
- 2020-12-15 rocksdb研究
- Fingerprint identification record
- 爱可可AI前沿推介 (4.22)
- P1794 solving many fish problem
猜你喜欢

剪切的文件在哪里?文件剪切丢失如何恢复?仅需3步

VS 2022 安装vld内存泄漏检测工具

系统分析师-论文写作 框架搭建

The 14th issue of HMS core discovery reviews the long article | enjoy the silky clip and release the creativity of the video

Cross chain asset interaction -- how to transfer KSM on Moonriver

【TCP】TCP 三次握手与四次挥手

With the rapid and savage growth of single chip microcomputer embedded industry, the demand of various posts also increases

Where is the cut file? How to recover the lost file cut? Just 3 steps

JSP learning (VIII. JDBC and file upload processing project)

【洛谷】P2372 yyy2015c01挑战算周长(BFS)
随机推荐
Data time-sharing market, data backup and individual stock rise and fall development of today's index items [11]
[TCP] TCP three handshakes and four waves
【TCP】TCP 三次握手与四次挥手
linux系统下redis相关问题
What does %[^\n] mean in C?
transfer方法详解
Network security -- the use of burp suite packet capture tool
Introduction to Alibaba micro service component Sentinel
【最佳实践】巡检项:内容分发网络(CDN)开启URL鉴权
ReDet 代码逐行解读
Talk about some opportunities I've missed over the years
图片转base64
Introduction to feign, a microservice invocation component
错误 C4996 ‘fopen‘: This function or variable may be unsafe. Consider using fopen_s instead. To disabl
GB8624-2012 与GB8624-2006 有什么区别?
2019-12-07 wav音频剪切与合并
漂亮舒服的KN95口罩,防护能力也很强
Aicoco AI frontier promotion (4.22)
Youth training camp - swipe questions and punch in - control the number of goroutines executed concurrently
Fingerprint identification record