这条语句 内部查询很快,查询时间为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.   

    你可以把数据最少的表放在第一个,然后把a.state = 1 放第一个,where 后面找一个能取出最少记录的条件放第二个,
      

  2.   


    大家都不要猜测,原因就在 like '43%' 我不加这个条件查询快,加了条件查询慢,其它的都是次要的
      

  3.   

    把 tbl_organization f 换成(select * from tbl_organization where code like '43%') f 试试,去掉外面的过滤。另外,最好在 tbl_organization 表的code列上建索引
      

  4.   

    看看执行计划,
    explain plan for select .....;SELECT plan_table_output
      FROM TABLE(DBMS_XPLAN.DISPLAY('PLAN_TABLE'));