Skip to content

Commit 64444ce

Browse files
committed
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
1 parent f2bf8fb commit 64444ce

File tree

1 file changed

+35
-63
lines changed

1 file changed

+35
-63
lines changed

src/backend/commands/tablecmds.c

Lines changed: 35 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2815,37 +2815,6 @@ MergeAttributes(List *columns, const List *supers, char relpersistence,
28152815
attributeName),
28162816
errdetail("%s versus %s", prevdef->compression, newdef->compression)));
28172817

2818-
/*
2819-
* In regular inheritance, columns in the parent's primary key
2820-
* get an extra not-null constraint.
2821-
*/
2822-
if (bms_is_member(parent_attno - FirstLowInvalidHeapAttributeNumber,
2823-
pkattrs))
2824-
{
2825-
CookedConstraint *nn;
2826-
2827-
nn = palloc(sizeof(CookedConstraint));
2828-
nn->contype = CONSTR_NOTNULL;
2829-
nn->conoid = InvalidOid;
2830-
nn->name = NULL;
2831-
nn->attnum = exist_attno;
2832-
nn->expr = NULL;
2833-
nn->skip_validation = false;
2834-
nn->is_local = false;
2835-
nn->inhcount = 1;
2836-
nn->is_no_inherit = false;
2837-
2838-
nnconstraints = lappend(nnconstraints, nn);
2839-
}
2840-
2841-
/*
2842-
* mark attnotnull if parent has it and it's not NO INHERIT
2843-
*/
2844-
if (bms_is_member(parent_attno, nncols) ||
2845-
bms_is_member(parent_attno - FirstLowInvalidHeapAttributeNumber,
2846-
pkattrs))
2847-
prevdef->is_not_null = true;
2848-
28492818
/*
28502819
* Check for GENERATED conflicts
28512820
*/
@@ -2877,45 +2846,48 @@ MergeAttributes(List *columns, const List *supers, char relpersistence,
28772846
*/
28782847
newdef->inhcount = 1;
28792848
newdef->is_local = false;
2880-
/* mark attnotnull if parent has it and it's not NO INHERIT */
2881-
if (bms_is_member(parent_attno, nncols) ||
2882-
bms_is_member(parent_attno - FirstLowInvalidHeapAttributeNumber,
2883-
pkattrs))
2884-
newdef->is_not_null = true;
28852849
inh_columns = lappend(inh_columns, newdef);
2886-
newattmap->attnums[parent_attno - 1] = ++child_attno;
28872850

2888-
/*
2889-
* In regular inheritance, columns in the parent's primary key
2890-
* get an extra not-null constraint. Partitioning doesn't
2891-
* need this, because the PK itself is going to be cloned to
2892-
* the partition.
2893-
*/
2894-
if (!is_partition &&
2895-
bms_is_member(parent_attno -
2896-
FirstLowInvalidHeapAttributeNumber,
2897-
pkattrs))
2898-
{
2899-
CookedConstraint *nn;
2900-
2901-
nn = palloc(sizeof(CookedConstraint));
2902-
nn->contype = CONSTR_NOTNULL;
2903-
nn->conoid = InvalidOid;
2904-
nn->name = NULL;
2905-
nn->attnum = newattmap->attnums[parent_attno - 1];
2906-
nn->expr = NULL;
2907-
nn->skip_validation = false;
2908-
nn->is_local = false;
2909-
nn->inhcount = 1;
2910-
nn->is_no_inherit = false;
2911-
2912-
nnconstraints = lappend(nnconstraints, nn);
2913-
}
2851+
newattmap->attnums[parent_attno - 1] = ++child_attno;
29142852

29152853
/* remember for default processing below */
29162854
savedef = newdef;
29172855
}
29182856

2857+
/*
2858+
* mark attnotnull if parent has it and it's not NO INHERIT
2859+
*/
2860+
if (bms_is_member(parent_attno, nncols) ||
2861+
bms_is_member(parent_attno - FirstLowInvalidHeapAttributeNumber,
2862+
pkattrs))
2863+
savedef->is_not_null = true;
2864+
2865+
/*
2866+
* In regular inheritance, columns in the parent's primary key get
2867+
* an extra not-null constraint. Partitioning doesn't need this,
2868+
* because the PK itself is going to be cloned to the partition.
2869+
*/
2870+
if (!is_partition &&
2871+
bms_is_member(parent_attno -
2872+
FirstLowInvalidHeapAttributeNumber,
2873+
pkattrs))
2874+
{
2875+
CookedConstraint *nn;
2876+
2877+
nn = palloc(sizeof(CookedConstraint));
2878+
nn->contype = CONSTR_NOTNULL;
2879+
nn->conoid = InvalidOid;
2880+
nn->name = NULL;
2881+
nn->attnum = newattmap->attnums[parent_attno - 1];
2882+
nn->expr = NULL;
2883+
nn->skip_validation = false;
2884+
nn->is_local = false;
2885+
nn->inhcount = 1;
2886+
nn->is_no_inherit = false;
2887+
2888+
nnconstraints = lappend(nnconstraints, nn);
2889+
}
2890+
29192891
/*
29202892
* Locate default/generation expression if any
29212893
*/

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy