一个SQL语句优化问题,,急急急
SQL:
select A.SSEM_voyage_id,
sum(A.HC_CONTAINER_COUNTER) pre_SUM_HC
from (select SSEM_voyage_id,
sum(decode(SECR_cnt_type, 'HC ', 1, 0)) HC_CONTAINER_COUNTER
from SExportManifest
left join SContainerRequirement
on SSEM_exp_bl_id = SECR_exp_bl_id
and secr_org_id = : "1 "
where SSEM_SC_BEFORE_AFTER_FLAG in (0, 2, 4)
and (: "2 " IS NULL OR SSEM_voyage_id = : "7 ")
and (: "3 " IS NULL OR : "1 " IS NULL OR
SSEM_modify_time between
TO_DATE(: "4 ", 'YYYY-MM-DD HH24:MI:SS ') and
TO_DATE(: "5 ", 'YYYY-MM-DD HH24:MI:SS '))
and ssem_Org_Id = : "6 "
group by
SSEM_voyage_id,
SSEM_exp_bl_id
) A
group by A.SSEM_voyage_id
目前执行计划中SContainerRequirement是全表扫描,SExportManifest是TABLE ACCESS BY GLOBAL INDEX ROWID,2张表都是业务表,所以执行起来肯定慢了,大家有没有好的解决方案
[解决办法]
将几个字查询,能改成视图的就改成视图,然后从视图中查询,这样会提高一些效率
------解决方案--------------------
SContainerRequirement 表数据量小的话,直接连接了,全表扫描没有关系了
不然你可以改成exists
SSEM_exp_bl_id SECR_exp_bl_id 两列有索引,就可以了