Skip to content

Commit 2a31969

Browse files
committed
add parameter 'lock_parent' to function replace_hash_partition()
1 parent dc0a854 commit 2a31969

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

hash.sql

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,14 @@ SET client_min_messages = WARNING;
5959

6060
/*
6161
* Replace hash partition with another one. It could be useful in case when
62-
* someone wants to attach foreign table as a partition
62+
* someone wants to attach foreign table as a partition.
63+
*
64+
* lock_parent - should we take an exclusive lock?
6365
*/
6466
CREATE OR REPLACE FUNCTION @extschema@.replace_hash_partition(
6567
old_partition REGCLASS,
66-
new_partition REGCLASS)
68+
new_partition REGCLASS,
69+
lock_parent BOOL DEFAULT TRUE)
6770
RETURNS REGCLASS AS
6871
$$
6972
DECLARE
@@ -81,8 +84,13 @@ BEGIN
8184
/* Parent relation */
8285
parent_relid := @extschema@.get_parent_of_partition(old_partition);
8386

84-
/* Acquire lock on parent */
85-
PERFORM @extschema@.lock_partitioned_relation(parent_relid);
87+
IF lock_parent THEN
88+
/* Acquire data modification lock (prevent further modifications) */
89+
PERFORM @extschema@.prevent_relation_modification(parent_relid);
90+
ELSE
91+
/* Acquire lock on parent */
92+
PERFORM @extschema@.lock_partitioned_relation(parent_relid);
93+
END IF;
8694

8795
/* Acquire data modification lock (prevent further modifications) */
8896
PERFORM @extschema@.prevent_relation_modification(old_partition);

0 commit comments

Comments
 (0)