I would suggest you read the following blog post, which goes into great detail on this question:
Which method is best to select values present in one table but missing
in another one?
And after a thorough analysis, arrives at the following conclusion:
However, these three methods [NOT IN
, NOT EXISTS
, LEFT JOIN
]
generate three different plans which are executed by three different
pieces of code. The code that executes EXISTS
predicate is about 30%
less efficient than those that execute index_subquery
and LEFT JOIN
optimized to use Not exists
method.
That’s why the best way to search for missing values in MySQL is using a LEFT JOIN
/ IS NULL
or NOT IN
rather than NOT
EXISTS
.
If the performance you're seeing with NOT IN
is not satisfactory, you won't improve this performance by switching to a LEFT JOIN
/ IS NULL
or NOT EXISTS
, and instead you'll need to take a different route to optimizing this query, such as adding indexes.