各位好: 
  麻烦各位高人帮忙看看下面这两段脚本如何优化好,我修改后,15分钟还是跑不出数据,麻烦各位高手帮忙在不改变提数结果和字段的情况进行比较好的优化,由于这个比较急,所以在此向各位跪谢啦。 
脚本如下: select distinct to_char(region) region, com, vc_subno, vc_dissrv, 
vc_startdate, vc_enddate, vc_addinf, int_yxplanid, vc_rectype, 
vc_dealdate, vc_logid, vc_applaydate 
from indata_log 
where (region, com, vc_subno, int_yxplanid, vc_dissrv, nvl(vc_addinf, '-'), vc_startdate, 
case when vc_enddate is null or vc_enddate > '20200101000000' then '20300101000000' 
else to_char(to_date(vc_enddate, 'yyyymmddhh24miss')-1/24/60/60, 'yyyymmddhh24miss') end) 
in ( 
select region, 'WX' com, vc_subno, int_yxplanid, vc_dissrv,trim(nvl(vc_addinf, '-')), vc_startdate, /*af_trim*/ 
case when vc_enddate is null or vc_enddate > '20200101000000' then '20300101000000' 
else to_char(to_date(vc_enddate, 'yyyymmddhh24miss')-1/24/60/60, 'yyyymmddhh24miss') end 
from indata_log 
where com = 'WX' 
minus 
select region, 'WX' com, vc_subno, int_yxplanid, vc_dissrv, vc_addinf, vc_startdate, 
case when vc_enddate > '20200101000000' then '20300101000000' else vc_enddate end 
from indata_log 
where com = 'CA' and vc_source = '1' ) 
order by region, vc_applaydate); 
------以上sql语句中有distinct的地方,建议修改成group by形式,避免产生不必要的排序。以上脚本如何在不改变提数结果及不改变字段和值的前提进行优化呢。 
select to_char(a.applyoid) as recoid, '0' as subsid, a.privsetid as privid, c.disccode, d.billingnbr as affixinfo, 
'BILLNBR' AS affixtype, a.startdate, a.enddate, to_char(a.grpsubsid) grpsubsid, 'D' as idu,e.recdate, '' as applyoid, 
to_char(a.canceloid) as canceloid, b.memservnumber as servnumber, '0' as custid 
from dhw_yxfn a, dhw_jtcy b, yxfn_djjh c, jtw_jtyh d,clrz e 
where e.oid in (select oid from clrz where groupid in 
(select groupid from clrz where oid in 
(select recoid from group_member_recdetail where idu ='D' and recdate between :STARTDATE and :ENDDATE and memtype in (1,7)) 
and recdate between :STARTDATE and :ENDDATE ) 
and recdefid ='ChangeProduct') 
and a.grpsubsmemoid = b.oid  and a.region =%s/*and e.recdate between :STARTDATE and :ENDDATE*/ 
and a.privsetid = c.yxplanid and b.groupoid = d.subsid and a.canceloid=e.oid,esRegion.GetData()); 
--------以上语句如何在不改变提数结果及不改变字段和值的前提进行优化呢,偶优化了后,20分钟还是提不出数据,请高人指点。 

解决方案 »

  1.   

    select to_char(a.applyoid) as recoid, '0' as subsid, a.privsetid as privid, c.disccode, d.billingnbr as affixinfo, 
    'BILLNBR' AS affixtype, a.startdate, a.enddate, to_char(a.grpsubsid) grpsubsid, 'D' as idu,e.recdate, '' as applyoid, 
    to_char(a.canceloid) as canceloid, b.memservnumber as servnumber, '0' as custid 
    from dhw_yxfn a, dhw_jtcy b, yxfn_djjh c, jtw_jtyh d,clrz e ,
    (select recoid from group_member_recdetail where idu ='D' and recdate between :STARTDATE and :ENDDATE and memtype in (1,7)) 
    and recdate between :STARTDATE and :ENDDATE ) X,(select oid,groupid,recdefid from clrz) Y,(select oid,groupid from clrz)Z,
    where e.oid =z.oid and z.groupid=y.groupid and y.oid=x.recoid
    and y.recdefid ='ChangeProduct' 
    and a.grpsubsmemoid = b.oid  and a.region =%s/*and e.recdate between :STARTDATE and :ENDDATE*/ 
    and a.privsetid = c.yxplanid and b.groupoid = d.subsid and a.canceloid=e.oid,esRegion.GetData(); 第二段脚本我修改了下,主要把in改写成采用数据表的形式(不知道这种叫法准确不),或许效率会高一点
    你应该看下执行计划,在进行调试
      

  2.   

    大哥,这么多in,怪不得跑不出来呢,建议都改成exists