免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2182 | 回复: 4
打印 上一主题 下一主题

MySQL分区测试中遇到的不解现象(很奇怪) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-01-07 18:33 |只看该作者 |倒序浏览
我的测试是按照这篇文章进行的 http://dev.mysql.com/tech-resour ... e-partitioning.html

但是,我最后看到的explain显示的结果和人家的不同,part_tab 和 no_part_tab 在执行select语句以后的explain分析结果竟然一样,都是扫描了8百万行记录,但是执行的速度完全天上地下,大家帮忙给瞅一眼。输出如下:

mysql> select count(*) from no_part_tab where c3 > date '1995-01-01' and c3 < date '1995-12-31';
+----------+
| count(*) |
+----------+
|   795181 |
+----------+
1 row in set (6.49 sec)

mysql> select count(*) from part_tab where c3 > date '1995-01-01' and c3 < date '1995-12-31';
+----------+
| count(*) |
+----------+
|   795181 |
+----------+
1 row in set (0.71 sec)

mysql> explain select count(*) from no_part_tab where c3 > date '1995-01-01' and c3 < date '1995-12-31';
+----+-------------+-------------+------+---------------+------+---------+------+---------+-------------+
| id | select_type | table       | type | possible_keys | key  | key_len | ref  | rows    | Extra       |
+----+-------------+-------------+------+---------------+------+---------+------+---------+-------------+
|  1 | SIMPLE      | no_part_tab | ALL  | NULL          | NULL | NULL    | NULL | 8000000 | Using where |
+----+-------------+-------------+------+---------------+------+---------+------+---------+-------------+
1 row in set (0.00 sec)

mysql> explain select count(*) from part_tab where c3 > date '1995-01-01' and c3 < date '1995-12-31';
+----+-------------+----------+------+---------------+------+---------+------+---------+-------------+
| id | select_type | table    | type | possible_keys | key  | key_len | ref  | rows    | Extra       |
+----+-------------+----------+------+---------------+------+---------+------+---------+-------------+
|  1 | SIMPLE      | part_tab | ALL  | NULL          | NULL | NULL    | NULL | 8000000 | Using where |
+----+-------------+----------+------+---------------+------+---------+------+---------+-------------+
1 row in set (0.00 sec)


思考中。。。。

论坛徽章:
0
2 [报告]
发表于 2010-01-07 23:40 |只看该作者
表part_tab是按什么键来分区的呢?是不是c3字段
分区表通过pruning来加速的

论坛徽章:
0
3 [报告]
发表于 2010-01-08 00:33 |只看该作者
原帖由 justin033 于 2010-1-7 23:40 发表
表part_tab是按什么键来分区的呢?是不是c3字段
分区表通过pruning来加速的


hi justin033....PARTITION BY RANGE (year(c3)) ,恩,是c3字段。

我希望看到的是两次select 扫描的记录数应该有很明星的差别。

part_tab表一共分有p0-p11,12个分区,其中p0和p11都是空没有记录,其余10分区中,记录数大概在795000-797000上下。

论坛徽章:
0
4 [报告]
发表于 2010-01-08 09:11 |只看该作者
你查询的条件怎么加了date,如:where c3 > date '1995-01-01' and c3 < date '1995-12-31';

看下文档吧http://dev.mysql.com/doc/refman/5.1/en/partitioning-pruning.html        这边有例子的

麻烦贴下
explain partitions select count(*) from no_part_tab where c3 > date '1995-01-01' and c3 < date '1995-12-31';

论坛徽章:
0
5 [报告]
发表于 2010-01-08 11:53 |只看该作者
原帖由 justin033 于 2010-1-8 09:11 发表
你查询的条件怎么加了date,如:where c3 > date '1995-01-01' and c3 < date '1995-12-31';

看下文档吧http://dev.mysql.com/doc/refman/5.1/en/partitioning-pruning.html        这边有例子的

麻烦贴下 ...


HI justin033

mysql> explain partitions select count(*) from part_tab where c3 > date '1995-01-01' and c3 < date '1995-12-31'\G
*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: part_tab
   partitions: p1
         type: ALL
possible_keys: NULL
          key: NULL
      key_len: NULL
          ref: NULL
         rows: 8000000
        Extra: Using where
1 row in set (0.00 sec)

上面的select语句中,比较的时候不加date也可以。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP