とりわけ、別のテーブルからテーブルを更新する SQL Server 2008 R2 プロジェクトを継承しました。
Table1(約 150,000 行) には 3 つの電話番号フィールド (Tel1、Tel2、Tel3)があります。Table2(約 20,000 行) には 3 つの電話番号フィールド (Phone1、Phone2、Phone3)があります。
.. これらの数値のいずれかが一致した場合Table1は、更新する必要があります。
現在のコードは次のようになります。
UPDATE t1
SET surname = t2.surname, Address1=t2.Address1, DOB=t2.DOB, Tel1=t2.Phone1, Tel2=t2.Phone2, Tel3=t2.Phone3,
FROM Table1 t1
inner join Table2 t2
on
(t1.Tel1 = t2.Phone1 and t1.Tel1 is not null) or
(t1.Tel1 = t2.Phone2 and t1.Tel1 is not null) or
(t1.Tel1 = t2.Phone3 and t1.Tel1 is not null) or
(t1.Tel2 = t2.Phone1 and t1.Tel2 is not null) or
(t1.Tel2 = t2.Phone2 and t1.Tel2 is not null) or
(t1.Tel2 = t2.Phone3 and t1.Tel2 is not null) or
(t1.Tel3 = t2.Phone1 and t1.Tel3 is not null) or
(t1.Tel3 = t2.Phone2 and t1.Tel3 is not null) or
(t1.Tel3 = t2.Phone3 and t1.Tel3 is not null);
ただし、このクエリの実行には 30 分以上かかります。
Nested Loop実行計画は、主なボトルネックがのクラスター化インデックス スキャン周辺にあることを示唆していTable1ます。両方のテーブルのID列にクラスター化インデックスがあります。
私の DBA スキルは非常に限られているため、このクエリのパフォーマンスを向上させる最善の方法を提案できる人はいますか? とのインデックスを各列に追加するのが最善でしょうかTel1、それともクエリを変更してパフォーマンスを向上させることはできますか?Tel2Tel3