MySQL版本:5.5.11
实验1
1、建表:
create table `t_part_test`(
`id` int NOT NULL default 0,
`detail` char(32) NOT NULL default '',
primary key (id)
)default charset=gbk
PARTITION BY HASH(id) PARTITIONS 10;
create table `t_nopart`(
`id` int NOT NULL default 0,
`detail` char(32) NOT NULL default '',
primary key (id)
)default charset=gbk;
CREATE TABLE `t_part_test_range` (
`id` int(11) NOT NULL DEFAULT '0',
`detail` char(32) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=gbk
PARTITION BY RANGE (id)
(PARTITION p01 VALUES LESS THAN (1000000),
PARTITION p02 VALUES LESS THAN (2000000),
PARTITION p03 VALUES LESS THAN (3000000),
PARTITION p04 VALUES LESS THAN (4000000),
PARTITION p05 VALUES LESS THAN (5000000),
PARTITION p06 VALUES LESS THAN (6000000),
PARTITION p07 VALUES LESS THAN (7000000),
PARTITION p08 VALUES LESS THAN (8000000),
PARTITION p09 VALUES LESS THAN (9000000),
PARTITION p10 VALUES LESS THAN MAXVALUE);
注意:5.5默认存储引擎是InnoDB
2、向三张表中分别注入10000000条数据
mysql> select count(*) from t_nopart;
+----------+
| count(*) |
+----------+
| 10000000 |
+----------+
1 row in set (4.68 sec)
mysql> select count(*) from t_part_test;
+----------+
| count(*) |
+----------+
| 10000000 |
+----------+
1 row in set (3.89 sec)
mysql> select count(*) from t_part_test_range;
+----------+
| count(*) |
+----------+
| 10000000 |
+----------+
1 row in set (3.15 sec)
3、进行查询实验
mysql> select count(*) from t_nopart where id>=3000000 and id<=8099900;
+----------+
| count(*) |
+----------+
| 5099901 |
+----------+
1 row in set (3.33 sec)
mysql> select count(*) from t_part_test where id>=3