MySQL调优 —— Using temporary
来源:互联网 发布:json对象解析成列表 编辑:程序博客网 时间:2024/05/23 01:16
DBA发来一个线上慢查询问题, SQL如下(为突出重点省略部分内容):
select distinct article0_.id, 等字段 from article_table article0_, hits_table articlehit1_ where article0_.id=articlehit1_.id order by hits;
EXPLAIN结果:耗时4.03S
出乎意料, 竟然会有Using temporary, order by只用到了一张表, 正常情况下不会出现借助辅助表再进行排序的情况(这种情况是多个表都涉及到排序字段才会引起的), 正常情况应该是只在排序有关系的表排序后然后就进行连接操作(例如本例的inner join)。 索引什么的其实都建好了, 看type字段就能看出来, 可参考 MySQL调优 ---- LEFT JOIN
认真一看SQL语句, 竟然在主键id上加上了distinct, 这不是白白浪费了性能, 尝试修改语句为:
select article0_.id, 等字段 from article_table article0_, hits_table articlehit1_ where article0_.id=articlehit1_.id order by hits;
EXPLAIN结果: 耗时0.04S
竟然因为一个distinct修饰, 让MySQL认为两张表排序需要用到临时表, 真是一个奇葩的问题。 distinct非常耗时, 准备在下一篇博文详细介绍下。
3 1
- MySQL调优 —— Using temporary
- MySQL explain 的Using temporary; Using filesort
- mysql查询优化--临时表和文件排序(Using temporary; Using filesort问题解决)
- MySQL 调优 —— Using filesort
- using_where, Using temporary ,using_filesort 分享
- using_where, Using temporary ,using_filesort 分享
- mysql order by 造成语句 执行计划中Using filesort,Using temporary相关语句的优化解决
- 27.笔记 MySQL学习——暂时性表TEMPORARY的创建
- mysql temporary table
- Mysql temporary table
- Creating and Using Temporary Tables in Oracle
- Creating and Using a Temporary File
- [linux]using temporary as lvalue [-fpermissive]
- LOB(6)— Temporary LOBs
- mysql优化索引 —— Using filesort
- mysql优化索引 —— Using filesort
- mysql android—Installation using AndroPHP
- EXPLAIN sql优化方法2 Using temporary ; Using filesort
- codeforce #126Div2 200A Cinema 【优化暴力枚举】
- warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失
- 可合并堆。。。BZOJ1078
- 【进展】2015.08.04 增加 SEMAPHORE 释放功能,增加MUTEX权限判断,非Onwer任务不能解锁
- 踢毽子问题
- MySQL调优 —— Using temporary
- java.net.ServerSocket详解
- PHP的正则
- HDU 4008 Parent and son (数据结构)
- Ubuntu14.04配置使用无线连接WiFi热点
- [leetCode] Different Ways to Add Parentheses
- 【爱笑话7.0版】笑话两万篇,免费阅读,绝无广告
- 测试
- 黑马程序员———反射机制