mysql - How to minimize the usage of these subqueries and increase the performance? -
it clause of subquery (columnnm = hierarchylvl#) changing. let me know way of improving performance of query. way rewrite subquery ? put in join ? use other functions?
select * (select (select top 1 itmtxt tm.code catcd = (select catcd tm.clienthierarchy objid='system' , tablenm='resume1' , columnnm ='hierarchylvl0' , delflg = 0) , delflg = 0 , lngcd in (0,-1) , itmcd = r1.hierarchylvl0) hierarchylvl0txt, (select top 1 itmtxt tm.code catcd = (select catcd tm.clienthierarchy objid='system' , tablenm='resume1' , columnnm ='hierarchylvl1' , delflg = 0) , delflg = 0 , itmcd=r1.hierarchylvl1 , lngcd in (0,-1)) hierarchylvl1txt, (select top 1 itmtxt tm.code catcd = (select catcd tm.clienthierarchy objid='system' , tablenm='resume1' , columnnm ='hierarchylvl2' , delflg = 0) , lngcd in (0,-1) , delflg = 0 , itmcd=r1.hierarchylvl2) hierarchylvl2txt, (select top 1 itmtxt tm.code catcd = (select catcd tm.clienthierarchy objid='system' , tablenm='resume1' , columnnm ='hierarchylvl3' , delflg = 0) , lngcd in (0,-1) , delflg = 0 , itmcd=r1.hierarchylvl3) hierarchylvl3txt, (select top 1 itmtxt tm.code catcd = (select catcd tm.clienthierarchy objid='system' , tablenm='resume1' , columnnm ='hierarchylvl4' , delflg = 0) , lngcd in (0,-1) , delflg = 0 , itmcd=r1.hierarchylvl4) hierarchylvl4txt, (select top 1 itmtxt tm.code catcd = (select catcd tm.clienthierarchy objid='system' , tablenm='resume1' , columnnm ='hierarchylvl5' , delflg = 0) , lngcd in (0,-1) , delflg = 0 , itmcd=r1.hierarchylvl5) hierarchylvl5txt, (select top 1 itmtxt tm.code catcd = (select catcd tm.clienthierarchy objid='system' , tablenm='resume1' , columnnm ='hierarchylvl6' , delflg = 0) , lngcd in (0,-1) , delflg = 0 , itmcd=r1.hierarchylvl6) hierarchylvl6txt, (select top 1 itmtxt tm.code catcd = (select catcd tm.clienthierarchy objid='system' , tablenm='resume1' , columnnm ='hierarchylvl7' , delflg = 0) , lngcd in (0,-1) , delflg = 0 , itmcd=r1.hierarchylvl7) hierarchylvl7txt, (select top 1 itmtxt tm.code catcd = (select catcd tm.clienthierarchy objid='system' , tablenm='resume1' , columnnm ='hierarchylvl8' , delflg = 0) , lngcd in (0,-1) , delflg = 0 , itmcd=r1.hierarchylvl8) hierarchylvl8txt, (select top 1 itmtxt tm.code catcd = (select catcd tm.clienthierarchy objid='system' , tablenm='resume1' , columnnm ='hierarchylvl9' , delflg = 0) , delflg = 0 , itmcd=r1.hierarchylvl9 , lngcd in (0,-1)) hierarchylvl9txt, sr.rsrcnum, sr.fllnm, isnull(mgr.fllnm,'') mgrnm, d.actid, d.goaldesctxt , d.cmpltstscd, (select top 1 itmtxt tm.code catcd = '12103' , itmcd = d.cmpltstscd , lngcd = 0 , delflg = 0) status, d.strtdt, d.enddt, dta tm.matrixgoal d inner join tm.sresource sr on d.rsrcid=sr.rsrcid , sr.delflg=0 , sr.stscd<>1 , sr.rsrcid > 7 left join tm.sresource mgr on mgr.rsrcid=sr.mgr1id , mgr.delflg=0 , mgr.stscd<>1 inner join tm.resume1 r1 on r1.rsrcid=sr.rsrcid
your subquery part can re-written below using in
operator
select top 1 itmtxt tm.code catcd in (select catcd tm.clienthierarchy objid = 'system' , tablenm = 'resume1' , columnnm in ('hierarchylvl0', 'hierarchylvl1', 'hierarchylvl2', 'hierarchylvl3', 'hierarchylvl4', 'hierarchylvl5', 'hierarchylvl6', 'hierarchylvl7', 'hierarchylvl8', 'hierarchylvl9') , delflg = 0) , delflg = 0 , lngcd in (0, -1)
Comments
Post a Comment