当前位置:网站首页>Several index utilization of joint index ABC
Several index utilization of joint index ABC
2022-07-07 06:49:00 【Adong-007】
For composite indexes :Mysql Use the fields in the index from left to right , A query can use only a part of the index , But only the far left part . For example, the index is key index (a,b,c). Can support a | a,b| a,b,c 3 Combination of search , But does not support b,c Search for . When the leftmost field is a constant reference , The index is very efficient .
Here are some examples :
(1) select * from myTest where a=3 and b=5 and c=4; ---- abc The order
abc All three indexes are in where It's used in the conditions , And it all worked
(2) select * from myTest where c=4 and b=6 and a=3;
where The order of the conditions inside will be changed before the query mysql Automatic optimization , The effect is the same as the sentence
(3) select * from myTest where a=3 and c=7;
a Use index ,b of no avail , therefore c There is no index effect (b Not used , So the index cannot reach c , therefore c Unused index )
(4) select * from myTest where a=3 and b>7 and c=3; ---- b Range value , The breakpoint , blocked c The index of
a Yes ,b Also used. ,c Not used , This place b It's the range value , It's also a breakpoint , It just uses the index itself
(5) select * from myTest where b=3 and c=4; — Federated indexes must be used sequentially , And need to use it all
because a The index is not used , So here bc No indexing effect
(6) select * from myTest where a>4 and b=7 and c=9;
a Yes b Not used ,c Not used (a The range is used, so , Equivalent to a breakpoint , After that b,c No index is used )
(7) select * from myTest where a=3 order by b;
a Index is used ,b Index effect is also used in result sorting ,a In any of the following paragraphs b It's in order
(8) select * from myTest where a=3 order by c;
a Index is used , But this place c No ranking effect , Because there's a break in the middle , Use explain You can see filesort
(9) select * from mytable where b=3 order by a;
b No index is used , Sorting a It doesn't have an indexing effect
The following conditions will invalidate the index :
1. Do nothing on the index column ( Calculation 、 function 、( Automatically or Manual ) Type conversion ), It will cause index invalidation and turn to full table scan
2. The storage engine cannot use the column to the right of the index range condition ( for example Only for b , c)
3. Try to use overlay index ( Queries that only access the index ( The index column is consistent with the query column )), Reduce select ***
4.mysql In use is not equal to (!= perhaps <>) When ** Failure to use the index will result in a full table scan
5.is null,is not null You can't use indexes
6.ike Start with a wildcard (’%abc…’)mysql Index invalidation will become a full table scan operation . problem : solve like‘% character string %’ When index is not used7. String index is invalid without single quotation marks
Suggest :
- For single key indexes , Try to choose the current query Better filtering index
- When choosing a composite index , At present Query The most filterable field in the index field order , The higher the position, the better .
- When choosing a composite index , Try to include the current query Medium where Index of more fields in clause
- When choosing a composite index , Try to include the current query Medium where Index of more fields in clause
- By analyzing statistics and adjusting as much as possible query To achieve the purpose of selecting the appropriate index
边栏推荐
猜你喜欢
FlexRay通信协议概述
如何给目标机器人建模并仿真【数学/控制意义】
多个kubernetes集群如何实现共享同一个存储
缓存在高并发场景下的常见问题
LM11丨重构K线构建择时交易策略
ICML 2022 | explore the best architecture and training method of language model
Linear algebra (1)
一文带你了解静态路由的特点、目的及配置基本功能示例
Force deduction 62 different paths (the number of all paths from the upper left to the lower right of the matrix) (dynamic planning)
Redis(二)—Redis通用命令
随机推荐
大促过后,销量与流量兼具,是否真的高枕无忧?
unity3d学习笔记
Stack and queue-p79-10 [2014 unified examination real question]
「运维有小邓」符合GDPR的合规要求
7天零基础能考证HCIA吗?华为认证系统学习路线分享
Google Chrome browser released patch 103.0.5060.114 to fix the 0-day vulnerability
docker-compose启动redis集群
What books can greatly improve programming ideas and abilities?
循环肿瘤细胞——Abnova 解决方案来啦
Doctoral application | Professor Hong Liang, Academy of natural sciences, Shanghai Jiaotong University, enrolls doctoral students in deep learning
面试中有哪些经典的数据库问题?
哈趣投影黑马之姿,仅用半年强势突围千元投影仪市场!
Etcd database source code analysis -- starting from the start function of raftnode
化工园区危化品企业安全风险智能化管控平台建设四大目标
怎样查找某个外文期刊的文献?
Redis(二)—Redis通用命令
中英文说明书丨ProSci LAG-3 重组蛋白
ANR 原理及实践
毕业设计游戏商城
VIM mapping large K