当前位置:网站首页>[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
边栏推荐
猜你喜欢
Appium foundation - use the first demo of appium
SPI 详解
[2021]IBRNet: Learning Multi-View Image-Based Rendering Qianqian
Sqlmap tutorial (1)
WordPress switches the page, and the domain name changes back to the IP address
Data visualization chart summary (I)
Arduino 控制的 RGB LED 无限镜
2021apmcm post game Summary - edge detection
Single chip computer engineering experience - layered idea
RGB LED infinite mirror controlled by Arduino
随机推荐
MySQL advanced part 1: View
How to set the drop-down arrow in the spinner- How to set dropdown arrow in spinner?
Basic explanation of typescript
MySQL advanced part 2: MySQL architecture
Traditional databases are gradually "difficult to adapt", and cloud native databases stand out
Error ora-28547 or ora-03135 when Navicat connects to Oracle Database
MySQL advanced part 2: the use of indexes
Simple selection sort of selection sort
QQ computer version cancels escape character input expression
数据可视化图表总结(一)
MySQL advanced part 1: index
SQLMAP使用教程(一)
【Rust 笔记】14-集合(下)
LeetCode-54
Leetcode heap correlation
Daily question 1189 Maximum number of "balloons"
Appium自动化测试基础 — Appium测试环境搭建总结
1.13 - RISC/CISC
[2020]GRAF: Generative Radiance Fields for 3D-Aware Image Synthesis
Data visualization chart summary (I)