我目前正在尝试执行的 MySQL 查询在功能上等同于:
SELECT small_table.A, small_table.B, small_table.C, huge_table.X, huge_table.Y
FROM small_table LEFT JOIN huge_table
ON small_table.D = huge_table.Z
WHERE small_table.E = 'blah'
除了查询似乎没有终止(至少不是在合理的时间内),可能是因为第二个表很大(即 7500 行,总大小为 3 MB)。我可以在合理的时间内执行功能等效的连接,还是需要通过将大表中的列添加到小表中来引入冗余。(我是 SQL 的初学者。)
该子句WHERE small_table.E = 'blah'
是静态的,'blah'
永远不会改变。
这是请求的 EXPLAIN 输出:
Array ( [0] => Array ( [0] => 1 [id] => 1 [1] => SIMPLE [select_type] => SIMPLE [2] => small_table [table] => small_table [3] => ref [type] => ref [4] => E [possible_keys] => E [5] => E [key] => E [6] => 1 [key_len] => 1 [7] => const [ref] => const [8] => 1064 [rows] => 1064 [9] => Using where [Extra] => Using where ) [1] => Array ( [0] => 1 [id] => 1 [1] => SIMPLE [select_type] => SIMPLE [2] => huge_table [table] => huge_table [3] => eq_ref [type] => eq_ref [4] => PRIMARY [possible_keys] => PRIMARY [5] => PRIMARY [key] => PRIMARY [6] => 4 [key_len] => 4 [7] => my_database.small_table.D [ref] => my_database.small_table.D [8] => 1 [rows] => 1 [9] => [Extra] => ) )