All Products
Search
Document Center

PolarDB:HASH-LIST

Last Updated:Mar 28, 2026

HASH-LIST partitioning distributes rows across partitions by hashing a partition expression, then places each row into a subpartition based on a list of discrete values. Use this partitioning strategy when you need even data distribution at the top level (hash) and categorical grouping within each partition (list).

Syntax

CREATE TABLE [schema.]table_name
  table_definition
  PARTITION BY [LINEAR] HASH(expr)
    SUBPARTITION BY LIST (expr)
    (partition_definition [, partition_definition] ...)

partition_definition is:

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

subpartition_definition is:

SUBPARTITION subpartition_name
  VALUES IN (value_list)

Parameters

ParameterDescription
table_nameThe name of the table.
exprThe partition expression. Must be of the INT type — string types are not supported.
value_listThe list of boundary values for the subpartition.
partition_nameThe name of the partition. Must be unique within the table.
subpartition_nameThe name of the subpartition. Must be unique within the table.
Both PARTITION BY HASH and SUBPARTITION BY LIST expressions must evaluate to an INT. String types are not supported for either expression.

Create a HASH-LIST partitioned table

The following example creates a sales_hash_list table partitioned by dept_no (hash) and subpartitioned by part_no (list). The table has three partitions, each containing three subpartitions that cover values 1–6.

CREATE TABLE sales_hash_list
(
  dept_no     INT,
  part_no     INT,
  country     VARCHAR(20),
  date        DATE,
  amount      INT
)
PARTITION BY HASH(dept_no)
SUBPARTITION BY LIST(part_no)
(
  PARTITION dp0 (
    SUBPARTITION p0 VALUES IN (1, 2),
    SUBPARTITION p1 VALUES IN (3, 4),
    SUBPARTITION p2 VALUES IN (5, 6)
  ),
  PARTITION dp1 (
    SUBPARTITION p3 VALUES IN (1, 2),
    SUBPARTITION p4 VALUES IN (3, 4),
    SUBPARTITION p5 VALUES IN (5, 6)
  ),
  PARTITION dp2 (
    SUBPARTITION p6 VALUES IN (1, 2),
    SUBPARTITION p7 VALUES IN (3, 4),
    SUBPARTITION p8 VALUES IN (5, 6)
  )
);

How rows are routed

PolarDB determines the target subpartition for each row in two steps:

  1. Hash stepdept_no is hashed to select one of the three partitions (dp0, dp1, or dp2).

  2. List steppart_no is matched against the VALUES IN lists within that partition to select the subpartition.

The following examples illustrate how specific rows are routed. The partition assigned by the hash step depends on the hash function and the number of partitions.

dept_nopart_noExample partitionSubpartitionReason
53dp1p4dept_no=5 hashes to dp1; part_no=3 matches VALUES IN (3, 4)
26dp0p2dept_no=2 hashes to dp0; part_no=6 matches VALUES IN (5, 6)
91dp2p6dept_no=9 hashes to dp2; part_no=1 matches VALUES IN (1, 2)