PolarDB-O provides the simple syntax for you to create a hash-partitioned tables for which the number of partitions is specified.

Create hash partitions

Syntax

CREATE TABLE ... PARTITION BY HASH (part_params) PARTITIONS number ;

The following table describes the parameters that are used in the syntax.

Parameter Description
part_params The partition field.
number The number of hash partitions.

The following example shows the corresponding statement:

CREATE TABLE part_hash (deptno NUMBER, deptname VARCHAR(32))
     PARTITION BY HASH(deptno) PARTITIONS 4;

Create hash subpartitions

Syntax

CREATE TABLE ... PARTITION BY part_strategy ( part_params )  SUBPARTITION BY HASH ( part_params)  SUBPARTITIONS number ( table_partitions_list );

The following table describes the parameters that are used in the syntax.

Parameter Description
part_strategy The type of the partitioned table. The following types are supported:
  • RANGE
  • LIST
  • HASH
part_params The partition field.
table_partitions_list The list of partition definitions.
number The number of hash subpartitions.
  • The partitioning type is RANGE and the subpartitioning type is HASH. The following example shows the corresponding statement:
     CREATE TABLE part_test
      ( prod_id       NUMBER(6), 
      cust_id       NUMBER, 
      time_id       DATE, 
      channel_id    CHAR(1), 
      promo_id      NUMBER(6), 
      quantity_sold NUMBER(3), 
      amount_sold   NUMBER(10,2)
      )
     PARTITION BY RANGE (time_id) SUBPARTITION BY HASH (cust_id)
      SUBPARTITIONS 4
     ( PARTITION sales_q1_2006 VALUES LESS THAN (TO_DATE('01-APR-2006','dd-MON-yyyy'))(
            SUBPARTITION q1_europe,
            SUBPARTITION q1_asia ,
            SUBPARTITION q1_americas
           ), 
     PARTITION sales_q2_2006 VALUES LESS THAN (TO_DATE('01-JUL-2006','dd-MON-yyyy')), 
     PARTITION sales_q3_2006 VALUES LESS THAN (TO_DATE('01-OCT-2006','dd-MON-yyyy')), 
     PARTITION sales_q4_2006 VALUES LESS THAN (TO_DATE('01-JAN-2007','dd-MON-yyyy'))
     );
  • Both the partitioning type and the subpartitioning type is HASH. The following example shows the corresponding statement:
    CREATE TABLE part_test
      ( prod_id       NUMBER(6), 
      cust_id       NUMBER, 
      time_id       DATE, 
      channel_id    CHAR(1), 
      promo_id      NUMBER(6), 
      quantity_sold NUMBER(3), 
      amount_sold   NUMBER(10,2)
      )
    PARTITION BY HASH (prod_id) SUBPARTITION BY HASH (cust_id) 
      PARTITIONS 4 SUBPARTITIONS 4;

Related documentation

CREATE TABLE... PARTITION BY