Updated on 2024-12-23 GMT+08:00

KEY-HASH

Syntax

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

CREATE TABLE [ schema. ]table_name
 table_definition
   PARTITION BY [LINEAR] KEY(expr) [PARTITIONS num]
   SUBPARTITION BY [LINEAR] HASH(expr) [SUBPARTITIONS sub_num]
   (partition_definition [, partition_definition] ...);

partition_definition is:

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

subpartition_definition is:

SUBPARTITION subpartition_name
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.

partition_name

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

subpartition_name

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

Example

Create a KEY-HASH partitioned table:

CREATE TABLE tbl_key_hash
(
    col1 INT,
    col2 INT,
    col3 varchar(20),
    col4 DATE
)
PARTITION BY KEY(col1) PARTITIONS 3
   SUBPARTITION BY HASH(col2) SUBPARTITIONS 2;