Skip to content

Instantly share code, notes, and snippets.

@spetrunia
Created July 26, 2024 08:50
Show Gist options
  • Save spetrunia/eeb2d030224c54602f90e2d6062b4f97 to your computer and use it in GitHub Desktop.
Save spetrunia/eeb2d030224c54602f90e2d6062b4f97 to your computer and use it in GitHub Desktop.
create table t1 (a int primary key, b int, c int, key(b));
insert into t1 select seq, floor(seq/100), seq from seq_1_to_20000;
create table t2 as select * from t1;
explain
delete from t1
where
b <= 42 and a not in (select b from t2);
MariaDB [test]> explain delete from t1 where b <= 5 and a not in (select b from t2);
+------+--------------+-------+-------+---------------+------+---------+------+-------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+--------------+-------+-------+---------------+------+---------+------+-------+-------------+
| 1 | PRIMARY | t1 | range | b | b | 5 | NULL | 599 | Using where |
| 2 | MATERIALIZED | t2 | ALL | NULL | NULL | NULL | NULL | 19742 | |
+------+--------------+-------+-------+---------------+------+---------+------+-------+-------------+
this has outer_lookup_keys=19735, even if we're going to invoke the subquery
only 599 times.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment