以下语句 分2层,内层查询速度很快,0.7秒就能查询出结果,结果不多,只有200多条, 如果在这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
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
like进行了全表编列,而且z.codes 又不是索引,当然就慢,ORDER BY 没有在索引列上,排序,也是全表扫描,慢
不是的,我这里 给code 建立了索引,去除 ORDER BY z.id desc
查询也很慢,只有 去除 z.codes like '43%' 查询才快