当前位置:网站首页>[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
边栏推荐
猜你喜欢
Gauss Cancellation acwing 884. Solution d'un système d'équations Xor linéaires par élimination gaussienne
Sqlmap tutorial (1)
MatrixDB v4.5.0 重磅发布,全新推出 MARS2 存储引擎!
博弈论 AcWing 893. 集合-Nim游戏
MySQL advanced part 2: MySQL architecture
Gaussian elimination acwing 884 Gauss elimination for solving XOR linear equations
There are three kinds of SQL connections: internal connection, external connection and cross connection
博弈论 AcWing 894. 拆分-Nim游戏
MySQL怎么运行的系列(八)14张图说明白MySQL事务原子性和undo日志原理
可变电阻器概述——结构、工作和不同应用
随机推荐
[rust notes] 13 iterator (Part 2)
Multi screen computer screenshots will cut off multiple screens, not only the current screen
1041 Be Unique
[BMZCTF-pwn] ectf-2014 seddit
博弈论 AcWing 892. 台阶-Nim游戏
Sqlmap tutorial (1)
Overview of variable resistors - structure, operation and different applications
博弈论 AcWing 891. Nim游戏
快速使用Amazon MemoryDB并构建你专属的Redis内存数据库
MySQL advanced part 2: SQL optimization
Leetcode-6109: number of people who know secrets
Record the process of configuring nccl and horovod in these two days (original)
【LeetCode】Day95-有效的数独&矩阵置零
MIT-6874-Deep Learning in the Life Sciences Week 7
A reason that is easy to be ignored when the printer is offline
How to generate an image from text on fly at runtime
【Rust 笔记】13-迭代器(中)
How to set the drop-down arrow in the spinner- How to set dropdown arrow in spinner?
Simple selection sort of selection sort
C Primer Plus Chapter 15 (bit operation)