This topic provides implementation details about partitioned tables to facilitate the use of these tables.
How partitioned tables are created
The creation of partitioned table involves two modules: syntax parsing and execution.
Syntax parsing module
Creation is the essential operation for table partitioning. A partitioned table is created through a CREATE TABLE statement that contains specific keywords.
Here are some of the keywords:
PARTITION BY: specifies the partitioning strategy and partition key of partitions.SUBPARTITION BY: specifies the partitioning strategy and partition key of subpartitions.INTERVAL: specifies the intervals for range partitioning.SUBPARTITION TEMPLATE: specifies the templates for subpartitioning.(PARTITION xxx): specifies a list of subpartitions.
After receiving the statement, the system first converts the statement into nodes in the database. The following figure shows the conversion process.

The entire structure is under the
CreateStmtnode.The
partspecnode is the first level for managing partitioning. It handles the partition key and partitioning strategy.The PartitionInfor node is the second level for managing partitioning. It manages most of the structures in the syntax. In the preceding figure, different colors are used to indicate the categories of the structures:
Intervals
Level-1 partitioning
Level-2 partitioning (subpartitioning)
Partitioning templates
List of second-level nodes
Execution module
The executor executes the table creation command in three steps.
Step 1: Stores the table definition
In this step, the template information that may be used for creating partitions in the future are stored in the table definition.
The table definition is stored in the Option structure of the table, including the following information:
interval_expr: stores the intervals for range partitioning.
sub_part_strategy/sub_part_params: stores the partition key and partition strategy for subpartitioning.
partition_template_list: stores the list of partitioning templates, which are used for the subsequent creation of partitions.
sub_hash_number: stores the number of hashs to create hash partitions.

Step 2: Generates partition definitions
In this step, the information is converted into lists for creation.
Generates node trees based on the hash number or template list, which will be used to create partitions.
NoteFor level-1 partitions, the partition_node_list is generated based on the hash_number.
For level-2 partitions, the partition_node_list is generated based on the template_list that is generated if partition templates are defined.
Traverses the partition_node_list and supplement key information such as the partitioning strategy and partition key.
Checks whether the sub_hash_number or template_list is empty. If they are, it indicates that the nodes also contain properties of level-2 partitions. The properties of level-2 partitions need to be added to the level-1 partitions to be processed later when level-2 partitions are created

Step 3: Creates the table
In this step, the table is actually created. The node list is converted into a creation list.
The PartitionRelNode, which contains child nodes, is converted into a CreateStmt node, based on which the system creates the table.

Management of partitioned tables
This section describes the commands used to managed partitioned tables.

The following are the main commands used to manage partitioned tables.
MODIFY: The collection of management operations on partitions. It can be performed on partitions and their subpartitions.
MOVE: Moves a partition to change its storage location.
ADD: Adds a partition to a partitioned table.
COLESCE: Merges two hash partitions to decrease the number of partitions of the parent hash-partitioned table by one.
DROP: Deletes a rang- or list-partition.
RENAME: Renames a partition.
TRUNCATE: Clears the data of a partition.
SPLIT: Splits a single rang- or list-partition to two based on a specified value.
MERGE: Merges two range- or list-partitions into one.
EXCHANGE: Swaps the content of two partitions. The operation needs to pass a validation check for their bounds.