DQL/DML-DDL Concurrency
Level-8 locks will be used for table-level DDL statements on a partitioned table. All DQL/DML statements are blocked.
Level-4 locks will be used for partition-level DDL statements on a partitioned table and level-8 locks will be used for the target partition. When DQL/DML and DDL statements are used in different partitions, concurrent execution is supported. When DQL/DML and DDL statements are used in the same partition, statements triggered later will be blocked.
If the target partitions of the concurrent DDL and DQL/DML statements overlap, the DQL/DML statements may occur before or after the DDL statements due to serial blocking. You need to know the possible expected results. For example, when TRUNCATE and INSERT take effect on the same partition, if TRUNCATE is triggered before INSERT, data exists in the target partition after the statements are complete. If TRUNCATE is triggered after INSERT, no data exists in the target partition after the statements are complete.
During partition-level DDL operations, do not perform DQL/DML operations on the target partition at the same time.
DQL/DML-DDL Concurrency Across Partitions
GaussDB supports DQL/DML-DDL concurrency across partitions.
CREATE TABLE range_sales ( product_id INT4 NOT NULL, customer_id INT4 NOT NULL, time_id DATE, channel_id CHAR(1), type_id INT4, quantity_sold NUMERIC(3), amount_sold NUMERIC(10,2) ) PARTITION BY RANGE (time_id) ( PARTITION time_2008 VALUES LESS THAN ('2009-01-01'), PARTITION time_2009 VALUES LESS THAN ('2010-01-01'), PARTITION time_2010 VALUES LESS THAN ('2011-01-01'), PARTITION time_2011 VALUES LESS THAN ('2012-01-01') );
-- In case 1, inserting partition time_2011 and truncating partition time_2008 do not block each other. \parallel on INSERT INTO range_sales VALUES (455124, 92121433, '2011-09-17', 'X', 4513, 7, 17); ALTER TABLE range_sales TRUNCATE PARTITION time_2008 UPDATE GLOBAL INDEX; \parallel off -- In case 2, querying partition time_2010 and exchanging partition time_2009 do not block each other. \parallel on SELECT COUNT(*) FROM range_sales PARTITION (time_2010); ALTER TABLE range_sales EXCHANGE PARTITION (time_2009) WITH TABLE temp UPDATE GLOBAL INDEX; \parallel off -- In case 3, updating partitioned table range_sales and dropping partition time_2008 do not block each other. This is because the SQL statement with a condition (partition pruning) updates the time_2010 and time_2011 partitions only. \parallel on UPDATE range_sales SET channel_id = 'T' WHERE channel_id = 'X' AND time_id > '2010-06-01'; ALTER TABLE range_sales DROP PARTITION time_2008 UPDATE GLOBAL INDEX; \parallel off -- In case 4, any DQL/DML statement of partitioned table range_sales and adding partition time_2012 do not block each other. This is because ADD PARTITION is invisible to other statements. \parallel on DELETE FROM range_sales WHERE channel_id = 'T'; ALTER TABLE range_sales ADD PARTITION time_2012 VALUES LESS THAN ('2013-01-01'); \parallel off
DQL/DML-DDL Concurrency on the Same Partition
GaussDB does not support DQL/DML-DDL concurrency on the same partition. A triggered statement will block the subsequent statements.
In principle, you are not advised to perform DQL/DML operations on a partition when performing DDL operations on the partition. This is because the status of the target partition changes abruptly, which may cause unexpected statement query results.
If the DQL/DML and DDL target partitions overlap due to improper statements or pruning failures, consider the following two scenarios:
Scenario 1: If DQL/DML statements are triggered before DDL statements, DDL statements are blocked until DQL/DML statements are committed.
Scenario 2: if DDL statements are triggered before DQL/DML statements, DQL/DML statements are blocked and are executed after DDL statements are committed. The result may be unexpected. To ensure data consistency, the expected result is formulated based on the following rules:
- ADD PARTITION
During ADD PARTITION, a new partition is generated and is invisible to the triggered DQL/DML statements. There is no blocking.
- DROP PARTITION
During DROP PARTITION, an existing partition is dropped, and the DQL/DML statements triggered on the target partition are blocked. After the blocking is complete, the processing on the partition will be skipped.
- TRUNCATE PARTITION
During TRUNCATE PARTITION, data is cleared from an existing partition, and the DQL/DML statements triggered on the target partition are blocked. After the blocking is complete, the processing on the partition continues.
Note that no data can be queried in the target partition during this period because no data exists in the target partition after the TRUNCATE operation is committed.
- EXCHANGE PARTITION
The EXCHANGE PARTITION exchanges an existing partition with an ordinary table. During this period, the DQL/DML statements on the target partition are blocked. After the blocking is complete, the partition processing continues. The actual data of the partition corresponds to the original ordinary table.
Exception: If the global index exists in the partitioned table, the EXCHANGE statement contains the UPDATE GLOBAL INDEX clause, and the partitioned table query triggered during this period uses the global index, the data in the partition after the exchange cannot be queried. As a result, an error is reported during the query after the blocking is complete.
ERROR: partition xxxxxx does not exist on relation "xxxxxx"
DETAIL: this partition may have already been dropped by cocurrent DDL operations EXCHANGE PARTITION
- SPLIT PARTITION
The SPLIT PARTITION splits a partition into multiple partitions. Even if a new partition has the same name as the source partition, the new partition is regarded as a different partition. During this period, the DQL/DML statements on the target partition are blocked. After the blocking is complete, an error is reported.
ERROR: partition xxxxxx does not exist on relation "xxxxxx"
DETAIL: this partition may have already been dropped by cocurrent DDL operations SPLIT PARTITION
- MERGE PARTITION
The MERGE PARTITION merges multiple partitions into one partition. If the name of the merged partition is the same as that of any of the source partitions, the merged partition is logically considered the same as the source partition. The DQL/DML statements on the target partition triggered during this period are blocked. After the blocking is complete, the system determines whether the target partition is the specified source partition based on the target partitioning type. If the target partition is the specified source partition, the statements take effect on the new partition. If the target partition is another source partition, an error is reported.
ERROR: partition xxxxxx does not exist on relation "xxxxxx"
DETAIL: this partition may have already been dropped by cocurrent DDL operations MERGE PARTITION
- RENAME PARTITION
The RENAME PARTITION does not change the partition structure information. The DQL/DML statements triggered during this period do not encounter any exception but are blocked until the RENAME operation is committed.
- MOVE PARTITION
The MOVE PARTITION does not change the partition structure information. The DQL/DML statements triggered during this period do not encounter any exception but are blocked until the MOVE operation is committed.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot