当我向查询添加“distinct”时,查询时间从 0.015 增加到 6 秒以上。
我想加入几个表,这些表通过外键链接并从中获得一个不同的列:
select distinct table3.idtable3 from
table1
join table2 on table1.idtable1 = table2.fkey
join table3 on table2.idtable2 = table3.fkey
where table1.idtable1 = 1
Run Code Online (Sandbox Code Playgroud)
独特的查询需要 6 秒,这在我看来是可以改进的。
选择:
持续时间:0.015s / fetch:5.532s(5.760.434 行)
解释:
id, select_type, table, partitions, type, possible_keys, key, key_len, ref, rows, filtered, Extra
1 SIMPLE table1 index asd asd 137 10 10.00 Using where; Using index
1 SIMPLE table2 ALL idtable2 200 25.00 Using where; Using join buffer (Block Nested Loop)
1 SIMPLE table3 ref …Run Code Online (Sandbox Code Playgroud)