mysql的distinct和groupby对比

mysql的distinct和groupby对比

ID:34724660

大小:180.68 KB

页数:3页

时间:2019-03-10

mysql的distinct和groupby对比_第1页
mysql的distinct和groupby对比_第2页
mysql的distinct和groupby对比_第3页
资源描述:

《mysql的distinct和groupby对比》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库

1、MySQL中distinct和groupby比较之前看了网上的一些测试,感觉不是很准确,今天亲自测试了一番。得出了结论(仅在个人计算机上测试,可能不全面,仅供参考)测试过程:准备一张测试表 1CREATETABLE`test_test`(2`id`int(11)NOTNULLauto_increment, 3`num`int(11)NOTNULLdefault'0', 4PRIMARYKEY(`id`)5)ENGINE=MyISAMDEFAULTCHARSET=utf8AUTO_INCREMENT=1;建个储存过程向表中插入10W条数据 01create

2、procedurep_test(paint(11))02begin03 04declaremax_numint(11)default100000;05declareiintdefault0;06declarerand_numint;07 08selectcount(id)intomax_numfromtest_test;09 10whilei

3、rand_num);14endif;15seti=i+1;16endwhile;17end调用存储过程插入数据1callp_test(100000);开始测试:(不加索引)01selectdistinctnumfromtest_test;02selectnumfromtest_testgroupbynum;03 04[SQL]selectdistinctnumfromtest_test;05受影响的行:0 06时间:0.078ms07 08[SQL]09selectnumfromtest_testgroupbynum;10受影响的行:0 11时间:0.0

4、31ms二、num字段上创建索引 1ALTERTABLE`test_test`ADDINDEX`num_index`(`num`); 再次查询01selectdistinctnumfromtest_test;02selectnumfromtest_testgroupbynum;03[SQL]selectdistinctnumfromtest_test;04受影响的行:0 05时间:0.000ms06 07[SQL]08selectnumfromtest_testgroupbynum;09受影响的行:0 10时间:0.000ms这时候我们发现时间太小了0.

5、000秒都无法精确了。 我们转到命令行下测试01mysql>setprofiling=1;02mysql>selectdistinct(num)fromtest_test;03mysql>selectnumfromtest_testgroupbynum;04mysql>showprofiles;05+----------+------------+----------------------------------------+ 06

6、Query_ID

7、Duration

8、Query

9、 07+----------+------------+--------

10、--------------------------------+ 08

11、1

12、0.00072550

13、selectdistinct(num)fromtest_test

14、 09

15、2

16、0.00071650

17、selectnumfromtest_testgroupbynum

18、 10+----------+------------+----------------------------------------+

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。