
- 本栏最新文章
- PHP实现网页自动更新块 05-08
- PHP开发中文件操作疑难问答 05-08
- 用PHP与XML 联手进行网站编程 04-29
- 将PHP作为Shell脚本语言使用 04-23
- 用 PHPRPC 实现 Ajax 级联下拉菜单 04-23
- PHP安装简明指南 04-22
- 在PHP中利用XML技术构造远程服务(下) 04-14
- 在PHP中利用XML技术构造远程服务(上) 04-14
- PHP动态网页开发中常用的一些函数 04-04
- PHP在大型网站开发中的一些问题 04-04

- 本栏推荐文章
- ASP.NET设计网络硬盘之查看文件夹 04-29
- ASP.NET设计网络硬盘之文件夹实现 04-29
- ASP.NET设计网络硬盘之上传文件 04-29
- 小试ASP.NET 2.0的兼容性 04-29
- ASP 系列函数大全 04-29
- Asp.net Mvc Framework 九 (View与Controlle... 04-04
- 【翻译】动态调用样式表代码 04-04
- Flash AS3.0 实现FLASH的“动态链接库” 03-31
- Flash AS3.0 爽快使用XML 03-31
- MySQL的LIST分区体验与总结 03-27
MySQL的LIST分区体验与总结 (1)
终于有点空闲时间了,测试一下LIST分区,因为LIST在我们的开发中用到。他分区以后再补上。
版本:
Server version: 5.1.23a-maria-alpha-log MySQL Community Server [Maria] (GPL)
一、讲在前面
注意:
1、ALTER TABLE也可以用于对带分区的表进行重新分区,所以不能在建表之后再用ALTER TABLE语法。
2、如果你表中有KEY。用来分区的字段必须是KEY的一部份。
3、现在的分区属于水平分区。(垂直分区我们可以自己模拟,这个以后再写)
mysql> use t_girl
Database changed
先建立一个普通表
mysql> create table category( cid int unsigned not null auto_increment primary key, cname varchar(64) not null, parent_id int not null);
Query OK, 0 rows affected (0.00 sec)
mysql> create table parent(parent_id int not null auto_increment primary key,pname varchar(64) not null);
Query OK, 0 rows affected (0.00 sec)
分区表
mysql> create table category_part( cid int unsigned not null auto_increment,cname varchar(64) not null,parent_id int not null,primary key (cid,parent_id))
partition by list(parent_id)(
partition p1 values in (1,2,3,6,9),
partition p2 values in (4,5,10,22,23),
partition p3 values in (7,8,11,12,13),
partition p4 values in (14,15,16,17,20),
partition p5 values in (18,19,21,24,25)
);
Query OK, 0 rows affected (0.01 sec)
插入数据部分省略。。。
建立索引。
mysql> create index f_parent_id on category(parent_id);
Query OK, 2048000 rows affected (17.61 sec)
Records: 2048000 Duplicates: 0 Warnings: 0
mysql> show index from category;
+----------+------------+-------------+--------------+-------------+-----------+---------| Table | Non_unique | Key_name | Seq_in_index | Column_name |
Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+----------+------------+-------------+--------------+-------------+-----------+---------| category | 0 | PRIMARY | 1 | cid | A | 2048000 | NULL | NULL |
| BTREE | |
| category | 1 | f_parent_id | 1 | parent_id | A | 25 |
NULL | NULL | | BTREE | |
+----------+------------+-------------+--------------+-------------+-----------+---------2 rows in set (0.00 sec)
mysql> create index f_parent_id on category_part(parent_id);
Query OK, 2048000 rows affected (18.57 sec)
Records: 2048000 Duplicates: 0 Warnings: 0
mysql> show index from category_part;
+---------------+------------+-------------+--------------+-------------+-----------+----| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality |
Sub_part | Packed | Null | Index_type | Comment |
+---------------+------------+-------------+--------------+-------------+-----------+----| category_part | 0 | PRIMARY | 1 | cid | A | 2048000 | NULL | NULL |
| BTREE | |
| category_part | 0 | PRIMARY | 2 | parent_id | A | 2048000 | NULL | NULL |
| BTREE | |
| category_part | 1 | f_parent_id | 1 | parent_id | A | 318 | NULL | NULL
| | BTREE | |
+---------------+------------+-------------+--------------+-------------+-----------+----3 rows in set (0.01 sec)
mysql> select count(*) from category; +----------+ | count(*) | +----------+ | 2048000 | +----------+ 1 row in set (0.00 sec)
mysql> select count(*) from category_part; +----------+ | count(*) | +----------+
| 2048000 | +----------+ 1 row in set (0.00 sec)
mysql> select count(*) from parent; +----------+ | count(*) | +----------+ | 25 |
+----------+ 1 row in set (0.00 sec)
[next]
二、具体测试
1、我们来看一下查询性能比较:
1)、单表查询
mysql> select count(*) from category where parent_id in (22,20);
+----------+
| count(*) |
+----------+
| 17002 |
+----------+
1 row in set (0.03 sec)
mysql> select count(*) from category_part where parent_id in (22,20);
+----------+
| count(*) |
+----------+
| 17002 |
+----------+
1 row in set (0.02 sec)
分区表普通的做了索引的速度上快了一点,不过差别不是很大。
mysql> explain select count(*) from category where parent_id in (22,20);
+----+-------------+----------+-------+---------------+-------------+---------+------+-------
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+----------+-------+---------------+------------+-----------------| 1 | SIMPLE
- 创意互动WEB设计艺术网 版权所有
创意互动工作小组 邮箱:creativegroup@yeah.net QQ:275579661 381419374 4564917 电话:0739-6322775 - Since 2008.01.01 湘ICP备07501727号 衷心感谢Phpcms.cn和Discuz!提供程序技术




