创建HASH-HASH二级分区
模板化用法
CREATE TABLE tb_h_h_tp(
id bigint not null auto_increment,
bid int,
name varchar(30),
birthday datetime not null,
primary key(id)
)
PARTITION BY HASH(bid)
PARTITIONS 2
SUBPARTITION BY HASH(id)
SUBPARTITIONS 4
非模板化用法
CREATE TABLE tb_h_h_ntp(
id bigint not null auto_increment,
bid int,
name varchar(30),
birthday datetime not null,
primary key(id)
)
PARTITION BY HASH(bid)
PARTITIONS 2
SUBPARTITION BY HASH(id)
(
PARTITION p1 SUBPARTITIONS 2,
PARTITION p2 SUBPARTITIONS 4
)
创建HASH-KEY二级分区
模板化用法
CREATE TABLE tb_h_k_tp(
id bigint not null auto_increment,
bid int,
name varchar(30),
birthday datetime not null,
primary key(id)
)
PARTITION BY HASH(bid)
PARTITIONS 4
SUBPARTITION BY KEY(id)
SUBPARTITIONS 2
非模板化用法
CREATE TABLE tb_h_k_ntp(
id bigint not null auto_increment,
bid int,
name varchar(30),
birthday datetime not null,
primary key(id)
)
PARTITION BY HASH(bid)
PARTITIONS 2
SUBPARTITION BY KEY(id)
(
PARTITION p1 SUBPARTITIONS 2,
PARTITION p2 SUBPARTITIONS 4
)
创建HASH-RANGE二级分区
模板化用法
CREATE TABLE tb_h_r_tp(
id bigint not null auto_increment,
bid int,
name varchar(30),
birthday datetime not null,
primary key(id)
)
PARTITION BY HASH(bid)
PARTITIONS 2
SUBPARTITION BY RANGE(id) (
SUBPARTITION sp1 VALUES LESS THAN(1000),
SUBPARTITION sp2 VALUES LESS THAN(MAXVALUE)
)
非模板化用法
CREATE TABLE tb_h_r_ntp(
id bigint not null auto_increment,
bid int,
name varchar(30),
birthday datetime not null,
primary key(id)
)
PARTITION BY HASH(bid)
PARTITIONS 2
SUBPARTITION BY RANGE(id)
(
PARTITION p1 (
SUBPARTITION sp1 VALUES LESS THAN(1000),
SUBPARTITION sp2 VALUES LESS THAN(MAXVALUE)
),
PARTITION p2 (
SUBPARTITION sp3 VALUES LESS THAN(1000),
SUBPARTITION sp4 VALUES LESS THAN(2000),
SUBPARTITION sp5 VALUES LESS THAN(MAXVALUE)
)
)
创建HASH-RANGE COLUMNS二级分区
模板化用法
CREATE TABLE tb_h_rc_tp(
id bigint not null auto_increment,
bid int,
name varchar(30),
birthday datetime not null,
primary key(id)
)
PARTITION BY HASH(bid)
PARTITIONS 2
SUBPARTITION BY RANGE COLUMNS(name,id) (
SUBPARTITION sp1 VALUES LESS THAN('Jack',1000),
SUBPARTITION sp2 VALUES LESS THAN(MAXVALUE,MAXVALUE)
)
非模板化用法
CREATE TABLE tb_h_rc_ntp(
id bigint not null auto_increment,
bid int,
name varchar(30),
birthday datetime not null,
primary key(id)
)
PARTITION BY HASH(bid)
PARTITIONS 2
SUBPARTITION BY RANGE COLUMNS(name,id)
(
PARTITION p1 (
SUBPARTITION sp1 VALUES LESS THAN('Jack',1000),
SUBPARTITION sp2 VALUES LESS THAN(MAXVALUE,MAXVALUE)
),
PARTITION p2 (
SUBPARTITION sp3 VALUES LESS THAN('Bob',1000),
SUBPARTITION sp4 VALUES LESS THAN('Tom',2000),
SUBPARTITION sp5 VALUES LESS THAN(MAXVALUE,MAXVALUE)
)
)
创建HASH-LIST二级分区
模板化用法
CREATE TABLE tb_h_l_tp(
id bigint not null auto_increment,
bid int,
name varchar(30),
birthday datetime not null,
primary key(id)
)
PARTITION BY HASH(bid)
PARTITIONS 2
SUBPARTITION BY LIST (name) (
SUBPARTITION sp1 VALUES IN ('Jack','Bob'),
SUBPARTITION sp2 VALUES IN (DEFAULT)
)
非模板化用法
CREATE TABLE tb_h_l_ntp(
id bigint not null auto_increment,
bid int,
name varchar(30),
birthday datetime not null,
primary key(id)
)
PARTITION BY HASH(bid)
PARTITIONS 2
SUBPARTITION BY LIST (name)
(
PARTITION p1 (
SUBPARTITION sp1 VALUES IN ('Jack','Bob'),
SUBPARTITION sp2 VALUES IN (DEFAULT)
),
PARTITION p2 (
SUBPARTITION sp3 VALUES IN ('Jack','Bob'),
SUBPARTITION sp4 VALUES IN ('Tom','Lily'),
SUBPARTITION sp5 VALUES IN (DEFAULT)
)
)
创建HASH-LIST COLUMNS二级分区
模板化用法
CREATE TABLE tb_h_lc_tp(
id bigint not null auto_increment,
bid int,
name varchar(30),
birthday datetime not null,
primary key(id)
)
PARTITION BY HASH(bid)
PARTITIONS 2
SUBPARTITION BY LIST COLUMNS (name,id) (
SUBPARTITION sp1 VALUES IN (('Jack',1000),('Bob',2000)),
SUBPARTITION sp2 VALUES IN (DEFAULT)
)
非模板化用法
CREATE TABLE tb_h_lc_ntp(
id bigint not null auto_increment,
bid int,
name varchar(30),
birthday datetime not null,
primary key(id)
)
PARTITION BY HASH(bid)
PARTITIONS 2
SUBPARTITION BY LIST COLUMNS(name,id)
(
PARTITION p1 (
SUBPARTITION sp1 VALUES IN (('Jack',1000),('Bob', 2000)),
SUBPARTITION sp2 VALUES IN (DEFAULT)
),
PARTITION p2 (
SUBPARTITION sp3 VALUES IN (('Bob',1000), ('Tom',2000)),
SUBPARTITION sp4 VALUES IN (('Lily',3000)),
SUBPARTITION sp5 VALUES IN (DEFAULT)
)
)
创建HASH-CO_HASH二级分区
模板化用法
CREATE TABLE tb_h_ch_tp(
id bigint not null auto_increment,
bid int,
uid int,
name varchar(30),
nick varchar(30),
birthday datetime not null,
primary key(id)
)
PARTITION BY HASH(bid)
PARTITIONS 2
SUBPARTITION BY CO_HASH(RIGHT(name, 6),RIGHT(nick, 6))
SUBPARTITIONS 4
非模板化用法
CREATE TABLE tb_h_ch_ntp(
id bigint not null auto_increment,
bid int,
uid int,
name varchar(30),
nick varchar(30),
birthday datetime not null,
primary key(id)
)
PARTITION BY HASH(bid)
PARTITIONS 2
SUBPARTITION BY CO_HASH(RIGHT(name, 6),RIGHT(nick, 6))
(
PARTITION p1 SUBPARTITIONS 2,
PARTITION p2 SUBPARTITIONS 4
)
文档内容是否对您有帮助?