Kei*_*thS 10 sql t-sql performance
我有一个insert-select语句,只需插入其中两个表中不存在该行的特定标识符的行.以下哪项会更快?
INSERT INTO Table1 (...)
SELECT (...) FROM Table2 t2
WHERE ...
AND NOT EXISTS (SELECT 'Y' from Table3 t3 where t2.SomeFK = t3.RefToSameFK)
AND NOT EXISTS (SELECT 'Y' from Table4 t4 where t2.SomeFK = t4.RefToSameFK AND ...)
Run Code Online (Sandbox Code Playgroud)
... 要么...
INSERT INTO Table1 (...)
SELECT (...) FROM Table2 t2
WHERE ...
AND t2.SomeFK NOT IN (SELECT RefToSameFK from Table3)
AND t2.SomeFK NOT IN (SELECT RefToSameFK from Table4 WHERE ...)
Run Code Online (Sandbox Code Playgroud)
......或者他们的表现差不多?另外,有没有其他方法来构建这个查询更好?我通常不喜欢子查询,因为它们为查询添加了另一个"维度",它通过多项式因子增加运行时间.