首页 > 编程笔记 > MySQL笔记 阅读:4

MySQL中的复合分区(附带实例)

复合分区是分区表中每个分区的再次分割,子分区既可以使用 HASH 分区,也可以使用 KEY 分区。

复合分区需要注意以下问题:
下面通过案例讲述不同的复合分区的创建方法。
1) 创建 RANGE - HASH 复合分区的命令如下:
mysql> create table rhtable(
  no varchar(20) not null,
      name varchar(20),
      deptno int,
      birthdate date not null,
      salary int
      )
      partition by range(salary)
      subpartition by hash(year(birthdate))
      subpartitions 3
      (
        partition p1 values less than (2000),
        partition p2 values less than maxvalue
      );
Query OK, 0 rows affected (0.23 sec)

2) 创建 RANGE - KEY 复合分区的命令如下:
mysql> create table rktable(
      no varchar(20) not null,
      name varchar(20),
      deptno int,
      birth date not null,
      salary int
      )
      partition by range(salary)
      subpartition by key(birth)
      subpartitions 3
      (
        partition p1 values less than (2000),
        partition p2 values less than maxvalue
      );
Query OK, 0 rows affected (0.07 sec)

3) 创建 LIST - HASH 复合分区的命令如下:
mysql> create table lhtable(
        no varchar(20) not null,
        name varchar(20),
        deptno int,
        birth date not null,
        salary int
       )
       partition by list(deptno)
       subpartition by hash( year(birth) )
       subpartitions 3
       (
         partition p1 values in (10),
         partition p2 values in (20)
       );
Query OK, 0 rows affected (0.08 sec)

4) 创建 LIST - KEY 复合分区的命令如下:
mysql> create table lktable(
       no varchar(20) not null,
       name varchar(20),
       deptno int,
       birthdate date not null,
       salary int
      )
      partition by list(deptno)
      subpartition by key(birthdate)
      subpartitions 3
      (
       partition p1 values in (10),
       partition p2 values in (20)
      );
Query OK, 0 rows affected (0.09 sec)

相关文章