2011-08-16 12 views
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'; 
+0

重複がない場合は、代わりに 'UNION ALL'を使用してください – van

答えて

4

UNIONは、2つのデータセットを取り、ユニークなオーバーラップを返します。つまり、重複を取り除くために時間を費やします。

UNION ALLただし、重複を削除するために結果セットを比較しません。

0

UNIONは大量のデータセットでは高価な操作になる可能性がある最終結果にDISTINCTフィルタを適用します。

関連する問題