sql server - Decrease execution time of SQL query -
i've got question in terms of processing , making query more efficient whilst maintaining accuracy. before display query i'd point out basics of it.
i've got case manipulates where
-clause childs of parent. i've got 2 types of data need display; red , green type. red type has column (trk_trackergroup_lkid2
) set null
default, whereas green data has value in said column (ranging 5-7).
my problem need extract both types of data accurately count of outstanding issues in view, doing (by adding case) execution time goes < 1 second on 15 seconds.
this query (with mentioned case):
select ts.id trackerstartdateid, tsm.mappingtypeid, tsm.maptoid, tflk.trk_trackergroup_lkid, count(tf.id) cnt [dbo].[trk_startdate] ts inner join [dbo].[trk_startdatemap] tsm on ts.id = tsm.trk_startdateid , tsm.deletedflag = 0 inner join [dbo].[trk_trackerfeatures] tf on tf.trk_startdateid = ts.id , tf.deletedflag = 0 inner join [dbo].[trk_trackerfeatures_lk] tflk on tflk.id = tf.trk_feature_lkid ts.deletedflag = 0 , tf.applicabletoproject = 1 , tf.readyforwork = case -- here problem when tf.trk_trackerstatus_lkid2 null 0 else 1 end , tf.datestamp = (select max(tf2.datestamp) [dbo].[trk_trackerfeatures] tf2 inner join [dbo].[trk_trackerfeatures_lk] tflk2 on tflk2.id = tf2.trk_feature_lkid tf.trk_startdateid = tf2.trk_startdateid , tflk2.trk_trackergroup_lkid = tflk.trk_trackergroup_lkid) group ts.id, tsm.mappingtypeid, tsm.maptoid, tflk.trk_trackergroup_lkid, tf.datestamp
it functions 'parent' in sense grabs latest inserted data-set (using datestamp) every single child-group. necessary produce parent-report in ssrs report @ later time, @ moment problem (as mentioned above) execution time.
i'd hear if there suggestions on how decrease execution time whilst maintaining accuracy of query.
expected output:
without case this:
your problem condition cant use index
and tf.readyforwork = case -- here problem when tf.trk_trackerstatus_lkid2 null 0 else 1 end
try change
and ( tf.readyforwork = 0 , tf.trk_trackerstatus_lkid2 null or tf.readyforwork = 1 , tf.trk_trackerstatus_lkid2 not null )
but again should check explain analize
test if query using index or not.
Comments
Post a Comment