MySQL中distinct和group by性能比较
2018-02-05 16:30
447 查看
一、不加索引
select distinct num from test_test;时间: 0.078ms
select num from test_test group by num; 时间: 0.031ms
二、加上索引
1 ALTER TABLE `test_test` ADD INDEX `num_index` (`num`) ;
再次查询
select distinct num from test_test;
时间: 0.000ms select num from test_test group by num; 时间: 0.000ms
三、结论
不管是加不加索引 group by 都比 distinct 快。因此使用的时候建议选 group by加了索引之后 distinct 比没加索引的 distinct 快了 107倍。
加了索引之后 group by 比没加索引的 group by 快了 43倍。
相关文章推荐
- MySQL中distinct和group by性能比较[转]
- MySQL中distinct与group by之间的性能进行比较
- MySQL中distinct和group by性能比较[转]
- MySQL中distinct和group by性能比较
- MySQL中distinct和group by性能比较[转]
- MySQL中distinct和group by性能比较[转]
- MySQL中distinct与group by之间的性能进行比较
- MySQL中distinct和group by性能比较
- MySQL中distinct与group by之间的性能进行比较
- mysql 去重方法distinct 与 group by 性能比较
- mysql distinct跟group by性能
- MySQL中distinct语句的基本原理及其与group by的比较
- mysql中distinct和group by比较
- MySQL中distinct与group by语句的一些比较及用法讲解
- MySQL中distinct与group by语句的一些比较及用法讲解
- MySQL中distinct语句的基本原理及其与group by的比较
- distinct和group by的性能比较
- mysql联合查询是用DISTINCT和GROUP BY之间的性能区别
- mysql中distinct和group by比较
- MySQL联合索引性能比较