Answer the question
In order to leave comments, you need to log in
How expensive is the NOT IN/NOT EXISTS SQL operation?
I'm wondering how expensive SQL queries with NOT IN or NOT EXISTS will be?
Let's say there are 2 tables
items and using_items
In the items table there are 12 million records, in using_items 11 million. Of course, the number is hypothetical and unlikely.
SELECT t.id, t.name
FROM items t
WHERE (t.type = 'some_item_type') AND t.id
NOT IN (
SELECT w.id_item
FROM using_items w
)
ORDER BY t.name ASC;
SELECT t.id, t.name
FROM items t
WHERE (t.type = 'some_item_type') AND
NOT EXISTS (
SELECT w.id_item
FROM using_items w
WHERE t.id = w.id_item
)
ORDER BY t.name ASC;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question