如何让 MySQL 先运行子查询并且只运行一次?现在 MySQL 对表 t1 中的每一行运行内部查询,这是一个性能灾难。
explain select * from t1 where uid in (select id from t0);
+----+--------------------+-------+------+---------------+------+---------+------+----------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+--------------------+-------+------+---------------+------+---------+------+----------+-------------+
| 1 | PRIMARY | t1 | ALL | NULL | NULL | NULL | NULL | 18954249 | Using where |
| 2 | DEPENDENT SUBQUERY | t0 | ALL | NULL | NULL | NULL | NULL | 12749 | Using where |
+----+--------------------+-------+------+---------------+------+---------+------+----------+-------------+