2
我編寫了一條SQL語句,各個語句運行良好,但是當我使用UNION將它們組合在一起時,語句花費的時間顯着延長。是否有我錯過的錯誤或使其更快的方法?UNION導致SQL語句運行慢很多
select bundle.bundle, bundle.week, bundle.sched_dt, dropper_assign.dropper_id
from bundle, dropper_assign
where bundle.bundle not in
(select bundle from forecast_entry)
and bundle.week = dropper_assign.week
and bundle.sched_zip3 = dropper_assign.zip3
and bundle.sched_dt = dropper_assign.sched_date
and bundle.project_cd = dropper_assign.project_code
and dropper_assign.dropper_id <> 10002
and bundle.project_cd = 'EXFC'
union
select bundle.bundle, bundle.week, bundle.sched_dt, splits.dropper_id
from bundle, splits
where bundle.bundle not in
(select bundle from forecast_entry)
and bundle.bundle = splits.bundle
and splits.dropper_id <> 10002
and bundle.project_cd = 'EXFC';
如果您確定沒有重複項,請改用'UNION ALL' – van