这条语句 内部查询很快,查询时间为0.8秒,查询结果为258 条, 
如果将内部查询结果再做一次 CODE like '43%' 过滤, 速度也很快, 
但是,我将2条语句写在一起,查询速度非常慢,请教这是什么原因,应该如何优化 
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.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.   

    z.codes like '43%' 改为 substr(z.codes,1,2) = '43'
      

  2.   

    放外面是否是没有利用到
    CODE 上的索引呀,你的图片看不到
      

  3.   

    当然substr(z.codes,1,2) = '43'也没利用到索引
      

  4.   


    1 楼方案 能够解决 但是我更想 做的就是, 我想要oracle 先 执行 括号里面的 语句, 因为括号里面 查出来 的数据 是小数据,对这批小数据 进行 like '43%' 过滤 应该不会很慢看不到执行计划图,去这里 
    http://download.csdn.net/source/1896703
      

  5.   

    看执行计划,放到外面的like 似乎又对tbl_organization 进行了一次全表扫描。为什么和怎么改,我不知道,等达人。