一个语句慢,如何更优化。。。。。急
SQL:
Select count(siim.siim_imp_bl_id) as blcount,
sum(decode(siim.siim_transfer_flag, 'Y ', 1, 0)) as transblcount,
sum(spgi.spgi_quantity) as cargoweight,
sum(decode(siim.siim_transfer_flag, 'Y ', spgi.spgi_quantity, 0)) as transcargoweight
from (select b.spgi_imp_bl_id, sum(b.SPGI_gross_weight) / 1000 spgi_quantity
from scargoinfo b
where b.spgi_record_type = '1 '
group by b.spgi_imp_bl_id) spgi,
cshipcanonical cshc,
shsailingschedule shss,
simportmanifest siim
where siim.siim_voyage_id = shss.shss_voyage_id(+)
and shss.shss_vessel_code = cshc.cshc_id(+)
and siim.siim_imp_bl_id = spgi.spgi_imp_bl_id(+)
and siim.siim_valid_flag = 'Y '
and siim.siim_voyage_id = '2683 '
and siim.siim_carrier_id = 'ESSA00100415 '
and shss.shss_eta_time > = to_date( '2006-01-01 ', 'yyyy-mm-dd hh24:mi:ss ')
and shss.shss_eta_time <= to_date( '2007-12-12 ', 'yyyy-mm-dd hh24:mi:ss ')
and shss.shss_berthing_time > = to_date( '2006-01-01 ', 'yyyy-mm-dd hh24:mi:ss ')
and shss.shss_berthing_time <= to_date( '2007-12-12 ', 'yyyy-mm-dd hh24:mi:ss ')
and SIIM.SIIM_ORG_ID = '139 '
该语句结果为1条记录,用时1.7S,如果把
(select b.spgi_imp_bl_id, sum(b.SPGI_gross_weight) / 1000 spgi_quantity
from scargoinfo b
where b.spgi_record_type = '1 '
group by b.spgi_imp_bl_id) spgi 去掉,用时为0.012s,我对scargoinfo的spgi_imp_bl_id,spgi_record_type,SPGI_gross_weight建立了联合索引,还是要0.84s,请问各位有更好的解决方案吗。
------解决方案--------------------单独执行
select b.spgi_imp_bl_id, sum(b.SPGI_gross_weight) / 1000 spgi_quantity
from scargoinfo b
where b.spgi_record_type = '1 '
group by b.spgi_imp_bl_id
要用多长时间,返回多少记录。