Updated on 2024-09-06 GMT+08:00

HASH-RANGE

Syntax

The following statement is used to create one or more HASH-RANGE partitioned tables where each partition may contain one or more subpartitions:

CREATE TABLE [ schema. ]table_name
 table_definition
   PARTITION BY [LINEAR] HASH(expr)
   SUBPARTITION BY RANGE {(expr) | COLUMNS(column_list)} 
   (partition_definition [, partition_definition] ...);

partition_definition is:

PARTITION partition_name
    (subpartition_definition [, subpartition_definition] ...)

subpartition_definition is:

SUBPARTITION subpartition_name VALUES LESS THAN {value | valuse_list | MAXVALUE}
Table 1 Parameters

Parameter

Description

table_name

The name of the table to be created.

expr

The expression of the partition. Currently, only the INT type is supported.

column_list

The list of partition key columns. It is used in LIST COLUMNS(). Expressions are not supported.

value

The boundary value of the partition.

value_list

The list of the values of the partition key columns. It is used in LIST COLUMNS().

MAXVALUE

The maximum value of the partition.

partition_name

subpartition_name

The name of the partition. The name must be unique within the table.

The name of the subpartition. The name must be unique within the table.

Example

Create a HASH-RANGE partitioned table:

CREATE TABLE tbl_hash_range
(
    col1 INT,
    col2 INT,
    col3 varchar(20),
    col4 DATE
)
PARTITION BY HASH(col1)
SUBPARTITION BY RANGE(col2)
(
  PARTITION p0 (
    SUBPARTITION s0 VALUES LESS THAN(4),
    SUBPARTITION s1 VALUES LESS THAN(7),
    SUBPARTITION s2 VALUES LESS THAN(10),
    SUBPARTITION s3 VALUES LESS THAN(13)
  ),
  PARTITION p1
  (
    SUBPARTITION s4 VALUES LESS THAN(4),
    SUBPARTITION s5 VALUES LESS THAN(7),
    SUBPARTITION s6 VALUES LESS THAN(10),
    SUBPARTITION s7 VALUES LESS THAN(13)
  ),
  PARTITION p2
  (
    SUBPARTITION s8 VALUES LESS THAN(4),
    SUBPARTITION s9 VALUES LESS THAN(7),
    SUBPARTITION s10 VALUES LESS THAN(10),
    SUBPARTITION s11 VALUES LESS THAN(13)
  )
);