mysql - why this query takes so much time to execute? -


is there better way write this?

select date, nename, kpiname, sub_type1, kpi  ggsn_kpi_2017  date      in ('2017-08-19', '2017-08-18', '2017-08-17', '2017-08-16', '2017-08-15',      '2017-08-14', '2017-08-13')      , kpiname in('sm_succ_sess_act_ggsn', 'sm_fail_sess_act_ggsn', 'sm_succ_sess_act_p_gw', 'sm_fail_sess_act_p_gw',      'sm_succ_sess_act_sae_gw', 'sm_fail_sess_act_sae_gw',      'sm_downlink_bytes_m2m', 'sm_uplink_bytes_m2m')       group date, nename, kpiname       union       select date, nename, kpiname, sub_type1, kpi      ggsn_kpi_2016      date in ('2017-08-19', '2017-08-18', '2017-08-17', '2017-08-16',      '2017-08-15', '2017-08-14', '2017-08-13')      , kpiname in('sm_succ_sess_act_ggsn', 'sm_fail_sess_act_ggsn', 'sm_succ_sess_act_p_gw',      'sm_fail_sess_act_p_gw', 'sm_succ_sess_act_sae_gw',      'sm_fail_sess_act_sae_gw', 'sm_downlink_bytes_m2m', 'sm_uplink_bytes_m2m')      group date, nename, kpiname; 

there's 1 obvious performance antipattern in query. have

where date in ('2017-08-19', '2017-08-18', '2017-08-17', '2017-08-16',  '2017-08-15', '2017-08-14', '2017-08-13') 

if date datetime, timestamp, or date column, change

where date >= '2017-08-13'   , date <  '2017-08-20' 

or even

where date >= '2017-08-13'   , date <  '2017-08-13' + interval 1 week 

then create indexes on (date, kpiname) both tables. make where clause @ least partly sargable.

also, appear misusing group by. goes aggregate functions max() , avg(). mean order by?


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -