我有这个简单的 JOIN:
SELECT my_table1.*,
TIME_FORMAT(time1, '%H:%i') AS time1,
TIME_FORMAT(time2, '%H:%i') AS time2,
TIME_FORMAT(time3, '%H:%i') AS time3,
my_table2.*,
TIME_FORMAT(time2_saved, '%H:%i') AS time2_saved,
TIME_FORMAT(time3_saved, '%H:%i') AS time3_saved,
my_table3.device_id, my_table3.device_token,
my_table3.device_language, my_table3.app_edition
FROM my_table1, my_table2, my_table3
WHERE my_table1.flight_id = mytable_2.flight_id
AND my_table2.device_id = my_table3.device_id AND my_table3.app_edition = '1'
正如 MySQL 报告的那样,这似乎效率低下。索引显然不是此查询的最佳选择。但是,所有表都有索引,但我缺少一些东西。
如果我在查询之前运行 EXPLAIN,MySQL 将返回以下内容:
1
SIMPLE
my_table2
ALL
flight_id,device_id
NULL
NULL
NULL
356
1
SIMPLE
my_table3
eq_ref
device_id
device_id
128
my_databasename.my_table2.device_id
1
Using where
1
SIMPLE
my_table1
ref
flight_id
flight_id
99
my_databasename.my_table2.flight_id
1
Using where
(如果您更喜欢看到干净的桌子,请在此处查看实际屏幕截图:http: //oi48.tinypic.com/20kov3d.jpg)
如您所见,第一行显示“ALL”类型,这意味着它使用全表扫描。我在这里失踪了吗?