Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commited74309

Browse files
committed
Reset relhassubclass upon attaching table as a partition
We don't allow inheritance parents as partitions, and have checks toprevent this; but if a table _was_ in the past an inheritance parentsand all their children are removed, the pg_class.relhassubclass flagmay remain set, which confuses the partition pruning code (mostobviously, it results in an assertion failure; in production builds itmay be worse.)Fix by resetting relhassubclass on attach.Backpatch to all supported versions.Reported-by: Alexander Lakhin <exclusion@gmail.com>Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>Discussion:https://postgr.es/m/18550-d5e047e9a897a889@postgresql.org
1 parent6c1b71b commited74309

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

‎src/backend/catalog/heap.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3808,6 +3808,14 @@ StorePartitionBound(Relation rel, Relation parent, PartitionBoundSpec *bound)
38083808
new_val,new_null,new_repl);
38093809
/* Also set the flag */
38103810
((Form_pg_class)GETSTRUCT(newtuple))->relispartition= true;
3811+
3812+
/*
3813+
* We already checked for no inheritance children, but reset
3814+
* relhassubclass in case it was left over.
3815+
*/
3816+
if (rel->rd_rel->relkind==RELKIND_RELATION&&rel->rd_rel->relhassubclass)
3817+
((Form_pg_class)GETSTRUCT(newtuple))->relhassubclass= false;
3818+
38113819
CatalogTupleUpdate(classRel,&newtuple->t_self,newtuple);
38123820
heap_freetuple(newtuple);
38133821
table_close(classRel,RowExclusiveLock);

‎src/test/regress/expected/alter_table.out

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3911,8 +3911,16 @@ ALTER TABLE list_parted ATTACH PARTITION child FOR VALUES IN (1);
39113911
ERROR: cannot attach inheritance child as partition
39123912
ALTER TABLE list_parted ATTACH PARTITION parent FOR VALUES IN (1);
39133913
ERROR: cannot attach inheritance parent as partition
3914+
DROP TABLE child;
3915+
-- now it should work, with a little tweak
3916+
ALTER TABLE parent ADD CONSTRAINT check_a CHECK (a > 0);
3917+
ALTER TABLE list_parted ATTACH PARTITION parent FOR VALUES IN (1);
3918+
-- test insert/update, per bug #18550
3919+
INSERT INTO parent VALUES (1);
3920+
UPDATE parent SET a = 2 WHERE a = 1;
3921+
ERROR: new row for relation "parent" violates partition constraint
3922+
DETAIL: Failing row contains (2, null).
39143923
DROP TABLE parent CASCADE;
3915-
NOTICE: drop cascades to table child
39163924
-- check any TEMP-ness
39173925
CREATE TEMP TABLE temp_parted (a int) PARTITION BY LIST (a);
39183926
CREATE TABLE perm_part (a int);

‎src/test/regress/sql/alter_table.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,6 +2413,13 @@ CREATE TABLE parent (LIKE list_parted);
24132413
CREATETABLEchild () INHERITS (parent);
24142414
ALTERTABLE list_parted ATTACH PARTITION child FORVALUESIN (1);
24152415
ALTERTABLE list_parted ATTACH PARTITION parent FORVALUESIN (1);
2416+
DROPTABLE child;
2417+
-- now it should work, with a little tweak
2418+
ALTERTABLE parent ADDCONSTRAINT check_aCHECK (a>0);
2419+
ALTERTABLE list_parted ATTACH PARTITION parent FORVALUESIN (1);
2420+
-- test insert/update, per bug #18550
2421+
INSERT INTO parentVALUES (1);
2422+
UPDATE parentSET a=2WHERE a=1;
24162423
DROPTABLE parent CASCADE;
24172424

24182425
-- check any TEMP-ness

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp