select count(*) from v1 where id not in (select id from t1); #correct
|
count(*)
|
0
|
|
select * from v1 where id not in (select id from t1); #wrong
|
id
|
1
|
2
|
3
|
|
MariaDB [test]> explain extended select * from v1 where id not in (select id from t1);
|
+------+--------------+-------+------+---------------+------+---------+------+------+----------+-------------------------------------------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
|
+------+--------------+-------+------+---------------+------+---------+------+------+----------+-------------------------------------------------+
|
| 1 | PRIMARY | t2 | ALL | NULL | NULL | NULL | NULL | 1 | 100.00 | Using temporary; Using filesort |
|
| 1 | PRIMARY | t1 | ALL | NULL | NULL | NULL | NULL | 3 | 100.00 | Using where; Using join buffer (flat, BNL join) |
|
| 2 | MATERIALIZED | t1 | ALL | NULL | NULL | NULL | NULL | 3 | 100.00 | |
|
+------+--------------+-------+------+---------------+------+---------+------+------+----------+-------------------------------------------------+
|
3 rows in set, 1 warning (0.00 sec)
|
|
Note (Code 1003): select `test`.`t1`.`id` AS `id` from `test`.`t1` join `test`.`t2` where !<expr_cache><`test`.`t1`.`id`>(<in_optimizer>(`test`.`t1`.`id`,`test`.`t1`.`id` in ( <materialize> (select `test`.`t1`.`id` from `test`.`t1` ), <primary_index_lookup>(`test`.`t1`.`id` in <temporary table> on distinct_key where `test`.`t1`.`id` = `<subquery2>`.`id`)))) order by `test`.`t1`.`id`
|
MariaDB [test]> explain extended select count(*) from v1 where id not in (select id from t1);
|
+------+--------------+-------+------+---------------+------+---------+------+------+----------+-------------------------------------------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
|
+------+--------------+-------+------+---------------+------+---------+------+------+----------+-------------------------------------------------+
|
| 1 | PRIMARY | t2 | ALL | NULL | NULL | NULL | NULL | 1 | 100.00 | |
|
| 1 | PRIMARY | t1 | ALL | NULL | NULL | NULL | NULL | 3 | 100.00 | Using where; Using join buffer (flat, BNL join) |
|
| 2 | MATERIALIZED | t1 | ALL | NULL | NULL | NULL | NULL | 3 | 100.00 | |
|
+------+--------------+-------+------+---------------+------+---------+------+------+----------+-------------------------------------------------+
|
3 rows in set, 1 warning (0.00 sec)
|
|
Note (Code 1003): select count(0) AS `count(*)` from `test`.`t1` join `test`.`t2` where !<expr_cache><`test`.`t1`.`id`>(<in_optimizer>(`test`.`t1`.`id`,`test`.`t1`.`id` in ( <materialize> (select `test`.`t1`.`id` from `test`.`t1` ), <primary_index_lookup>(`test`.`t1`.`id` in <temporary table> on distinct_key where `test`.`t1`.`id` = `<subquery2>`.`id`)))) order by `test`.`t1`.`id`
|