当前位置:网站首页>[learning] database: several cases of index failure
[learning] database: several cases of index failure
2022-07-05 06:20:00 【Daidou family】
Catalog
- Seven cases of index failure
- Column and column comparison index failure
- Column existence NULL Value index failure
- NOT Condition index failure
- LIKE Wildcard index failure
- The query condition includes function index invalidation
- Data type hermit conversion index failure
- If msyql When you think full table scanning is faster ( Less data ) Index failure
- When is index unnecessary ?
Seven cases of index failure
Column and column comparison index failure
- Two columns are indexed separately , The following situations will not be indexed
select * from test where id = c_id
Column existence NULL Value index failure
- When we talk about database tables , It should be avoided as much as possible NULL Value appears
- If it can't be avoided , You'd better give one, too default The default value is
- The default value can be 0,-1
- The default value of the string can be “ An empty string ”
NOT Condition index failure
where The following conditions will cause the index to fail
- <>
- in
- not in
- not exists
select * from test where id<>500;
select * from test where id in (1,2,3,4,5);
select * from test where not in (6,7,8,9,0);
select * from test where not exists (select 1 from test_02 where test_02.id=test.id);
LIKE Wildcard index failure
- Try to use post wildcards for example ’name%’, Because when walking the index, it will match the index before , It can be found at this time
- If it is ‘%name’ Conditions of the query Pre wildcard
- The execution plan prefers to choose full table scanning , Therefore, the index will be invalid
The query condition includes function index invalidation
- In terms of query conditions, try not to use functions for indexes
- ABS,UPPER,DATE,DAY,YEAR etc.
- for example :
select * from test where upper(name) = 'SUPPER';
select * from test where DATE(swap_time) = DATE( date_sub( CURRENT_DATE, INTERVAL 1 DAY ) );
- This is not going to be indexed , Because the index may be different when it is built and after calculation , Unable to locate index .
- But if the query condition is not to calculate the index column , So you can still go through the index , for example :
select * from test where name = upper('sunnnn');
Data type hermit conversion index failure
- When the query condition has hermit transformation , The index will fail
- For example, in the database id yes NUMBER type , But at the time of inquiry , But in the following form :
select * from test where id = '123';
If msyql When you think full table scanning is faster ( Less data ) Index failure
When is index unnecessary ?
When the uniqueness of the field is poor
Frequently updated fields do not need to be
where Fields not used in conditions
Index usage <> when , Results the general
边栏推荐
- Sword finger offer II 058: schedule
- Winter vacation water test 1 Summary
- Data visualization chart summary (II)
- Sqlmap tutorial (II) practical skills I
- __ builtin_ Popcount() counts the number of 1s, which are commonly used in bit operations
- C job interview - casting and comparing - C job interview - casting and comparing
- 【Rust 笔记】13-迭代器(下)
- 做 SQL 性能优化真是让人干瞪眼
- 【LeetCode】Day94-重塑矩阵
- LeetCode 0108. Convert an ordered array into a binary search tree - the median of the array is the root, and the left and right of the median are the left and right subtrees respectively
猜你喜欢
Appium基础 — 使用Appium的第一个Demo
Arduino 控制的 RGB LED 无限镜
SPI details
QQ computer version cancels escape character input expression
Simple selection sort of selection sort
Introduction to LVS [unfinished (semi-finished products)]
Leetcode-6108: decrypt messages
Real time clock (RTC)
Alibaba's new member "Lingyang" officially appeared, led by Peng Xinyu, Alibaba's vice president, and assembled a number of core department technical teams
Traditional databases are gradually "difficult to adapt", and cloud native databases stand out
随机推荐
927. Trisection simulation
[rust notes] 17 concurrent (Part 1)
What's wrong with this paragraph that doesn't work? (unresolved)
Matrixdb V4.5.0 was launched with a new mars2 storage engine!
1039 Course List for Student
Series of how MySQL works (VIII) 14 figures explain the atomicity of MySQL transactions and the principle of undo logging
QQ电脑版取消转义符输入表情
Regulations for network security events of vocational group in 2022 Guizhou Vocational College skill competition
Appium基础 — 使用Appium的第一个Demo
[rust notes] 14 set (Part 1)
SQLMAP使用教程(一)
Alibaba's new member "Lingyang" officially appeared, led by Peng Xinyu, Alibaba's vice president, and assembled a number of core department technical teams
MySQL advanced part 2: storage engine
Sqlmap tutorial (II) practical skills I
[rust notes] 17 concurrent (Part 2)
Records of some tools 2022
【LeetCode】Day94-重塑矩阵
Applicable to Net free barcode API [off] - free barcode API for NET [closed]
Redis publish subscribe command line implementation
Is it impossible for lamda to wake up?