@@ -350,7 +350,7 @@ static void truncate_check_perms(Oid relid, Form_pg_class reltuple);
350
350
static void truncate_check_activity(Relation rel);
351
351
static void RangeVarCallbackForTruncate(const RangeVar *relation,
352
352
Oid relId, Oid oldRelId, void *arg);
353
- static List *MergeAttributes(List *schema, List *supers, char relpersistence,
353
+ static List *MergeAttributes(List *columns, const List *supers, char relpersistence,
354
354
bool is_partition, List **supconstr,
355
355
List **supnotnulls);
356
356
static List *MergeCheckConstraint(List *constraints, const char *name, Node *expr);
@@ -361,7 +361,7 @@ static void StoreCatalogInheritance(Oid relationId, List *supers,
361
361
static void StoreCatalogInheritance1(Oid relationId, Oid parentOid,
362
362
int32 seqNumber, Relation inhRelation,
363
363
bool child_is_partition);
364
- static int findAttrByName(const char *attributeName, List *schema );
364
+ static int findAttrByName(const char *attributeName, const List *columns );
365
365
static void AlterIndexNamespaces(Relation classRel, Relation rel,
366
366
Oid oldNspOid, Oid newNspOid, ObjectAddresses *objsMoved);
367
367
static void AlterSeqNamespaces(Relation classRel, Relation rel,
@@ -2307,7 +2307,7 @@ storage_name(char c)
2307
2307
* Returns new schema given initial schema and superclasses.
2308
2308
*
2309
2309
* Input arguments:
2310
- * 'schema ' is the column/attribute definition for the table. (It's a list
2310
+ * 'columns ' is the column/attribute definition for the table. (It's a list
2311
2311
* of ColumnDef's.) It is destructively changed.
2312
2312
* 'supers' is a list of OIDs of parent relations, already locked by caller.
2313
2313
* 'relpersistence' is the persistence type of the table.
@@ -2369,17 +2369,17 @@ storage_name(char c)
2369
2369
*----------
2370
2370
*/
2371
2371
static List *
2372
- MergeAttributes(List *schema, List *supers, char relpersistence,
2372
+ MergeAttributes(List *columns, const List *supers, char relpersistence,
2373
2373
bool is_partition, List **supconstr, List **supnotnulls)
2374
2374
{
2375
- List *inhSchema = NIL;
2375
+ List *inh_columns = NIL;
2376
2376
List *constraints = NIL;
2377
2377
List *nnconstraints = NIL;
2378
2378
bool have_bogus_defaults = false;
2379
2379
int child_attno;
2380
2380
static Node bogus_marker = {0}; /* marks conflicting defaults */
2381
- List *saved_schema = NIL;
2382
- ListCell *entry ;
2381
+ List *saved_columns = NIL;
2382
+ ListCell *lc ;
2383
2383
2384
2384
/*
2385
2385
* Check for and reject tables with too many columns. We perform this
@@ -2392,7 +2392,7 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
2392
2392
* Note that we also need to check that we do not exceed this figure after
2393
2393
* including columns from inherited relations.
2394
2394
*/
2395
- if (list_length(schema ) > MaxHeapAttributeNumber)
2395
+ if (list_length(columns ) > MaxHeapAttributeNumber)
2396
2396
ereport(ERROR,
2397
2397
(errcode(ERRCODE_TOO_MANY_COLUMNS),
2398
2398
errmsg("tables can have at most %d columns",
@@ -2406,15 +2406,15 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
2406
2406
* sense to assume such conflicts are errors.
2407
2407
*
2408
2408
* We don't use foreach() here because we have two nested loops over the
2409
- * schema list, with possible element deletions in the inner one. If we
2409
+ * columns list, with possible element deletions in the inner one. If we
2410
2410
* used foreach_delete_current() it could only fix up the state of one of
2411
2411
* the loops, so it seems cleaner to use looping over list indexes for
2412
2412
* both loops. Note that any deletion will happen beyond where the outer
2413
2413
* loop is, so its index never needs adjustment.
2414
2414
*/
2415
- for (int coldefpos = 0; coldefpos < list_length(schema ); coldefpos++)
2415
+ for (int coldefpos = 0; coldefpos < list_length(columns ); coldefpos++)
2416
2416
{
2417
- ColumnDef *coldef = list_nth_node(ColumnDef, schema , coldefpos);
2417
+ ColumnDef *coldef = list_nth_node(ColumnDef, columns , coldefpos);
2418
2418
2419
2419
if (!is_partition && coldef->typeName == NULL)
2420
2420
{
@@ -2431,9 +2431,9 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
2431
2431
}
2432
2432
2433
2433
/* restpos scans all entries beyond coldef; incr is in loop body */
2434
- for (int restpos = coldefpos + 1; restpos < list_length(schema );)
2434
+ for (int restpos = coldefpos + 1; restpos < list_length(columns );)
2435
2435
{
2436
- ColumnDef *restdef = list_nth_node(ColumnDef, schema , restpos);
2436
+ ColumnDef *restdef = list_nth_node(ColumnDef, columns , restpos);
2437
2437
2438
2438
if (strcmp(coldef->colname, restdef->colname) == 0)
2439
2439
{
@@ -2447,7 +2447,7 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
2447
2447
coldef->cooked_default = restdef->cooked_default;
2448
2448
coldef->constraints = restdef->constraints;
2449
2449
coldef->is_from_type = false;
2450
- schema = list_delete_nth_cell(schema , restpos);
2450
+ columns = list_delete_nth_cell(columns , restpos);
2451
2451
}
2452
2452
else
2453
2453
ereport(ERROR,
@@ -2467,26 +2467,25 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
2467
2467
*/
2468
2468
if (is_partition)
2469
2469
{
2470
- saved_schema = schema ;
2471
- schema = NIL;
2470
+ saved_columns = columns ;
2471
+ columns = NIL;
2472
2472
}
2473
2473
2474
2474
/*
2475
2475
* Scan the parents left-to-right, and merge their attributes to form a
2476
- * list of inherited attributes (inhSchema ).
2476
+ * list of inherited columns (inh_columns ).
2477
2477
*/
2478
2478
child_attno = 0;
2479
- foreach(entry , supers)
2479
+ foreach(lc , supers)
2480
2480
{
2481
- Oid parent = lfirst_oid(entry );
2481
+ Oid parent = lfirst_oid(lc );
2482
2482
Relation relation;
2483
2483
TupleDesc tupleDesc;
2484
2484
TupleConstr *constr;
2485
2485
AttrMap *newattmap;
2486
2486
List *inherited_defaults;
2487
2487
List *cols_with_defaults;
2488
2488
List *nnconstrs;
2489
- AttrNumber parent_attno;
2490
2489
ListCell *lc1;
2491
2490
ListCell *lc2;
2492
2491
Bitmapset *pkattrs;
@@ -2507,8 +2506,7 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
2507
2506
* We do not allow partitioned tables and partitions to participate in
2508
2507
* regular inheritance.
2509
2508
*/
2510
- if (relation->rd_rel->relkind == RELKIND_PARTITIONED_TABLE &&
2511
- !is_partition)
2509
+ if (relation->rd_rel->relkind == RELKIND_PARTITIONED_TABLE && !is_partition)
2512
2510
ereport(ERROR,
2513
2511
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
2514
2512
errmsg("cannot inherit from partitioned table \"%s\"",
@@ -2593,7 +2591,7 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
2593
2591
nncols = bms_add_member(nncols,
2594
2592
((CookedConstraint *) lfirst(lc1))->attnum);
2595
2593
2596
- for (parent_attno = 1; parent_attno <= tupleDesc->natts;
2594
+ for (AttrNumber parent_attno = 1; parent_attno <= tupleDesc->natts;
2597
2595
parent_attno++)
2598
2596
{
2599
2597
Form_pg_attribute attribute = TupleDescAttr(tupleDesc,
@@ -2611,7 +2609,7 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
2611
2609
/*
2612
2610
* Does it conflict with some previously inherited column?
2613
2611
*/
2614
- exist_attno = findAttrByName(attributeName, inhSchema );
2612
+ exist_attno = findAttrByName(attributeName, inh_columns );
2615
2613
if (exist_attno > 0)
2616
2614
{
2617
2615
Oid defTypeId;
@@ -2624,7 +2622,7 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
2624
2622
ereport(NOTICE,
2625
2623
(errmsg("merging multiple inherited definitions of column \"%s\"",
2626
2624
attributeName)));
2627
- def = (ColumnDef *) list_nth(inhSchema , exist_attno - 1);
2625
+ def = (ColumnDef *) list_nth(inh_columns , exist_attno - 1);
2628
2626
2629
2627
/*
2630
2628
* Must have the same type and typmod
@@ -2761,7 +2759,7 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
2761
2759
if (CompressionMethodIsValid(attribute->attcompression))
2762
2760
def->compression =
2763
2761
pstrdup(GetCompressionMethodName(attribute->attcompression));
2764
- inhSchema = lappend(inhSchema , def);
2762
+ inh_columns = lappend(inh_columns , def);
2765
2763
newattmap->attnums[parent_attno - 1] = ++child_attno;
2766
2764
2767
2765
/*
@@ -2862,7 +2860,7 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
2862
2860
* If we already had a default from some prior parent, check to
2863
2861
* see if they are the same. If so, no problem; if not, mark the
2864
2862
* column as having a bogus default. Below, we will complain if
2865
- * the bogus default isn't overridden by the child schema .
2863
+ * the bogus default isn't overridden by the child columns .
2866
2864
*/
2867
2865
Assert(def->raw_default == NULL);
2868
2866
if (def->cooked_default == NULL)
@@ -2882,9 +2880,8 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
2882
2880
if (constr && constr->num_check > 0)
2883
2881
{
2884
2882
ConstrCheck *check = constr->check;
2885
- int i;
2886
2883
2887
- for (i = 0; i < constr->num_check; i++)
2884
+ for (int i = 0; i < constr->num_check; i++)
2888
2885
{
2889
2886
char *name = check[i].ccname;
2890
2887
Node *expr;
@@ -2945,27 +2942,27 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
2945
2942
}
2946
2943
2947
2944
/*
2948
- * If we had no inherited attributes, the result schema is just the
2945
+ * If we had no inherited attributes, the result columns are just the
2949
2946
* explicitly declared columns. Otherwise, we need to merge the declared
2950
- * columns into the inherited schema list. Although, we never have any
2947
+ * columns into the inherited column list. Although, we never have any
2951
2948
* explicitly declared columns if the table is a partition.
2952
2949
*/
2953
- if (inhSchema != NIL)
2950
+ if (inh_columns != NIL)
2954
2951
{
2955
- int schema_attno = 0;
2952
+ int newcol_attno = 0;
2956
2953
2957
- foreach(entry, schema )
2954
+ foreach(lc, columns )
2958
2955
{
2959
- ColumnDef *newdef = lfirst(entry );
2956
+ ColumnDef *newdef = lfirst(lc );
2960
2957
char *attributeName = newdef->colname;
2961
2958
int exist_attno;
2962
2959
2963
- schema_attno ++;
2960
+ newcol_attno ++;
2964
2961
2965
2962
/*
2966
2963
* Does it conflict with some previously inherited column?
2967
2964
*/
2968
- exist_attno = findAttrByName(attributeName, inhSchema );
2965
+ exist_attno = findAttrByName(attributeName, inh_columns );
2969
2966
if (exist_attno > 0)
2970
2967
{
2971
2968
ColumnDef *def;
@@ -2985,15 +2982,15 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
2985
2982
/*
2986
2983
* Yes, try to merge the two column definitions.
2987
2984
*/
2988
- if (exist_attno == schema_attno )
2985
+ if (exist_attno == newcol_attno )
2989
2986
ereport(NOTICE,
2990
2987
(errmsg("merging column \"%s\" with inherited definition",
2991
2988
attributeName)));
2992
2989
else
2993
2990
ereport(NOTICE,
2994
2991
(errmsg("moving and merging column \"%s\" with inherited definition", attributeName),
2995
2992
errdetail("User-specified column moved to the position of the inherited column.")));
2996
- def = (ColumnDef *) list_nth(inhSchema , exist_attno - 1);
2993
+ def = (ColumnDef *) list_nth(inh_columns , exist_attno - 1);
2997
2994
2998
2995
/*
2999
2996
* Must have the same type and typmod
@@ -3118,19 +3115,19 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
3118
3115
else
3119
3116
{
3120
3117
/*
3121
- * No, attach new column to result schema
3118
+ * No, attach new column to result columns
3122
3119
*/
3123
- inhSchema = lappend(inhSchema , newdef);
3120
+ inh_columns = lappend(inh_columns , newdef);
3124
3121
}
3125
3122
}
3126
3123
3127
- schema = inhSchema ;
3124
+ columns = inh_columns ;
3128
3125
3129
3126
/*
3130
3127
* Check that we haven't exceeded the legal # of columns after merging
3131
3128
* in inherited columns.
3132
3129
*/
3133
- if (list_length(schema ) > MaxHeapAttributeNumber)
3130
+ if (list_length(columns ) > MaxHeapAttributeNumber)
3134
3131
ereport(ERROR,
3135
3132
(errcode(ERRCODE_TOO_MANY_COLUMNS),
3136
3133
errmsg("tables can have at most %d columns",
@@ -3144,13 +3141,13 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
3144
3141
*/
3145
3142
if (is_partition)
3146
3143
{
3147
- foreach(entry, saved_schema )
3144
+ foreach(lc, saved_columns )
3148
3145
{
3149
- ColumnDef *restdef = lfirst(entry );
3146
+ ColumnDef *restdef = lfirst(lc );
3150
3147
bool found = false;
3151
3148
ListCell *l;
3152
3149
3153
- foreach(l, schema )
3150
+ foreach(l, columns )
3154
3151
{
3155
3152
ColumnDef *coldef = lfirst(l);
3156
3153
@@ -3222,9 +3219,9 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
3222
3219
*/
3223
3220
if (have_bogus_defaults)
3224
3221
{
3225
- foreach(entry, schema )
3222
+ foreach(lc, columns )
3226
3223
{
3227
- ColumnDef *def = lfirst(entry );
3224
+ ColumnDef *def = lfirst(lc );
3228
3225
3229
3226
if (def->cooked_default == &bogus_marker)
3230
3227
{
@@ -3247,7 +3244,7 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
3247
3244
*supconstr = constraints;
3248
3245
*supnotnulls = nnconstraints;
3249
3246
3250
- return schema ;
3247
+ return columns ;
3251
3248
}
3252
3249
3253
3250
@@ -3402,22 +3399,20 @@ StoreCatalogInheritance1(Oid relationId, Oid parentOid,
3402
3399
}
3403
3400
3404
3401
/*
3405
- * Look for an existing schema entry with the given name.
3402
+ * Look for an existing column entry with the given name.
3406
3403
*
3407
- * Returns the index (starting with 1) if attribute already exists in schema ,
3404
+ * Returns the index (starting with 1) if attribute already exists in columns ,
3408
3405
* 0 if it doesn't.
3409
3406
*/
3410
3407
static int
3411
- findAttrByName(const char *attributeName, List *schema )
3408
+ findAttrByName(const char *attributeName, const List *columns )
3412
3409
{
3413
- ListCell *s ;
3410
+ ListCell *lc ;
3414
3411
int i = 1;
3415
3412
3416
- foreach(s, schema )
3413
+ foreach(lc, columns )
3417
3414
{
3418
- ColumnDef *def = lfirst(s);
3419
-
3420
- if (strcmp(attributeName, def->colname) == 0)
3415
+ if (strcmp(attributeName, lfirst_node(ColumnDef, lc)->colname) == 0)
3421
3416
return i;
3422
3417
3423
3418
i++;
0 commit comments