0

無期限に実行される単純な SQL クエリ (以下を参照) があります (完了を待つことができませんでした)。

if exists(
    select 1 
    from [files].[Contacts_Migration_Template] c 
    where not exists(select 1 
                     from [files].[Additional_Contact_Migration_Template] 
                     where contact = c.[migration id])
) print 'warning message'

ただし、サブクエリ (if exists( subquery ) print 'warning message') 自体はすぐに実行されます (以下のスクリーンショットを参照)。

「フル」クエリ ここに画像の説明を入力

サブクエリ ここに画像の説明を入力

両方のクエリに対して生成された推定実行プラン (以下を参照) は、サブクエリが「フル」クエリよりもクエリ コストが高くなければならないことを示しています。無限に長く実行されています...

ここに画像の説明を入力

どうしたの?


元のクエリ

ここに画像の説明を入力

4

2 に答える 2

0

一時テーブルを使用して実行シーケンスを中断しました。それは役に立ちました。

select 1 [x] into #tmp_87624435
from [files].[Contacts_Migration_Template] c
where not exists( select 1
    from [files].[Additional_Contact_Migration_Template]
    where contact = c.[migration id]);
if exists(select 1 from #tmp_87624435) throw 51000, 'warning', 1;

しかし、これでもこのような単純な問題にはやり過ぎだと思います:)

于 2013-05-09T08:58:54.770 に答える