当我分别运行它们时,内部和外部查询都使用索引,但是当我运行整个查询时,外部查询扫描整个表。。。
mysql>解释从SMSDelivery WHERE smsId IN中选择smsId(从SMS WHERE phoneNumber='123456'或从user='5678p'或toUser='5124p'中选择smsId)\G
*************************** 1. row ***************************
id: 1
select_type: PRIMARY
table: SMSDelivery
type: index
possible_keys: NULL
key: FK75C784D70BE5EC9
key_len: 4
ref: NULL
rows: 1337017
Extra: Using where; Using index
*************************** 2. row ***************************
id: 2
select_type: DEPENDENT SUBQUERY
table: SMS
type: unique_subquery
possible_keys: PRIMARY,phoneNumber,fromUser,toUser
key: PRIMARY
key_len: 4
ref: func
rows: 1
Extra: Using where
2 rows in set (0.00 sec)