当前位置:网站首页>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
边栏推荐
猜你喜欢
R language multiple linear regression, ARIMA analysis of the impact of different candidates in the United States on the economic GDP time series
如何开展性能测试,你知道吗?
nvidia-smi详解
MySQL索引与事务
Lianshengde W801 series 6-Analyze the Bluetooth communication source code of W801 from the perspective of WeChat applet (indicate method)
颠覆性创新招商,链动2+1是个怎么样的制度模式?
Section 4-6 of the first week of the second lesson: Appreciation of medical prognosis cases + homework analysis
2022年PMP报考指南
请讲一讲JS中的 for...in 与 for...of (下)
R语言多元线性回归、ARIMA分析美国不同候选人对经济GDP时间序列影响
随机推荐
第二课第一周第4-6节 医学预后案例欣赏+作业解析
Summarize the acquisition of commonly used file information QFileInfo in Qt: suffix, name, path, link
install dlib library
2022英伟达显卡排名天梯图
MySQL advanced query
划分字母区间[贪心->空间换时间->数组hash优化]
进程间通信方式(1)无名管道(全CSDN最用心的博主)
软件测试面试题:什么是α测试,β测试?
sql 使用到where和groupby时到底怎么建立索引?
FPGA learning column (xinlinx) serial communication -
软件测试面试题:什么是Negative测试?
最新国产电源厂家及具体型号pin-to-pin替代手册发布
Linux install redis database
leetcode 739. Daily Temperatures 每日温度(中等)
SyntaxError: invalid syntax
How to convert url to obj or obj to url
如何防止离职员工把企业文件拷贝带走?法律+技术,4步走
QT+VTK+PCL拟合圆柱并计算起始点、中止点
nvidia-smi详解
如何开展性能测试,你知道吗?