当我使用explain
运行以下查询时:
explain
SELECT `leads`.*
FROM `leads`
INNER JOIN `people` ON `people`.`id` = `leads`.`person_id`
WHERE `people`.`email` = 'email@test.co.za'
我明白了:
+----+-------------+--------+-------+-------------------------------+-----------------------+---------+-------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+--------+-------+-------------------------------+-----------------------+---------+-------+------+-------------+
| 1 | SIMPLE | people | const | PRIMARY,index_people_on_email | index_people_on_email | 768 | const | 1 | Using index |
| 1 | SIMPLE | leads | ref | fk_person_lead | fk_person_lead | 5 | const | 2 | NULL |
+----+-------------+--------+-------+-------------------------------+-----------------------+---------+-------+------+-------------+
我理解使用index_people_on_email
,因为搜索是在电子邮件上,并且电子邮件上有索引。人员表中也没有引用其他列。
我猜测索引未被用于潜在客户的原因是因为我从引导表leads.*
中提取的数据多于fk_person_lead
上的数据。
让我感到困惑的是,我认为查询仍会使用外键引用来过滤引线,然后进行查找以获取其余信息。
我在这里误解了什么?