4 ms·
Ok, I haven't benchmarked this, but shouldn't NOT IN be faster than NOT EXISTS, especially if the fields are indexed. SELECT * FROM content c WHERE c.content_
by jaxn 18y ago
Ok, I haven't benchmarked this, but shouldn't NOT IN be faster than NOT EXISTS, especially if the fields are indexed.
SELECT *
FROM content c
WHERE c.content_id NOT IN (
SELECT c2t.content_id
FROM content_to_tags c2t
)
- pradocchia 18y agoShouldn't make a difference. Check the query plan, though, the semantics appear identical but the execution might be different. Edit: I stand corrected.
- NyxWulf 18y agoIn general not exists is faster than NOT IN because the optimizer will usually eliminate any result set from the sub table. Usually they can handle select *, but I always do select 1 just to make sure. It's been a few years since I tested that on SQL Server, but not exists and exists were substantially faster than in/not in.