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

Commit 42534a8

Browse files
lathiarbCommitfest Bot
authored and
Commitfest Bot
committed
Fix MergeWithExistingConstraint()
If the child already has a valid constraint and we are creating an invalid one with same definition on it. The child's constraint will remain valid, but can no longer be marked as local.
1 parent 7afca7e commit 42534a8

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/backend/catalog/heap.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2826,11 +2826,24 @@ MergeWithExistingConstraint(Relation rel, const char *ccname, Node *expr,
28262826
{
28272827
if (is_local)
28282828
con->conislocal = true;
2829-
else if (pg_add_s16_overflow(con->coninhcount, 1,
2829+
else
2830+
{
2831+
if(pg_add_s16_overflow(con->coninhcount, 1,
28302832
&con->coninhcount))
2831-
ereport(ERROR,
2832-
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
2833-
errmsg("too many inheritance parents"));
2833+
ereport(ERROR,
2834+
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
2835+
errmsg("too many inheritance parents"));
2836+
2837+
/*
2838+
* If the child already has a valid constraint and we are
2839+
* creating an invalid one with same definition on it. The
2840+
* child's constraint will remain valid, but can no longer be
2841+
* marked as local.
2842+
*/
2843+
if (!is_initially_valid && con->convalidated &&
2844+
is_enforced && con->conenforced)
2845+
con->conislocal = false;
2846+
}
28342847
}
28352848

28362849
if (is_no_inherit)

src/test/regress/expected/inherit.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1571,7 +1571,7 @@ order by 1, 2;
15711571
relname | conname | convalidated | conislocal | coninhcount | connoinherit
15721572
-------------------------+----------------------+--------------+------------+-------------+--------------
15731573
invalid_check_con | inh_check_constraint | f | t | 0 | f
1574-
invalid_check_con_child | inh_check_constraint | t | t | 1 | f
1574+
invalid_check_con_child | inh_check_constraint | t | f | 1 | f
15751575
(2 rows)
15761576

15771577
-- We don't drop the invalid_check_con* tables, to test dump/reload with

0 commit comments

Comments
 (0)