Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

Versions available for this page: CUBRID 8.3.0 |  CUBRID 8.3.1 |  CUBRID 8.4.0 |  CUBRID 8.4.1 |  CUBRID 8.4.3 |  CUBRID 9.0.0 | 

Hash Partitioning Definition

Description

You can define a hash partition by using the PARTITION BY HASH clause.

Syntax

CREATE TABLE (

...

)

( PATITION BY HASH ( <partition_expression> )

 PATITIONS ( <number_of_partitions> )

)

  • partition_expression : Specifies a partition expression. The expression can be specified by the name of the column to be partitioned or by a function.
  • number_of_partitions : Specifies the number of partitions.
Example 1

The following is an example of creating the nation2 table with country codes and country names, and defining 4 hash partitions based on code values. Only the number of partitions, not the name, is defined in hash partitioning; names such as p0 and p1 are assigned automatically.

CREATE TABLE nation2

( code CHAR(3),

name VARCHAR(50) )

PARTITION BY HASH ( code) PARTITIONS 4;

Example 2

The following is an example of inserting data to the hash partition created in the example 1. When a value is inserted into a hash partition, the partition to store the data is determined by the hash value of the partition key. If the partition key value is NULL, the data is stored in the first partition.

INSERT INTO nation2 VALUES ('KOR','Korea');

INSERT INTO nation2 VALUES ('USA','USA United States of America');

INSERT INTO nation2 VALUES ('FRA','France');

INSERT INTO nation2 VALUES ('DEN','Denmark');

INSERT INTO nation2 VALUES ('CHN','China');

INSERT INTO nation2 VALUES (NULL,'AAA');

Caution
  • The maximum number of partitions cannot exceed 1,024.