MergeAttributes code deduplication

The code handling NOT NULL constraints is duplicated in blocks merging
the attribute definition incrementally.  Deduplicate that code.

Author: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/52a125e4-ff9a-95f5-9f61-b87cf447e4da@eisentraut.org
This commit is contained in:
Peter Eisentraut 2024-01-26 09:04:27 +01:00
parent f2bf8fb048
commit 64444ce071

View File

@ -2815,37 +2815,6 @@ MergeAttributes(List *columns, const List *supers, char relpersistence,
attributeName),
errdetail("%s versus %s", prevdef->compression, newdef->compression)));
/*
* In regular inheritance, columns in the parent's primary key
* get an extra not-null constraint.
*/
if (bms_is_member(parent_attno - FirstLowInvalidHeapAttributeNumber,
pkattrs))
{
CookedConstraint *nn;
nn = palloc(sizeof(CookedConstraint));
nn->contype = CONSTR_NOTNULL;
nn->conoid = InvalidOid;
nn->name = NULL;
nn->attnum = exist_attno;
nn->expr = NULL;
nn->skip_validation = false;
nn->is_local = false;
nn->inhcount = 1;
nn->is_no_inherit = false;
nnconstraints = lappend(nnconstraints, nn);
}
/*
* mark attnotnull if parent has it and it's not NO INHERIT
*/
if (bms_is_member(parent_attno, nncols) ||
bms_is_member(parent_attno - FirstLowInvalidHeapAttributeNumber,
pkattrs))
prevdef->is_not_null = true;
/*
* Check for GENERATED conflicts
*/
@ -2877,19 +2846,26 @@ MergeAttributes(List *columns, const List *supers, char relpersistence,
*/
newdef->inhcount = 1;
newdef->is_local = false;
/* mark attnotnull if parent has it and it's not NO INHERIT */
inh_columns = lappend(inh_columns, newdef);
newattmap->attnums[parent_attno - 1] = ++child_attno;
/* remember for default processing below */
savedef = newdef;
}
/*
* mark attnotnull if parent has it and it's not NO INHERIT
*/
if (bms_is_member(parent_attno, nncols) ||
bms_is_member(parent_attno - FirstLowInvalidHeapAttributeNumber,
pkattrs))
newdef->is_not_null = true;
inh_columns = lappend(inh_columns, newdef);
newattmap->attnums[parent_attno - 1] = ++child_attno;
savedef->is_not_null = true;
/*
* In regular inheritance, columns in the parent's primary key
* get an extra not-null constraint. Partitioning doesn't
* need this, because the PK itself is going to be cloned to
* the partition.
* In regular inheritance, columns in the parent's primary key get
* an extra not-null constraint. Partitioning doesn't need this,
* because the PK itself is going to be cloned to the partition.
*/
if (!is_partition &&
bms_is_member(parent_attno -
@ -2912,10 +2888,6 @@ MergeAttributes(List *columns, const List *supers, char relpersistence,
nnconstraints = lappend(nnconstraints, nn);
}
/* remember for default processing below */
savedef = newdef;
}
/*
* Locate default/generation expression if any
*/