简体   繁体   中英

Is there a way this query can be optimized?

Below is my query, and is there a way to optimize my query so that the cost would be reduced

FYI : There's already index created on JTASK.JOBHANDLE and JLIST.HANDLE

SELECT JLIST.*, 
       JTASK.jtstatus   LATESTTASKSTATUS, 
       JTASK.jtruncount JOBRUNCOUNT, 
       JTASK.objecthandle 
FROM   esm_n_joblist JLIST 
       LEFT OUTER JOIN (SELECT JT1.jobhandle, 
                               JT1.taskstatus   JTSTATUS, 
                               JT2.rc           JTRUNCOUNT, 
                               JT1.objecthandle objecthandle 
                        FROM   esm_n_jobtasklist JT1, 
                               (SELECT Count(DISTINCT runid) RC, 
                                       jobhandle             JH, 
                                       Max (starttime)       MAXT 
                                FROM   esm_n_jobtasklist 
                                GROUP  BY jobhandle) JT2 
                        WHERE  JT1.jobhandle = JT2.jh 
                               AND JT2.maxt = JT1.starttime) JTASK 
                    ON JLIST.handle = JTASK.jobhandle; 

Below is the execution plan of the query

在此处输入图片说明

The index below has a good chance of speeding up your query:

create index ix_jtl1 on esm_n_jobtasklist (jobhandle, starttime, runid);

Please provide the execution plan BEFORE and AFTER you added this index.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2025 STACKOOM.COM