Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit fce742d

Browse files
committed
improved function drop_partitions()
1 parent 5567629 commit fce742d

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

init.sql

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -581,23 +581,22 @@ DECLARE
581581
v_rec RECORD;
582582
v_rows BIGINT;
583583
v_part_count INTEGER := 0;
584-
conf_num_del INTEGER;
584+
conf_num INTEGER;
585585
v_relkind CHAR;
586586

587587
BEGIN
588588
PERFORM @extschema@.validate_relname(parent_relid);
589589

590-
/* Drop trigger first */
591-
PERFORM @extschema@.drop_triggers(parent_relid);
590+
/* Acquire data modification lock */
591+
PERFORM @extschema@.prevent_relation_modification(parent_relid);
592592

593-
WITH config_num_deleted AS (DELETE FROM @extschema@.pathman_config
594-
WHERE partrel = parent_relid
595-
RETURNING *)
596-
SELECT count(*) from config_num_deleted INTO conf_num_del;
593+
/* First, drop all triggers */
594+
PERFORM @extschema@.drop_triggers(parent_relid);
597595

598-
DELETE FROM @extschema@.pathman_config_params WHERE partrel = parent_relid;
596+
SELECT count(*) FROM @extschema@.pathman_config
597+
WHERE partrel = parent_relid INTO conf_num;
599598

600-
IF conf_num_del = 0 THEN
599+
IF conf_num = 0 THEN
601600
RAISE EXCEPTION 'relation "%" has no partitions', parent_relid::TEXT;
602601
END IF;
603602

@@ -621,8 +620,8 @@ BEGIN
621620
INTO v_relkind;
622621

623622
/*
624-
* Determine the kind of child relation. It can be either regular
625-
* table (r) or foreign table (f). Depending on relkind we use
623+
* Determine the kind of child relation. It can be either a regular
624+
* table (r) or a foreign table (f). Depending on relkind we use
626625
* DROP TABLE or DROP FOREIGN TABLE.
627626
*/
628627
IF v_relkind = 'f' THEN
@@ -634,6 +633,10 @@ BEGIN
634633
v_part_count := v_part_count + 1;
635634
END LOOP;
636635

636+
/* Finally delete both config entries */
637+
DELETE FROM @extschema@.pathman_config WHERE partrel = parent_relid;
638+
DELETE FROM @extschema@.pathman_config_params WHERE partrel = parent_relid;
639+
637640
RETURN v_part_count;
638641
END
639642
$$ LANGUAGE plpgsql

0 commit comments

Comments
 (0)