There are DDL statements:
CREATE TABLE t1(
c1 INT NOT NULL
);
CREATE TABLE t2(
c2 INT NOT NULL
);
My query:
SELECT c1 FROM t1 WHERE c1 NOT IN (SELECT c2 from t2)
EXPLAIN output:
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 3 Using where
Subquery doesn’t correlate with outer query. Why it’s type is DEPENDENT SUBQUERY?
UPD: query is SELECT c1 FROM t1 WHERE c1 NOT IN (SELECT c2 from t2)
The execution planner / optimizer of the MySQL version you are using, rewrites the query internally as a correlated subquery (or to be more accurate, both these are transformed into the same execution plan):
This type of query is called antijoin (or anti-semijoin) and can also be written in another way, with a
LEFT JOIN / WHERE IS NULL, which produces in MySQL (5.1 and 5.5 versions) a slightly different Explain plan:Notice that in other versions, like the 5.6 (which is still in development), or in MariaDB (that has some optimizer improvements in the recent versions), the queries may be rewritten differently.
Even in the same version, the final execution plan for the same query (and especially for more complex ones) may vary from execution to execution, depending on the indexes available, the sizes of the tables and several other factors.