sql server - How Can I speed up my SQL Query -
i'm running query:
select time_id, site_type_id, abandoned_id, worktype_id, sum (staging.dbo.incoming_measure.ring_time) ring_time, sum (staging.dbo.incoming_measure.hold_time) hold_time, sum (staging.dbo.incoming_measure.talk_time) talk_time, sum (staging.dbo.incoming_measure.acw_time) acw_time, count(*) callcount incoming_measure inner join datamartend.dbo.time_dim on incoming_measure.starttimedate between time_dim.time_start , time_dim.time_end inner join datamartend.dbo.site_type_dim on incoming_measure.dbid = site_type_dim.site_type_code inner join datamartend.dbo.abandoned_call_dim on incoming_measure.abandoned = abandoned_call_dim.abandoned_value inner join datamartend.dbo.work_type_dim on incoming_measure.dbid = work_type_dim.mig_site_id , work_type_dim.work_type_code = incoming_measure.queue , incoming_measure.starttimedate between work_type_dim.dimeffectivestartdtm , work_type_dim.dimeffectiveenddtm group time_id, site_type_id, abandoned_id, worktype_id
it returning correct results taking around 8minutes run , wondered if had advice on how can speed query? main issue if part of project in have demonstrate end result client , allowed 10 minutes demonstrate (university rules) , query 30% of project.
the bulk of estimated execution sort 57%.
you may find query performs better if rewritten this:
select time_id, site_type_id, abandoned_id, worktype_id, sum (im.ring_time) ring_time, sum (im.hold_time) hold_time, sum (im.talk_time) talk_time, sum (im.acw_time) acw_time, count(*) callcount incoming_measure im inner join datamartend.dbo.time_dim td on dateadd(mi, 15*floor(datediff(mi, dateadd(dd, datediff(dd,0,im.starttimedate), 0), im.starttimedate ) / 15), dateadd(dd, datediff(dd,0,im.starttimedate), 0) ) = td.time_start inner join datamartend.dbo.site_type_dim std on im.dbid = std.site_type_code inner join datamartend.dbo.abandoned_call_dim acd on im.abandoned = acd.abandoned_value inner join datamartend.dbo.work_type_dim wtd on im.dbid = wtd.mig_site_id , im.queue = wtd.work_type_code , im.starttimedate between wtd.dimeffectivestartdtm , wtd.dimeffectiveenddtm group time_id, site_type_id, abandoned_id, worktype_id
- time dimension joined on equals value, rather on value between range of values.
if not improve performance, suggest creating indexed view on existing query, , selecting indexed view new query - can find more creating indexed views here, while there information on limitations here.
Comments
Post a Comment