mysql distinct和group by性能
mysql distinct和group by性能
- ??
- 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>?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