当前位置:网站首页>[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
边栏推荐
- 【Rust 笔记】13-迭代器(下)
- 【LeetCode】Day94-重塑矩阵
- MIT-6874-Deep Learning in the Life Sciences Week 7
- Leetcode-6108: decrypt messages
- 1040 Longest Symmetric String
- Chart. JS - Format Y axis - chart js - Formatting Y axis
- Sqlmap tutorial (II) practical skills I
- Filter the numbers and pick out even numbers from several numbers
- JS quickly converts JSON data into URL parameters
- MySQL怎么运行的系列(八)14张图说明白MySQL事务原子性和undo日志原理
猜你喜欢

Doing SQL performance optimization is really eye-catching

栈 AcWing 3302. 表达式求值

博弈论 AcWing 892. 台阶-Nim游戏

Alibaba established the enterprise digital intelligence service company "Lingyang" to focus on enterprise digital growth

SPI 详解

Leetcode-6110: number of incremental paths in the grid graph

可变电阻器概述——结构、工作和不同应用

MySQL怎么运行的系列(八)14张图说明白MySQL事务原子性和undo日志原理

Overview of variable resistors - structure, operation and different applications

传统数据库逐渐“难适应”,云原生数据库脱颖而出
随机推荐
Single chip computer engineering experience - layered idea
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
[rust notes] 17 concurrent (Part 1)
Leetcode-1200: minimum absolute difference
CPU内核和逻辑处理器的区别
MIT-6874-Deep Learning in the Life Sciences Week 7
容斥原理 AcWing 890. 能被整除的数
Real time clock (RTC)
[BMZCTF-pwn] ectf-2014 seddit
4. 对象映射 - Mapping.Mapster
Chapter 6 relational database theory
Appium automation test foundation - Summary of appium test environment construction
RGB LED infinite mirror controlled by Arduino
C Primer Plus Chapter 15 (bit operation)
Filter the numbers and pick out even numbers from several numbers
Network security skills competition in Secondary Vocational Schools -- a tutorial article on middleware penetration testing in Guangxi regional competition
1040 Longest Symmetric String
Traditional databases are gradually "difficult to adapt", and cloud native databases stand out
Data visualization chart summary (I)
11-gorm-v2-02-create data