All Products
Search
Document Center

Hologres:CREATE LOGICAL PARTITION TABLE

Last Updated:Nov 11, 2025

Hologres V3.1 and later supports logical partition tables. In a logical partition table, the parent table is a physical table, and its child tables are logical concepts. This topic describes how to use the CREATE LOGICAL PARTITION TABLE statement.

Limits

  • Only Hologres V3.1 and later supports logical partition tables.

  • Logical partition tables support only LIST partitioning. You can specify up to two partition key columns.

  • The partition key for a logical partition table supports the following data types: INT, TEXT, VARCHAR, DATE, TIMESTAMP, and TIMESTAMPTZ.

  • The partition key for a logical partition table must have the NOT NULL property.

  • The partition key for a logical partition table can be a generated column.

  • A single logical partition table supports a maximum of 5,200 partitions. A database supports a maximum of 200,000 logical partitions in total.

  • Because logical partition tables automatically create partitions when you write data, the following limits and recommendations apply:

    • Optimize data write jobs and use Data Quality to avoid dirty data. For example, if you partition data by day, avoid data with timestamps other than 00:00:00. This practice prevents the excessive expansion of partitions.

    • Write data to partitions sequentially to avoid writing to too many partitions at the same time.

    • The following limits apply to import jobs for a single table:

      • During a batch import, a single import job can import data into a maximum of 50 partitions. If this limit is exceeded, the error message Bulkload partition count exceed limit, partition count is xxx, limit is xxx is returned.

      • When you import data using a Fixed Plan, if the number of partitions being written to simultaneously in a single table exceeds 30, new write requests are throttled. The requests are automatically committed after a few seconds.

      • When you import data using a Fixed Plan, if the number of partitions being written to simultaneously in a single table exceeds 100, new write requests fail with the error message mem partition count exceed reject limit.

    • The following throttling mechanisms apply at the instance or compute group level:

      • If more than 50 new partitions are created per minute, new partition creation requests are throttled. The requests are automatically committed after a few seconds.

      • If more than 100 new partitions are created per minute, new partition creation requests fail with the error message mem partition count exceed reject limit.

      • For in-memory tables, when you use a Fixed Plan, if the total number of partitions being written to simultaneously reaches 500, new write requests are throttled. The requests are automatically committed after a few seconds. The total number is calculated using the following formula: (Number of partitions written to in a single table × Number of shards / Number of workers). For tables that use both row and column storage, multiply the result by 2. Then, sum the results for all tables.

      • For in-memory tables, when you use a Fixed Plan, if the total number of partitions being written to simultaneously reaches 5,000, new write requests fail with the error message mem partition count exceed reject limit. The total number is calculated using the following formula: (Number of partitions written to in a single table × Number of shards / Number of workers). For tables that use both row and column storage, multiply the result by 2. Then, sum the results for all tables.

Notes

  • Avoid using partitions with a very small data volume, such as less than 100 million rows. This practice can reduce query acceleration performance and create many small files. Instead, use a larger partition granularity.

  • If you frequently need to replace all data in a partition using operations such as `TRUNCATE` or `INSERT OVERWRITE`, use partitioned tables. They provide better performance and help avoid large-scale delete operations.

  • `TRUNCATE` operations do not support binary logging. You must execute the SET hg_experimental_generate_binlog = off command at the session level.

  • You do not need to manually create partitions for a logical partition table. A partition exists only if it contains data. When all data in a partition is deleted, the partition is also automatically deleted.

    Note

    Hologres performs data cleanup as an asynchronous operation. Therefore, partitions are also deleted asynchronously.

  • To modify the properties of a logical partition table, use the REBUILD syntax. The system automatically splits the task and executes it sequentially by partition. To perform a resharding operation, which modifies the table's table group, do not use the `HG_MOVE_TABLE_TO_TABLE_GROUP` stored procedure. For more information, see Table Group and shard count operations.

Create a logical partition table

Syntax

Note

The partitions of a logical partition table are determined by its data. Therefore, you do not need to manually create or delete partitions.

-- Statement to create a logical parent partition table
CREATE TABLE [IF NOT EXISTS] [<schema_name>.]<table_name>  ([
  {
   <column_name> <column_type> [ <column_constraints>, [...]]
   | <table_constraints>
   [, ...]
  }
])
LOGICAL PARTITION BY LIST(<partition_column_1> [, <partition_column_2>])
[WITH(
  <property_name> = <property_value>
 [, ...]
)];

Parameters

Parameter

Description

schema_name

The name of the schema where the table resides.

If you create the parent and child tables in the same schema, you do not need to specify the schema name. If you create them across different schemas, you must specify the schema name.

table_name

The name of the parent partitioned table to create.

column_name

The name of the field to create in the new table.

column_type

The data type of the field.

column_constraints

The name of the column constraint.

table_constraints

The name of the table constraint.

partition_column

The partition key of the logical partition table. You can set one or two partition keys.

property_name

The name of the table property to set for the logical partition table.

property_value

The value to set for the table property.

Table properties

The parent table of a logical partition table supports the following table properties.

Note

In a logical partition table, the parent table is a physical table and the partitions are logical concepts. Therefore, you cannot set the following properties for individual partitions.

Property

Description

partition_expiration_time

The expiration duration for partitions. After a partition expires, its data is asynchronously cleared.

  • By default, partitions do not expire, and data is not automatically cleared.

  • You can set values such as '30 day' or '12 month'. The time unit for this parameter should match the unit of the partition key.

Note

This property applies only to a single partition key of a time-based data type.

partition_keep_hot_window

The duration for which partition data remains in hot storage. After this period, the data is asynchronously moved to cold storage. For more information about hot and cold storage, see Data tiering.

  • By default, all data is in hot storage and is not automatically moved to cold storage.

  • You can set values such as '30 day' or '12 month'. The time unit for this parameter should match the unit of the partition key.

Note

This property applies only to a single partition key of a time-based data type.

partition_require_filter

Specifies whether a filter condition on the partition key is required when you query the parent table. Valid values:

  • TRUE: A filter condition is required. Otherwise, an error is returned.

  • FALSE (default): A filter condition is not required. You can query the parent table directly.

binlog_level

Specifies whether to enable binary logging for the parent table. For more information about the binary logging feature, see Subscribe to Hologres binary logs. Valid values:

  • 'none' (default): Disables binary logging.

  • 'replica': Enables binary logging.

binlog_ttl

The time to live (TTL) for binary log data, in seconds. The default value is 2592000, which is 30 days.

partition_generate_binlog_window

The time window for generating binary logs for parent table data. Binary logs are generated only for data in partitions that fall within the range of `current time - parameter value`.

  • By default, no time window is set, which means binary logs are generated for all data in the parent table.

  • You can set values such as '3 day' or '12 hour'. The time unit for this parameter should match the unit of the partition key.

Note

This property applies only to a single partition key of a time-based data type.

Other important properties such as indexes

Logical partition tables also support indexes such as distribution_key and clustering_key, and other important properties such as orientation and time_to_live_in_seconds.

For more information about properties, see CREATE TABLE. You can refer to the scenarios listed in Scenario-based table creation and optimization to set appropriate values for index-related table properties.

Logical partition tables do not support the dynamic partition management properties of physical partition tables. For more information, see Dynamic partition management.

Partition properties

Partitions in a logical partition table support the following properties. You can modify these properties using ALTER LOGICAL PARTITION TABLE.

Partition property

Description

keep_alive

Specifies whether the partition is automatically cleared. Valid values:

  • TRUE: The partition is not automatically cleared. It is not affected by the partition_expiration_time parameter of the parent table.

  • FALSE (default): The partition is affected by the partition_expiration_time parameter of the parent table and is automatically cleared upon expiration.

This property takes effect only when the partition_expiration_time parameter is set for the parent table.

storage_mode

Specifies whether the partition maintains a specific storage class. By default, this property is not set, and the partition is controlled by the partition_keep_hot_window parameter of the parent table. Valid values:

  • 'hot': The partition remains in hot storage. It is not affected by the partition_keep_hot_window parameter of the parent table.

  • 'cold': The partition remains in cold storage. It is not affected by the partition_keep_hot_window parameter of the parent table.

generate_binlog

Specifies whether to generate a binary log for the partition. By default, this property is not set, and the partition is controlled by the partition_generate_binlog_window parameter of the parent table. Valid values:

  • 'on': A binary log is generated for the partition. It is not affected by the partition_generate_binlog_window parameter of the parent table.

  • 'off': A binary log is not generated for the partition. It is not affected by the partition_generate_binlog_window parameter of the parent table.

Examples

  • Set a standard column `ds` as the partition key.

    CREATE TABLE public.hologres_logical_parent_1 (
        a TEXT,
        b INT,
        c TIMESTAMP,
        ds DATE NOT NULL,
        PRIMARY KEY (b, ds)) 
    LOGICAL PARTITION BY LIST (ds) 
    WITH (
        orientation = 'column',
        distribution_key = 'b',
        partition_expiration_time = '30 day', 
        partition_keep_hot_window = '15 day', 
        partition_require_filter = TRUE,
        binlog_level = 'replica',
        partition_generate_binlog_window = '3 day'
    );
  • Set a generated column `ds` as the partition key.

    CREATE TABLE public.hologres_logical_parent_2 (
        a TEXT,
        b INT,
        c TIMESTAMP,
        ds TIMESTAMP GENERATED ALWAYS AS (date_trunc('day', c)) STORED NOT NULL,
        PRIMARY KEY (b, ds)) 
    LOGICAL PARTITION BY LIST (ds) 
    WITH (
        orientation = 'column',
        distribution_key = 'b',
        partition_expiration_time = '30 day', 
        partition_keep_hot_window = '15 day', 
        partition_require_filter = TRUE,
        binlog_level = 'replica',
        partition_generate_binlog_window = '3 day'
    );
  • Set two partition key columns.

    CREATE TABLE public.hologres_logical_parent_3 (
        a TEXT,
        b INT,
        yy TEXT NOT NULL,
        mm TEXT NOT NULL)
    LOGICAL PARTITION BY LIST (yy, mm) 
    WITH (
        orientation = 'column',
        distribution_key = 'b',
        partition_require_filter = TRUE
    );

Manage data in a logical partition table

The following locks are acquired when you manage data in a logical partition table:

  • Batch import or update for a specified partition, or `TRUNCATE` for a specified partition: A partition metadata lock is acquired. Data management in other partitions is not affected.

  • Batch import or update without specifying a partition, `TRUNCATE` without specifying a partition, or any `DELETE` operation: A table lock is acquired. Other data management operations must wait for the lock to be released.

  • Data write, update, or delete operations using a Fixed Plan: Row locks are acquired. These operations can interfere with batch import, update, or delete operations on partitions or tables. They do not affect other data write, update, or delete operations that use a Fixed Plan.

Manage data in the parent table

For the parent table of a logical partition table, data write, update, and cleanup operations are the same as those for a standard table. The Hologres storage engine automatically adds or removes partitions based on the data.

  • Write data to the parent table.

    INSERT INTO public.hologres_logical_parent_2 
    VALUES 
        ('a', 1, '2025-03-16 10:00:00'), 
        ('b', 2, '2025-03-17 11:00:00'), 
        ('c', 3, '2025-03-18 12:00:00'), 
        ('d', 4, '2025-03-19 13:00:00'), 
        ('e', 5, '2025-03-20 14:00:00');
  • Clear data from the parent table.

    -- Clear data using the DELETE command
    DELETE FROM public.hologres_logical_parent_2 WHERE ds = '2025-03-20';
    
    -- Clear data using the TRUNCATE command
    SET hg_experimental_generate_binlog = off;
    TRUNCATE public.hologres_logical_parent_2;

Manage data in partitions

Logical partition tables also support data management operations on specified partitions.

  • Import data into a logical partition. If the data to be imported does not match the specified partition, the non-matching data is ignored.

    -- Specify a partition and import data
    INSERT INTO public.hologres_logical_parent_1 
    PARTITION (ds = '2025-03-16')
    VALUES 
        ('a', 1, '2025-03-16 10:00:00', '2025-03-16');
    
    -- If the data does not match the partition, the non-matching data is not written, and no error is reported
    INSERT INTO public.hologres_logical_parent_1 
    PARTITION (ds = '2025-03-16')
    VALUES 
        ('a', 3, '2025-03-16 10:00:00', '2025-03-16'), 
        ('b', 2, '2025-03-17 11:00:00', '2025-03-17');
  • Clear data from partitions.

    The automatic DML routing feature of compute groups does not support routing `TRUNCATE` operations for specified partitions. You must execute these operations on the primary (Leader) compute group.

    -- Clear data using the DELETE command
    DELETE FROM public.hologres_logical_parent_1 WHERE ds = '2025-03-16' or ds = '2025-03-17';
    
    -- Clear data using the TRUNCATE command
    SET hg_experimental_generate_binlog = off;
    TRUNCATE public.hologres_logical_parent_1 PARTITION (ds = '2025-03-16') PARTITION (ds = '2025-03-17');
  • Overwrite partitions using INSERT OVERWRITE.

    Hologres V3.1 and later supports the native `INSERT OVERWRITE` syntax. You can perform `INSERT OVERWRITE` operations on logical partition tables. For more information, see INSERT OVERWRITE.

    Important

    An `INSERT OVERWRITE` job is a sync task. If you specify multiple logical partitions at the same time, the `INSERT OVERWRITE` jobs for these partitions are processed in parallel. This can cause high CPU and memory pressure. To perform an `INSERT OVERWRITE` operation on multiple logical partitions, we recommend that you split the operation into multiple jobs by partition and process them sequentially.

Query a logical partition table

Unlike physical partition tables, logical partition tables support the `partition_require_filter` property. If this property is set to TRUE, the search statement must include a filter condition on the partition key when you query the table.

  • Query a logical partition table with a filter condition on the partition key.

    SELECT * FROM public.hologres_logical_parent_1 WHERE ds = '2025-03-16';
  • Query a logical partition table without a filter condition on the partition key. This requires the `partition_require_filter` property of the parent table to be FALSE.

    SELECT * FROM public.hologres_logical_parent_1;

Other operations

Hologres provides the following system tables and system functions to query the metadata of logical partition tables.

  • hologres.hg_list_logical_partition('<table_name>'): Lists all partitions of a logical partition table.

  • hologres.hg_logical_partitioned_table_properties: Lists all logical partitions and their property configurations in the current instance.

  • hologres.hg_partition_file_status('<table_name>'): Starting from Hologres V3.1.4, you can use this function to query the amount of data stored in hot and cold storage for all partitions in a logical partition table.

Examples:

  • View all logical partitions of a table.

    SELECT * FROM hologres.hg_list_logical_partition ('<schema_name>.<table_name>');
  • View the property configurations of all logical partitions of a table.

Note: This query displays only the configurations of subpartitions that differ from the parent table. If the result is empty, the subpartitions have no special configurations.

SELECT
    *
FROM
    hologres.hg_logical_partitioned_table_properties
WHERE 
    table_namespace = '<schema_name>'
    AND table_name = '<table_name>'
ORDER BY partition DESC;
  • View the current amount of data in hot and cold storage for all logical partitions in the table.

    SELECT * FROM hologres.hg_partition_file_status ('<schema_name>.<table_name>');

In addition to the preceding system tables, a logical partition table is a physical table. It is compatible with other Hologres system tables and supports the same metadata query methods as standard tables. The following examples show how to query metadata:

  • View the DDL statement of a logical partition table.

    SELECT hg_dump_script('<schema_name>.<table_name>');
  • View the properties of the parent table of a logical partition table.

    SELECT
        *
    FROM
        hologres.hg_table_properties
    WHERE 
        table_namespace = '<schema_name>'
        AND table_name = '<table_name>';
  • View the largest partition of a logical partition table.

    Note

    Data cleanup and partition cleanup for logical partition tables are asynchronous operations. To clear data from the largest partition, use the `INSERT OVERWRITE` operation to delete the data. Otherwise, the `MAX_PT` function might return an incorrect result.

    SELECT MAX_PT('<schema_name>.<table_name>');

References