admin 管理员组文章数量: 1086019
I have the following two queries. The first runs in less than 1 second. The latter query takes minutes to run. All of the columns being joined are indexed. Both queries are doing the same thing, the second just combines the two not exists
from the first into a single not exists
.
Is the second written in a way which is known to perform worse than two not exists
?
Executes in less than 1 second:
select *
from
A
join B on B.AId = A.Id
where
not exists (select * from C where C.ObjectId = A.Id)
and not exists (select * from C where C.ObjectId = B.Id)
Runs for minutes:
select *
from
A
join B on B.AId = A.Id
where
not exists (select * from C where C.ObjectId = A.Id or C.ObjectId = B.Id)
本文标签: sqlOR is slower than two NOT EXISTSStack Overflow
版权声明:本文标题:sql - OR is slower than two NOT EXISTS? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744076064a2529371.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论