解决sql查询表数据太慢的方法之一

136 阅读1分钟

问题:

缩短 t_an_radio表查询的时间

t_an_radio 表查询的时间是 1.235s

image.png

t_survey_answer表的查询时间是 0.117s

image.png



  • 两种写法 缩短第一个表查询的时间--

  • 查询时间:0.067

select r.qu_id, r.qu_item_id,count(r.qu_item_id) count from t_an_radio r,t_survey_answer a where r.visibility=1 and  a.xf_task_id='4028923580d5b2ef0180d6112c6d0012' and r.belong_answer_id=a.id and a.handle_state=0 and a.data_state<>2  GROUP BY r.qu_item_id
  • 查询时间:0.066s
select r.qu_id, r.qu_item_id,count(r.qu_item_id)  from  t_an_radio r 
join t_survey_answer a on r.belong_answer_id = a.id and a.xf_task_id='4028923580d5b2ef0180d6112c6d0012'
GROUP BY r.qu_item_id