在语义相同,有索引的情况下group by和distinct都能使用索引,效率相同。 在语义相同,无索引的情况下:distinct效率高于group by。原因是distinct 和 group by都会进行分组操作,但group by可能会进行排序,触发filesort,导致sql执行效率低下。 基于这个结论,你可能会问 ...
I have a table that links two other tables together. I've defined an index on the first column, and its cardinality ends up being 218 (out of 5000+ rows). If I then ...