Updated on 2025-05-29 GMT+08:00

Partitioned Table

A partitioned table is a table object on which users perform operations. It supports the SELECT, INSERT, UPDATE, and DELETE operations of the data manipulation language (DML). Generally, the PARTITION BY clause is explicitly used in the table creation DDL statement to define a partitioned table. After a partitioned table is created, a record is added to the pg_class table. The value of the parttype field is 'p' (indicating level-1 partition) or '' (indicating level-2 partition), indicating that the table corresponding to the record is a partitioned table.

Note that a partitioned table is a logical concept, and no data is really stored in the corresponding physical table.

Example: t1_hash is a partitioned table whose partitioning type is hash.
gaussdb=# CREATE TABLE t1_hash (c1 INT, c2 INT, c3 INT)
PARTITION BY HASH(c1)
(
    PARTITION p0,
    PARTITION p1,
    PARTITION p2,
    PARTITION p3,
    PARTITION p4,
    PARTITION p5,
    PARTITION p6,
    PARTITION p7,
    PARTITION p8,
    PARTITION p9
);

gaussdb=# \d+ t1_hash
                      Table "public.t1_hash"
Column |  Type    | Modifiers | Storage | Stats target | Description
--------+---------+-----------+---------+--------------+-------------
c1     | integer |              | plain   |                 |
c2     | integer |              | plain   |                 |
c3     | integer |              | plain   |                 |
Partition By HASH(c1)
Number of partitions: 10 (View pg_partition to check each partition range.)
Distribute By: HASH(c1)
Location Nodes: ALL DATANODES
Has OIDs: no
Options: orientation=row, compression=no

-- Query the partitioning type of table t1_hash.
gaussdb=#  SELECT relname, parttype FROM pg_class WHERE relname = 't1_hash';
relname | parttype
---------+----------
t1_hash | p           
(1 row)

-- Drop table t1_hash.
gaussdb=# DROP TABLE t1_hash;