我有两个表:search_criteria和pricing。
表中的列和表中的search_id列都有一个索引。search_criteriapricing_idpricing
但是运行这个嵌套查询不会在search_criteria表上使用索引。
explain
select *
from search_criteria USE INDEX (idx_search_id)
where search_id in
(select search_id
from pricing
where pricing_id = '009330be-d041-444f-a624-ca652f3f61ed');
+----+--------------------+---------------------+------+------------------------------+----------------+---------+-------+----------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+--------------------+---------------------+------+------------------------------+----------------+---------+-------+----------+-------------+
| 1 | PRIMARY | search_criteria | ALL | NULL | NULL | NULL | NULL | 19582252 | Using where |
| 2 …Run Code Online (Sandbox Code Playgroud)