Skip to content

Commit 4ebe6fe

Browse files
committed
fix drop_single_update_trigger_internal() to avoid warnings; fix replace_hash_partition()
1 parent be854e7 commit 4ebe6fe

File tree

5 files changed

+31
-6
lines changed

5 files changed

+31
-6
lines changed

expected/pathman_basic.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,6 +1303,7 @@ SELECT * FROM test.hash_rel WHERE id = 123;
13031303
/* Test replacing hash partition */
13041304
CREATE TABLE test.hash_rel_extern (LIKE test.hash_rel INCLUDING ALL);
13051305
SELECT pathman.replace_hash_partition('test.hash_rel_0', 'test.hash_rel_extern');
1306+
NOTICE: trigger "hash_rel_upd_trig" for relation "test.hash_rel_0" does not exist, skipping
13061307
replace_hash_partition
13071308
------------------------
13081309
test.hash_rel_extern
@@ -1338,6 +1339,7 @@ CREATE TABLE test.hash_rel_wrong(
13381339
id INTEGER NOT NULL,
13391340
value INTEGER);
13401341
SELECT pathman.replace_hash_partition('test.hash_rel_1', 'test.hash_rel_wrong');
1342+
NOTICE: trigger "hash_rel_upd_trig" for relation "test.hash_rel_1" does not exist, skipping
13411343
ERROR: column "value" in child table must be marked NOT NULL
13421344
EXPLAIN (COSTS OFF) SELECT * FROM test.hash_rel;
13431345
QUERY PLAN

hash.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,19 @@ BEGIN
143143
EXECUTE format('ALTER TABLE %s DROP CONSTRAINT %s',
144144
old_partition,
145145
old_constr_name);
146+
EXECUTE format('DROP TRIGGER IF EXISTS %s ON %s',
147+
@[email protected]_update_trigger_name(parent_relid),
148+
old_partition);
146149

147150
/* Attach the new one */
148151
EXECUTE format('ALTER TABLE %s INHERIT %s', new_partition, parent_relid);
149152
EXECUTE format('ALTER TABLE %s ADD CONSTRAINT %s %s',
150153
new_partition,
151154
@[email protected]_check_constraint_name(new_partition::REGCLASS),
152155
old_constr_def);
156+
IF @[email protected]_update_trigger(parent_relid) THEN
157+
PERFORM @[email protected]_single_update_trigger(parent_relid, new_partition);
158+
END IF;
153159

154160
/* Fetch init_callback from 'params' table */
155161
WITH stub_callback(stub) as (values (0))

range.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ BEGIN
970970
INTO v_init_callback;
971971

972972
/* If update trigger is enabled then create one for this partition */
973-
if @[email protected]_update_trigger(parent_relid) THEN
973+
IF @[email protected]_update_trigger(parent_relid) THEN
974974
PERFORM @[email protected]_single_update_trigger(parent_relid, partition_relid);
975975
END IF;
976976

src/partition_creation.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,14 +1827,33 @@ drop_single_update_trigger_internal(Oid relid,
18271827
DropStmt *n = makeNode(DropStmt);
18281828
const char *relname = get_qualified_rel_name(relid);
18291829
List *namelist = stringToQualifiedNameList(relname);
1830+
Relation relation = NULL;
1831+
ObjectAddress address;
18301832

18311833
namelist = lappend(namelist, makeString((char *) trigname));
1834+
1835+
/*
1836+
* To avoid warning message about missing trigger we check it beforehand.
1837+
* and quit if it doesn't
1838+
*/
1839+
address = get_object_address(OBJECT_TRIGGER,
1840+
namelist, NIL,
1841+
&relation,
1842+
AccessExclusiveLock,
1843+
true);
1844+
if (!OidIsValid(address.objectId))
1845+
return;
1846+
1847+
/* Actually remove trigger */
18321848
n->removeType = OBJECT_TRIGGER;
1833-
n->missing_ok = true;
18341849
n->objects = list_make1(namelist);
18351850
n->arguments = NIL;
18361851
n->behavior = DROP_RESTRICT; /* default behavior */
1837-
n->concurrent = false;
1838-
1852+
n->missing_ok = true;
1853+
n->concurrent = false;
18391854
RemoveObjects(n);
1855+
1856+
/* Release any relcache reference count, but keep lock until commit. */
1857+
if (relation)
1858+
heap_close(relation, NoLock);
18401859
}

src/pl_funcs.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,8 +1527,6 @@ create_update_triggers_internal(Oid relid)
15271527

15281528
/* Check that table is partitioned */
15291529
prel = get_pathman_relation_info(relid);
1530-
/* TODO: check this only for topmost relid? */
1531-
// shout_if_prel_is_invalid(relid, prel, PT_ANY);
15321530
if (!prel)
15331531
return;
15341532

0 commit comments

Comments
 (0)