mysql distinct和group by性能
mysql distinct和group by性能
?
1,测试前的准备
查看
复制
打印
?
- //准备一张测试表 ??
- mysql>?CREATE?TABLE?`test_test`?( ??
- ?->???`id`?int(11)?NOT?NULL?auto_increment, ??
- ?->???`num`?int(11)?NOT?NULL?default?‘0’, ??
- ?->???PRIMARY?KEY??(`id`) ??
- ?->?)?ENGINE=MyISAM??DEFAULT?CHARSET=utf8?AUTO_INCREMENT=1?; ??
- Query?OK,?0?rows?affected?(0.05?sec) ??
- ??
- mysql>?delimiter?||??//改变mysql命令结束符为|| ??
- ??
- //建个储存过程向表中插入10W条数据 ??
- mysql>?create?procedure?p_test(pa?int(11)) ??
- ?->?begin ??
- ?-> ??
- ?->??declare?max_num?int(11)?default?100000; ??
- ?->??declare?i?int?default?0; ??
- ?->??declare?rand_num?int; ??
- ?-> ??
- ?->??select?count(id)?into?max_num?from?test_test; ??
- ?-> ??
- ?->??while?i?<?pa?do??
- ?->??????????if?max_num?<?100000?then ??
- ?->??????????????????select?cast(rand()*100?as?unsigned)?into?rand_num; ??
- ?->??????????????????insert?into?test_test(num)values(rand_num); ??
- ?->??????????end?if; ??
- ?->??????????set?i?=?i?+1; ??
- ?->??end?while; ??
- ?->?end|| ??
- Query?OK,?0?rows?affected?(0