请教怎么优化查询效率

Lcindep110 2017-09-16 07:06:55
怎么优化这张表呢?现在查询好慢
...全文
224 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjcxc 2017-09-21
  • 打赏
  • 举报
回复
估计是自定义函数的问题,你可以试试去掉函数,仅做查询看看效率
qq_30635781 2017-09-21
  • 打赏
  • 举报
回复
先算运算,再查
ACMAIN_CHM 2017-09-21
  • 打赏
  • 举报
回复
create index xxx on jh_device_upload_5387(terminal,newFinishHour)
Lcindep110 2017-09-21
  • 打赏
  • 举报
回复
EXPLAIN select terminal, avg(fun_get_value(substring(filedir,113,16))) as noise, avg(fun_get_value(substring(filedir,129,16))) as pm25, avg(fun_get_value(substring(filedir,145,16))) as pm10, avg(fun_get_value(substring(filedir,161,16))) as temperature, avg(fun_get_value(substring(filedir,177,16))) as humidity, avg(fun_get_value(substring(filedir,193,16))) as windspeed, avg(fun_get_value(substring(filedir,225,16))) as tsp,newFinishHour as d from jh_device_upload_5387 FORCE INDEX(terminal_newFinishMinute) where terminal=5387 and newFinishMinute>=201708210000 and newFinishMinute<=201709211459 group by terminal,d 1 SIMPLE jh_device_upload_5387 range terminal_newFinishMinute terminal_newFinishMinute 13 22956 Using where; Using temporary; Using filesort
Lcindep110 2017-09-21
  • 打赏
  • 举报
回复
show index from jh_device_upload_5387 jh_device_upload_5387 0 PRIMARY 1 id A 45901 BTREE jh_device_upload_5387 0 PRIMARY 2 terminal A 45901 BTREE jh_device_upload_5387 0 PRIMARY 3 InfoType A 45901 BTREE jh_device_upload_5387 1 newFinishMonth 1 newFinishMonth A 2 YES BTREE jh_device_upload_5387 1 newFinishDate 1 newFinishDate A 108 YES BTREE jh_device_upload_5387 1 newFinishHour 1 newFinishHour A 1207 YES BTREE jh_device_upload_5387 1 newFinishMinute 1 newFinishMinute A 45901 YES BTREE jh_device_upload_5387 1 terminal_newFinishMinute 1 terminal A 2 BTREE jh_device_upload_5387 1 terminal_newFinishMinute 2 newFinishMinute A 45901 YES BTREE
Lcindep110 2017-09-21
  • 打赏
  • 举报
回复
引用 1 楼 Lcindep110 的回复:
引用 2 楼 ACMAIN_CHM 的回复:
文本方式贴出(不要贴图!) show create table ... explain select ....show index from 以供分析
好的
Oh_my_godness 2017-09-19
  • 打赏
  • 举报
回复
你这个sql中计算的太多了,sql最好就是准确查询,条件多没关系,但是运算会严重拖延查询效率,可以尝试将运算的部分放到代码中执行
ACMAIN_CHM 2017-09-18
  • 打赏
  • 举报
回复
文本方式贴出(不要贴图!) show create table ... explain select ....show index from 以供分析
Lcindep110 2017-09-16
  • 打赏
  • 举报
回复

56,678

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧