@@ -2815,37 +2815,6 @@ MergeAttributes(List *columns, const List *supers, char relpersistence,
2815
2815
attributeName),
2816
2816
errdetail("%s versus %s", prevdef->compression, newdef->compression)));
2817
2817
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
-
2849
2818
/*
2850
2819
* Check for GENERATED conflicts
2851
2820
*/
@@ -2877,45 +2846,48 @@ MergeAttributes(List *columns, const List *supers, char relpersistence,
2877
2846
*/
2878
2847
newdef->inhcount = 1;
2879
2848
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;
2885
2849
inh_columns = lappend(inh_columns, newdef);
2886
- newattmap->attnums[parent_attno - 1] = ++child_attno;
2887
2850
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;
2914
2852
2915
2853
/* remember for default processing below */
2916
2854
savedef = newdef;
2917
2855
}
2918
2856
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
+
2919
2891
/*
2920
2892
* Locate default/generation expression if any
2921
2893
*/
0 commit comments