我有一个插入选择语句,它只需要插入行的特定标识符在其他两个表中的任何一个中都不存在的行。以下哪个会更快?
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 ...)
... 或者...
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 ...)
...或者他们的表现大致相同?此外,还有其他更好的方法来构造这个查询吗?我通常不喜欢子查询,因为它们为查询添加了另一个“维度”,通过多项式因子增加了运行时间。