当前位置:网站首页>sql 使用到where和groupby时建立索引结果为啥是这样,原理是什么?
sql 使用到where和groupby时建立索引结果为啥是这样,原理是什么?
2022-08-11 01:46:00 【CSDN问答】
优化sql的时候,由于数据量比较大,一个简单的sql但执行速度特别慢
SELECT max(id) FROM log WHERE create_date <= "2022-08-03" GROUP BY code
试了这四种索引,create_date、code、(code,create_date)、(create_date,code)
网上查是说建立(create_date,code)组合索引,毕竟先执行where再执行groupby ,explain可以看到居然只使用到组合索引中的 create_date,没有使用到code,查询速度也没有变快
结果使用(code,create_date)组合索引是最快的,只需要1秒,explain命令查看索引的两列都用到了
为什么(code,create_date)是最快的,这到底是什么原理
补充一下:
建立create_date和code的单独索引用explain看到只走了code索引
这要是组合索引(code,create_date)中也只走了code我还好理解些,偏偏组合索引(code,create_date)中两个索引都走了
而组合索引(create_date,code)中只走了create_date
边栏推荐
- 软件测试面试题:缺陷等级应如何划分?
- 备战“金九银十”,软件测试功能 / 数据库 /linux/ 接口 / 自动化 / 测试开发面试真题解析
- Successfully resolved TypeError: can't multiply sequence by non-int of type 'float'
- HCIP-R&S By Wakin自用笔记(3)OSPF之引入外部路由、Forwarding-Address、汇总、特殊区域
- Construction inspection, no rules and no square
- Section 4-6 of the first week of the second lesson: Appreciation of medical prognosis cases + homework analysis
- OpenWrt之opkg详解
- loop word
- paddle2.3和torch1.8在SentenceBert上的性能对比
- vim取上个窗口号.
猜你喜欢
单面PCB布线阻抗的工程设计
Lianshengde W801 series 6-Analyze the Bluetooth communication source code of W801 from the perspective of WeChat applet (indicate method)
Oops Framework模板项目新手引导
FPGA learning column (xinlinx) serial communication -
The concept of services
阿里的数据同步神器——Canal
ARM开发(四)新手小白如何阅读芯片手册,裸机驱动开发步骤以及纯汇编实现点灯,汇编结合c点灯,c实现点灯
颠覆性创新招商,链动2+1是个怎么样的制度模式?
数据的存储(下)——浮点型在内存中的存储
Matlab矩阵(数组)元素过滤常见方法详解
随机推荐
15 DOM 扩展
【websocket】
The statistical data analysis, interview manual"
Lianshengde W801 series 6-Analyze the Bluetooth communication source code of W801 from the perspective of WeChat applet (indicate method)
Qt 中的隐式共享
FPGA learning column (xinlinx) serial communication -
88Q2110 通过C22方式访问C45 phy地址
Ambari Migrates Spark2 to Other Machines (Graphic and Text Tutorial)
微服务概念
联盛德W801系列6-从微信小程序的角度来分析W801的蓝牙通信源码(indicate方式)
请讲一讲JS中的 for...in 与 for...of (下)
生信实验记录(part3)--scipy.spatial.distance_matrix
MySQL索引与事务
软件测试面试题:单元测试的策略有哪些?
软件测试面试题:Web服务器指标指标?
Still using Xshell?You are out, recommend a more modern terminal connection tool, easy to use!
21. Aliyun oss
[Server data recovery] Data recovery case of lvm information and VXFS file system corruption caused by raid5 crash
0图中等 LeetCode565. 数组嵌套
【HFSS学习记录1】实例:宽带非对称多节定向耦合器设计