@@ -350,7 +350,7 @@ static void truncate_check_perms(Oid relid, Form_pg_class reltuple);
350350static void truncate_check_activity(Relation rel);
351351static void RangeVarCallbackForTruncate(const RangeVar *relation,
352352 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,
354354 bool is_partition, List **supconstr,
355355 List **supnotnulls);
356356static List *MergeCheckConstraint(List *constraints, const char *name, Node *expr);
@@ -361,7 +361,7 @@ static void StoreCatalogInheritance(Oid relationId, List *supers,
361361static void StoreCatalogInheritance1(Oid relationId, Oid parentOid,
362362 int32 seqNumber, Relation inhRelation,
363363 bool child_is_partition);
364- static int findAttrByName(const char *attributeName, List *schema );
364+ static int findAttrByName(const char *attributeName, const List *columns );
365365static void AlterIndexNamespaces(Relation classRel, Relation rel,
366366 Oid oldNspOid, Oid newNspOid, ObjectAddresses *objsMoved);
367367static void AlterSeqNamespaces(Relation classRel, Relation rel,
@@ -2307,7 +2307,7 @@ storage_name(char c)
23072307 * Returns new schema given initial schema and superclasses.
23082308 *
23092309 * 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
23112311 * of ColumnDef's.) It is destructively changed.
23122312 * 'supers' is a list of OIDs of parent relations, already locked by caller.
23132313 * 'relpersistence' is the persistence type of the table.
@@ -2369,17 +2369,17 @@ storage_name(char c)
23692369 *----------
23702370 */
23712371static List *
2372- MergeAttributes(List *schema, List *supers, char relpersistence,
2372+ MergeAttributes(List *columns, const List *supers, char relpersistence,
23732373 bool is_partition, List **supconstr, List **supnotnulls)
23742374{
2375- List *inhSchema = NIL;
2375+ List *inh_columns = NIL;
23762376 List *constraints = NIL;
23772377 List *nnconstraints = NIL;
23782378 bool have_bogus_defaults = false;
23792379 int child_attno;
23802380 static Node bogus_marker = {0}; /* marks conflicting defaults */
2381- List *saved_schema = NIL;
2382- ListCell *entry ;
2381+ List *saved_columns = NIL;
2382+ ListCell *lc ;
23832383
23842384 /*
23852385 * Check for and reject tables with too many columns. We perform this
@@ -2392,7 +2392,7 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
23922392 * Note that we also need to check that we do not exceed this figure after
23932393 * including columns from inherited relations.
23942394 */
2395- if (list_length(schema ) > MaxHeapAttributeNumber)
2395+ if (list_length(columns ) > MaxHeapAttributeNumber)
23962396 ereport(ERROR,
23972397 (errcode(ERRCODE_TOO_MANY_COLUMNS),
23982398 errmsg("tables can have at most %d columns",
@@ -2406,15 +2406,15 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
24062406 * sense to assume such conflicts are errors.
24072407 *
24082408 * 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
24102410 * used foreach_delete_current() it could only fix up the state of one of
24112411 * the loops, so it seems cleaner to use looping over list indexes for
24122412 * both loops. Note that any deletion will happen beyond where the outer
24132413 * loop is, so its index never needs adjustment.
24142414 */
2415- for (int coldefpos = 0; coldefpos < list_length(schema ); coldefpos++)
2415+ for (int coldefpos = 0; coldefpos < list_length(columns ); coldefpos++)
24162416 {
2417- ColumnDef *coldef = list_nth_node(ColumnDef, schema , coldefpos);
2417+ ColumnDef *coldef = list_nth_node(ColumnDef, columns , coldefpos);
24182418
24192419 if (!is_partition && coldef->typeName == NULL)
24202420 {
@@ -2431,9 +2431,9 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
24312431 }
24322432
24332433 /* 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 );)
24352435 {
2436- ColumnDef *restdef = list_nth_node(ColumnDef, schema , restpos);
2436+ ColumnDef *restdef = list_nth_node(ColumnDef, columns , restpos);
24372437
24382438 if (strcmp(coldef->colname, restdef->colname) == 0)
24392439 {
@@ -2447,7 +2447,7 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
24472447 coldef->cooked_default = restdef->cooked_default;
24482448 coldef->constraints = restdef->constraints;
24492449 coldef->is_from_type = false;
2450- schema = list_delete_nth_cell(schema , restpos);
2450+ columns = list_delete_nth_cell(columns , restpos);
24512451 }
24522452 else
24532453 ereport(ERROR,
@@ -2467,26 +2467,25 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
24672467 */
24682468 if (is_partition)
24692469 {
2470- saved_schema = schema ;
2471- schema = NIL;
2470+ saved_columns = columns ;
2471+ columns = NIL;
24722472 }
24732473
24742474 /*
24752475 * 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 ).
24772477 */
24782478 child_attno = 0;
2479- foreach(entry , supers)
2479+ foreach(lc , supers)
24802480 {
2481- Oid parent = lfirst_oid(entry );
2481+ Oid parent = lfirst_oid(lc );
24822482 Relation relation;
24832483 TupleDesc tupleDesc;
24842484 TupleConstr *constr;
24852485 AttrMap *newattmap;
24862486 List *inherited_defaults;
24872487 List *cols_with_defaults;
24882488 List *nnconstrs;
2489- AttrNumber parent_attno;
24902489 ListCell *lc1;
24912490 ListCell *lc2;
24922491 Bitmapset *pkattrs;
@@ -2507,8 +2506,7 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
25072506 * We do not allow partitioned tables and partitions to participate in
25082507 * regular inheritance.
25092508 */
2510- if (relation->rd_rel->relkind == RELKIND_PARTITIONED_TABLE &&
2511- !is_partition)
2509+ if (relation->rd_rel->relkind == RELKIND_PARTITIONED_TABLE && !is_partition)
25122510 ereport(ERROR,
25132511 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
25142512 errmsg("cannot inherit from partitioned table \"%s\"",
@@ -2593,7 +2591,7 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
25932591 nncols = bms_add_member(nncols,
25942592 ((CookedConstraint *) lfirst(lc1))->attnum);
25952593
2596- for (parent_attno = 1; parent_attno <= tupleDesc->natts;
2594+ for (AttrNumber parent_attno = 1; parent_attno <= tupleDesc->natts;
25972595 parent_attno++)
25982596 {
25992597 Form_pg_attribute attribute = TupleDescAttr(tupleDesc,
@@ -2611,7 +2609,7 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
26112609 /*
26122610 * Does it conflict with some previously inherited column?
26132611 */
2614- exist_attno = findAttrByName(attributeName, inhSchema );
2612+ exist_attno = findAttrByName(attributeName, inh_columns );
26152613 if (exist_attno > 0)
26162614 {
26172615 Oid defTypeId;
@@ -2624,7 +2622,7 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
26242622 ereport(NOTICE,
26252623 (errmsg("merging multiple inherited definitions of column \"%s\"",
26262624 attributeName)));
2627- def = (ColumnDef *) list_nth(inhSchema , exist_attno - 1);
2625+ def = (ColumnDef *) list_nth(inh_columns , exist_attno - 1);
26282626
26292627 /*
26302628 * Must have the same type and typmod
@@ -2761,7 +2759,7 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
27612759 if (CompressionMethodIsValid(attribute->attcompression))
27622760 def->compression =
27632761 pstrdup(GetCompressionMethodName(attribute->attcompression));
2764- inhSchema = lappend(inhSchema , def);
2762+ inh_columns = lappend(inh_columns , def);
27652763 newattmap->attnums[parent_attno - 1] = ++child_attno;
27662764
27672765 /*
@@ -2862,7 +2860,7 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
28622860 * If we already had a default from some prior parent, check to
28632861 * see if they are the same. If so, no problem; if not, mark the
28642862 * 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 .
28662864 */
28672865 Assert(def->raw_default == NULL);
28682866 if (def->cooked_default == NULL)
@@ -2882,9 +2880,8 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
28822880 if (constr && constr->num_check > 0)
28832881 {
28842882 ConstrCheck *check = constr->check;
2885- int i;
28862883
2887- for (i = 0; i < constr->num_check; i++)
2884+ for (int i = 0; i < constr->num_check; i++)
28882885 {
28892886 char *name = check[i].ccname;
28902887 Node *expr;
@@ -2945,27 +2942,27 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
29452942 }
29462943
29472944 /*
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
29492946 * 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
29512948 * explicitly declared columns if the table is a partition.
29522949 */
2953- if (inhSchema != NIL)
2950+ if (inh_columns != NIL)
29542951 {
2955- int schema_attno = 0;
2952+ int newcol_attno = 0;
29562953
2957- foreach(entry, schema )
2954+ foreach(lc, columns )
29582955 {
2959- ColumnDef *newdef = lfirst(entry );
2956+ ColumnDef *newdef = lfirst(lc );
29602957 char *attributeName = newdef->colname;
29612958 int exist_attno;
29622959
2963- schema_attno ++;
2960+ newcol_attno ++;
29642961
29652962 /*
29662963 * Does it conflict with some previously inherited column?
29672964 */
2968- exist_attno = findAttrByName(attributeName, inhSchema );
2965+ exist_attno = findAttrByName(attributeName, inh_columns );
29692966 if (exist_attno > 0)
29702967 {
29712968 ColumnDef *def;
@@ -2985,15 +2982,15 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
29852982 /*
29862983 * Yes, try to merge the two column definitions.
29872984 */
2988- if (exist_attno == schema_attno )
2985+ if (exist_attno == newcol_attno )
29892986 ereport(NOTICE,
29902987 (errmsg("merging column \"%s\" with inherited definition",
29912988 attributeName)));
29922989 else
29932990 ereport(NOTICE,
29942991 (errmsg("moving and merging column \"%s\" with inherited definition", attributeName),
29952992 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);
29972994
29982995 /*
29992996 * Must have the same type and typmod
@@ -3118,19 +3115,19 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
31183115 else
31193116 {
31203117 /*
3121- * No, attach new column to result schema
3118+ * No, attach new column to result columns
31223119 */
3123- inhSchema = lappend(inhSchema , newdef);
3120+ inh_columns = lappend(inh_columns , newdef);
31243121 }
31253122 }
31263123
3127- schema = inhSchema ;
3124+ columns = inh_columns ;
31283125
31293126 /*
31303127 * Check that we haven't exceeded the legal # of columns after merging
31313128 * in inherited columns.
31323129 */
3133- if (list_length(schema ) > MaxHeapAttributeNumber)
3130+ if (list_length(columns ) > MaxHeapAttributeNumber)
31343131 ereport(ERROR,
31353132 (errcode(ERRCODE_TOO_MANY_COLUMNS),
31363133 errmsg("tables can have at most %d columns",
@@ -3144,13 +3141,13 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
31443141 */
31453142 if (is_partition)
31463143 {
3147- foreach(entry, saved_schema )
3144+ foreach(lc, saved_columns )
31483145 {
3149- ColumnDef *restdef = lfirst(entry );
3146+ ColumnDef *restdef = lfirst(lc );
31503147 bool found = false;
31513148 ListCell *l;
31523149
3153- foreach(l, schema )
3150+ foreach(l, columns )
31543151 {
31553152 ColumnDef *coldef = lfirst(l);
31563153
@@ -3222,9 +3219,9 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
32223219 */
32233220 if (have_bogus_defaults)
32243221 {
3225- foreach(entry, schema )
3222+ foreach(lc, columns )
32263223 {
3227- ColumnDef *def = lfirst(entry );
3224+ ColumnDef *def = lfirst(lc );
32283225
32293226 if (def->cooked_default == &bogus_marker)
32303227 {
@@ -3247,7 +3244,7 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
32473244 *supconstr = constraints;
32483245 *supnotnulls = nnconstraints;
32493246
3250- return schema ;
3247+ return columns ;
32513248}
32523249
32533250
@@ -3402,22 +3399,20 @@ StoreCatalogInheritance1(Oid relationId, Oid parentOid,
34023399}
34033400
34043401/*
3405- * Look for an existing schema entry with the given name.
3402+ * Look for an existing column entry with the given name.
34063403 *
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 ,
34083405 * 0 if it doesn't.
34093406 */
34103407static int
3411- findAttrByName(const char *attributeName, List *schema )
3408+ findAttrByName(const char *attributeName, const List *columns )
34123409{
3413- ListCell *s ;
3410+ ListCell *lc ;
34143411 int i = 1;
34153412
3416- foreach(s, schema )
3413+ foreach(lc, columns )
34173414 {
3418- ColumnDef *def = lfirst(s);
3419-
3420- if (strcmp(attributeName, def->colname) == 0)
3415+ if (strcmp(attributeName, lfirst_node(ColumnDef, lc)->colname) == 0)
34213416 return i;
34223417
34233418 i++;
0 commit comments