Hologres V3.1 and later supports logical partitioned tables. In a logical partitioned table, the parent table is a physical table, and the child tables are logical concepts. This topic describes how to use the CREATE LOGICAL PARTITION TABLE statement.
Limits
Only Hologres V3.1 and later instances support logical partitioned tables.
Logical partitioned tables support only
LISTpartitioning. You can select a maximum of two columns as partition keys.The partition key of a logical partitioned table supports the following data types: INT, TEXT, VARCHAR, DATE, TIMESTAMP, and TIMESTAMPTZ.
The partition key of a logical partitioned table must have the NOT NULL property.
The partition key of a logical partitioned table supports generated columns.
A single logical partitioned table supports a maximum of 5,200 partitions. A database supports a maximum of 200,000 logical partitions in total.
When you write data to a logical partitioned table, the corresponding partitions are created automatically. Note the following limits and suggestions:
Optimize data write jobs and 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 an excessive number of partitions from being created.
Write data to partitions sequentially. Avoid writing to too many partitions at the same time.
The following limits apply to import jobs for a single table:
For batch imports, a single import task supports a maximum of 50 partitions. Exceeding this limit results in the
Bulkload partition count exceed limit, partition count is xxx, limit is xxxerror.When you import data using Fixed Plan, if more than 30 partitions in a single table are being written to simultaneously, new write requests for partitions are throttled. The requests are automatically submitted after a few seconds.
When you import data using Fixed Plan, if the number of partitions being written to simultaneously in a single table exceeds 100, new requests to write to partitions fail with the
mem partition count exceed reject limiterror.
The following throttling mechanisms apply at the instance or compute group level:
If more than 50 partitions are created per minute, new requests to create partitions are throttled. The requests are automatically submitted after a few seconds.
If more than 100 partitions are created per minute, subsequent requests to create partitions fail with the
mem partition count exceed reject limiterror.For memory tables, if the total number of partitions being written to simultaneously using Fixed Plan reaches 500, new write requests for partitions are throttled and are automatically submitted after a few seconds. The total number of partitions is the sum of the following value calculated for each table: `Number of partitions written to in a single table × Number of shards / Number of workers`. For row-column hybrid tables, this value is multiplied by 2.
In memory tables, if the total number of partitions being written to simultaneously using a Fixed Plan reaches 5,000, new requests to write to partitions fail with a
mem partition count exceed reject limiterror. This total is the sum for all tables of the value calculated by `(Number of partitions written to per table × Number of shards / Number of workers)`. For hybrid row-column tables, this value is multiplied by 2.
Precautions
Do not create partitions with a small amount of data, such as less than 100 million rows. Otherwise, query acceleration is not significant, and many small files are more likely to be generated. We recommend that you choose a larger partition granularity.
If you frequently need to replace all data in a partition by running TRUNCATE or INSERT OVERWRITE operations, use standard partitioned tables. They provide better performance and help you avoid large-scale delete operations.
Because the TRUNCATE operation does not support binary logging, you must execute the
SET hg_experimental_generate_binlog = offcommand at the session level.You do not need to manually create partitions for a logical partitioned table. A partition exists only if it contains data. When all data in a partition is deleted, the partition is automatically deleted.
NoteBecause data cleanup in Hologres is an asynchronous operation, partitions are also deleted asynchronously.
To modify the properties of a logical partitioned table, use the REBUILD syntax. The system automatically splits the task and executes it sequentially by partition. To reshard a logical partitioned table, which means modifying its Table Group, do not use the HG_MOVE_TABLE_TO_TABLE_GROUP stored procedure. For more information, see Manage Table Groups and shard counts.
Create a logical partitioned table
Syntax
The partitions in a logical partitioned table are determined by the data within the table. You do not need to manually create or delete partitions.
-- Create a logical partitioned parent 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. You can omit the schema name if you create the parent table and its partitions within the same schema. You must specify the schema name if you create them in different schemas. |
table_name | The name of the parent table of the logical 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 partitioned table. You can set one or two partition keys. |
property_name | The name of the table property to set for the logical partitioned table. |
property_value | The value for the table property. |
Table properties
The parent table of a logical partitioned table supports the following properties.
Because the parent table of a logical partitioned table is a physical table and its partitions are logical concepts, you cannot set the following properties for individual partitions.
Property | Description |
partition_expiration_time | The expiration time for partitions. After a partition expires, its data is asynchronously cleaned up.
Note This parameter is effective only for a single partition key of a time-based data type. |
partition_keep_hot_window | The duration for which partition data is kept in hot storage. After this period, the data is asynchronously moved to cold storage. For more information about cold and hot storage, see Tiered storage.
Note This parameter is effective only for 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:
|
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:
|
binlog_ttl | The time to live (TTL) of binary log data, in seconds. The default value is 2,592,000, 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`.
Note This parameter is effective only for a single partition key of a time-based data type. |
Other important properties such as indexes | Logical partitioned 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 guide to set appropriate values for index-related table properties. Logical partitioned tables do not support the dynamic partition management properties of physical partitioned tables. For more information, see Dynamic partition management. |
Partition properties
Partitions of a logical partitioned table support the following properties. You can use the ALTER LOGICAL PARTITION TABLE statement to modify them.
Partition property | Description |
keep_alive | Specifies whether the partition is automatically cleaned up. Valid values:
This parameter 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 affected by the partition_keep_hot_window parameter of the parent table. Valid values:
|
generate_binlog | Specifies whether to generate binary logs for the partition. By default, this property is not set, and the partition is affected by the partition_generate_binlog_window parameter of the parent table. Valid values:
|
Examples
Set the regular 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 the 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 keys.
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 );
Data management for logical partitioned tables
When you manage data in a logical partitioned table, the following locks are applied:
Batch import or update of a specified partition, or TRUNCATE of a specified partition: A partition metadata lock is applied. This lock does not affect data management operations on other partitions.
Batch import or update without a specified partition, TRUNCATE without a specified partition, or any DELETE operation: A table lock is applied. Other data management operations must wait for the lock to be released.
Data write, update, or delete operations that use Fixed Plan: Row locks are applied. These operations can be affected by batch import, update, or delete operations on partitions or tables. They do not affect other data write, update, or delete operations that also use Fixed Plan.
Parent table data management
For the parent table of a logical partitioned table, data write, update, and cleanup operations are the same as those for a standard table. The Hologres storage engine automatically adds or cleans up partitions based on the data that they contain.
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');Clean up data in the parent table.
-- Clean up data using the DELETE command. DELETE FROM public.hologres_logical_parent_2 WHERE ds = '2025-03-20'; -- Clean up data using the TRUNCATE command. SET hg_experimental_generate_binlog = off; TRUNCATE public.hologres_logical_parent_2;
Partition data management
Logical partitioned 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 mismatched 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');Clean up partition data.
The automatic Data Manipulation Language (DML) routing feature of compute groups does not support automatically routing TRUNCATE operations for specified partitions. You must run the operation on the primary (Leader) compute group.
-- Clean up data using the DELETE command. DELETE FROM public.hologres_logical_parent_1 WHERE ds = '2025-03-16' or ds = '2025-03-17'; -- Clean up 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 a partition using INSERT OVERWRITE.
Hologres V3.1 and later support the native INSERT OVERWRITE syntax for logical partitioned tables. For more information, see INSERT OVERWRITE.
ImportantAn INSERT OVERWRITE job is a synchronous 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, you should split the operation into multiple jobs by partition and process them sequentially.
Query a logical partitioned table
Unlike physical partitioned tables, logical partitioned tables support the partition_require_filter property. If this property is set to TRUE, queries on the logical partitioned table must include a partition filter condition.
Query a logical partitioned table with a filter condition on the partition key.
SELECT * FROM public.hologres_logical_parent_1 WHERE ds = '2025-03-16';To query a logical partitioned table without a partition filter condition, you must set the partition_require_filter property of the parent table to
FALSE.SELECT * FROM public.hologres_logical_parent_1;
Other operations
Hologres provides the following system tables and functions to query the metadata of logical partitioned tables.
hologres.hg_list_logical_partition('<table_name>'): Lists all partitions of a logical partitioned 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 hot and cold storage used by all partitions in a logical partitioned 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.
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 hot and cold storage for all logical partitions in a table.
SELECT * FROM hologres.hg_partition_file_status ('<schema_name>.<table_name>');
In addition to the system tables listed above, the parent table of a logical partitioned table is a physical table. It is compatible with other Hologres system tables and supports the same metadata query methods as a standard table. The following examples show how to query metadata:
View the Data Definition Language (DDL) statement of the logical partitioned table.
SELECT hg_dump_script('<schema_name>.<table_name>');View the properties of the parent table of the logical partitioned table.
SELECT * FROM hologres.hg_table_properties WHERE table_namespace = '<schema_name>' AND table_name = '<table_name>';View the largest partition of the logical partitioned table.
NoteData cleanup and partition cleanup for logical partitioned tables are asynchronous operations. To clear the data in 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>');