diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 64a0dacca4f..912674cc0b3 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -12769,6 +12769,13 @@ ATExecAlterCheckConstrEnforceability(List **wqueue, ATAlterConstraint *cmdcon, children = find_all_inheritors(RelationGetRelid(rel), lockmode, NULL); + /* + * Build the set of equivalent CHECK constraints that this command + * will attempt to change before visiting descendants. The root + * itself has already been checked above. + */ + changing_conids = list_make1_oid(currcon->oid); + foreach_oid(childoid, children) { if (childoid == RelationGetRelid(rel)) @@ -12785,35 +12792,20 @@ ATExecAlterCheckConstrEnforceability(List **wqueue, ATAlterConstraint *cmdcon, errcode(ERRCODE_INVALID_TABLE_DEFINITION), errmsg("constraint must be altered on child tables too"), errhint("Do not specify the ONLY keyword.")); - } - if (!cmdcon->is_enforced) - { /* - * Build the set of equivalent CHECK constraints that this - * command will attempt to change before visiting descendants. - * The root itself has already been checked above. + * It is sufficient to look up the constraint by name here. + * Supported DDL ensures that inheritable CHECK constraints + * with the same name have equivalent definitions when they + * are propagated to children or when inheritance is + * established. */ - changing_conids = list_make1_oid(currcon->oid); - - foreach_oid(childoid, children) - { - if (childoid == RelationGetRelid(rel)) - continue; - - /* - * It is sufficient to look up the constraint by name - * here. Supported DDL ensures that inheritable CHECK - * constraints with the same name have equivalent - * definitions when they are propagated to children or - * when inheritance is established. - */ + if (!cmdcon->is_enforced) changing_conids = list_append_unique_oid(changing_conids, get_relation_constraint_oid(childoid, cmdcon->conname, false)); - } } }