mysql distinct跟group by性能

mysql distinct和group by性能

mysql distinct和group by性能

?

1,测试前的准备

查看
复制
打印
?

  1. //准备一张测试表 ??
  2. mysql>?CREATE?TABLE?`test_test`?( ??
  3. ?->???`id`?int(11)?NOT?NULL?auto_increment, ??
  4. ?->???`num`?int(11)?NOT?NULL?default?‘0’, ??
  5. ?->???PRIMARY?KEY??(`id`) ??
  6. ?->?)?ENGINE=MyISAM??DEFAULT?CHARSET=utf8?AUTO_INCREMENT=1?; ??
  7. Query?OK,?0?rows?affected?(0.05?sec) ??
  8. ??
  9. mysql>?delimiter?||??//改变mysql命令结束符为|| ??
  10. ??
  11. //建个储存过程向表中插入10W条数据 ??
  12. mysql>?create?procedure?p_test(pa?int(11)) ??
  13. ?->?begin ??
  14. ?-> ??
  15. ?->??declare?max_num?int(11)?default?100000; ??
  16. ?->??declare?i?int?default?0; ??
  17. ?->??declare?rand_num?int; ??
  18. ?-> ??
  19. ?->??select?count(id)?into?max_num?from?test_test; ??
  20. ?-> ??
  21. ?->??while?i?<?pa?do??
  22. ?->??????????if?max_num?<?100000?then ??
  23. ?->??????????????????select?cast(rand()*100?as?unsigned)?into?rand_num; ??
  24. ?->??????????????????insert?into?test_test(num)values(rand_num); ??
  25. ?->??????????end?if; ??
  26. ?->??????????set?i?=?i?+1; ??
  27. ?->??end?while; ??
  28. ?->?end|| ??
  29. Query?OK,?0?rows?affected?(0
mysql distinct跟group by性能

相关文章:

你感兴趣的文章:

标签云: