以下语句 分2层,内层查询速度很快,0.7秒就能查询出结果,结果不多,只有200多条,
因此如果 oracle 按照 先执行内部查询,再执行外部查询 的先后顺序,结果 是很快的,但是这个整体查询 速度却非常的慢,我觉得oracle 并未先查询内部,请求,这个如何优化。select * from(
select f.code codes , a.id,a.sealname,a.imagetype,a.proposer,a.orgid,a.workphone,a.mobile,a.email, 
a.sealtype,a.homephone,a.address,a.cardtype,a.card,a.state,a.country,a.province,
a.location,a.business,a.tax,a.sealorg,a.certificateorg, b.name as proposername,
c.name as orgname,d.name as sealtypename , e.state as statename, f.name as sealorgname, 
a.enc,a.hashcode,a.code,a.endday  FROM tbl_sealrequest a,tbl_user b,tbl_organization c,tbl_sealtype d,
tbl_sealrequeststate e,tbl_organization f  WHERE a.id IS NOT NULL and a.state <> 0 and a.proposer = b.id 
 and  a.orgid = c.id and a.sealtype = d.id  and a.state = e.id and a.sealorg = f.id  AND 
  a.state = 1
 ) z   where  z.codes like '43%' ORDER BY z.id desc

解决方案 »

  1.   

    为什么不写成一个呢?还有a.state <> 0 和 a.state = 1重复了select f.code codes , a.id,a.sealname,a.imagetype,a.proposer,a.orgid,a.workphone,a.mobile,a.email, 
    a.sealtype,a.homephone,a.address,a.cardtype,a.card,a.state,a.country,a.province, 
    a.location,a.business,a.tax,a.sealorg,a.certificateorg, b.name as proposername, 
    c.name as orgname,d.name as sealtypename , e.state as statename, f.name as sealorgname, 
    a.enc,a.hashcode,a.code,a.endday  
    FROM  tbl_sealrequest a,tbl_user b,tbl_organization c,tbl_sealtype d, 
          tbl_sealrequeststate e,tbl_organization f  
    WHERE a.proposer  = b.id 
    and   a.orgid     = c.id 
    and   a.sealtype  = d.id  
    and   a.state     = e.id 
    and   a.sealorg   = f.id 
    and   f.code like '43%'
    AND   a.id IS NOT NULL
    and   a.state = 1 
    ORDER BY a.id desc; 
      

  2.   

    Oracle的执行计划中是可以看到的,因Oracle解析是从右往左进行,因此建议在使用表之间的join时,将小表放到join的后面.
      

  3.   

    可以看看解析计划啊,可能tbl_sealrequest先用code对应的INDEX查。 
      

  4.   

    and   f.code like '43%'换成 substr(f.code,1,2)= '43'  试一下,速度还慢,就在这个字段建立函数索引。