@@ -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,
352352Oid 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 intfindAttrByName(const char *attributeName, List *schema );
364+ static intfindAttrByName(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,
23732373bool is_partition, List **supconstr, List **supnotnulls)
23742374{
2375- List *inhSchema = NIL;
2375+ List *inh_columns = NIL;
23762376List *constraints = NIL;
23772377List *nnconstraints = NIL;
23782378boolhave_bogus_defaults = false;
23792379intchild_attno;
23802380static 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)
23962396ereport(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
24192419if (!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
24382438if (strcmp(coldef->colname, restdef->colname) == 0)
24392439{
@@ -2447,7 +2447,7 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
24472447coldef->cooked_default = restdef->cooked_default;
24482448coldef->constraints = restdef->constraints;
24492449coldef->is_from_type = false;
2450- schema = list_delete_nth_cell(schema , restpos);
2450+ columns = list_delete_nth_cell(columns , restpos);
24512451}
24522452else
24532453ereport(ERROR,
@@ -2467,26 +2467,25 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
24672467 */
24682468if (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 inheritedattributes (inhSchema ).
2476+ * list of inheritedcolumns (inh_columns ).
24772477 */
24782478child_attno = 0;
2479- foreach(entry , supers)
2479+ foreach(lc , supers)
24802480{
2481- Oidparent = lfirst_oid(entry );
2481+ Oidparent = lfirst_oid(lc );
24822482Relationrelation;
24832483TupleDesctupleDesc;
24842484TupleConstr *constr;
24852485AttrMap *newattmap;
24862486List *inherited_defaults;
24872487List *cols_with_defaults;
24882488List *nnconstrs;
2489- AttrNumberparent_attno;
24902489ListCell *lc1;
24912490ListCell *lc2;
24922491Bitmapset *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)
25122510ereport(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,
25932591nncols = 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{
25992597Form_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 );
26152613if (exist_attno > 0)
26162614{
26172615OiddefTypeId;
@@ -2624,7 +2622,7 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
26242622ereport(NOTICE,
26252623(errmsg("merging multiple inherited definitions of column \"%s\"",
26262624attributeName)));
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,
27612759if (CompressionMethodIsValid(attribute->attcompression))
27622760def->compression =
27632761pstrdup(GetCompressionMethodName(attribute->attcompression));
2764- inhSchema = lappend(inhSchema , def);
2762+ inh_columns = lappend(inh_columns , def);
27652763newattmap->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 childschema .
2863+ * the bogus default isn't overridden by the childcolumns .
28662864 */
28672865Assert(def->raw_default == NULL);
28682866if (def->cooked_default == NULL)
@@ -2882,9 +2880,8 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
28822880if (constr && constr->num_check > 0)
28832881{
28842882ConstrCheck *check = constr->check;
2885- inti;
28862883
2887- for (i = 0; i < constr->num_check; i++)
2884+ for (int i = 0; i < constr->num_check; i++)
28882885{
28892886char *name = check[i].ccname;
28902887Node *expr;
@@ -2945,27 +2942,27 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
29452942}
29462943
29472944/*
2948- * If we had no inherited attributes, the resultschema is just the
2945+ * If we had no inherited attributes, the resultcolumns are just the
29492946 * explicitly declared columns. Otherwise, we need to merge the declared
2950- * columns into the inheritedschema list. Although, we never have any
2947+ * columns into the inheritedcolumn 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- intschema_attno = 0;
2952+ intnewcol_attno = 0;
29562953
2957- foreach(entry, schema )
2954+ foreach(lc, columns )
29582955{
2959- ColumnDef *newdef = lfirst(entry );
2956+ ColumnDef *newdef = lfirst(lc );
29602957char *attributeName = newdef->colname;
29612958intexist_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 );
29692966if (exist_attno > 0)
29702967{
29712968ColumnDef *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 )
29892986ereport(NOTICE,
29902987(errmsg("merging column \"%s\" with inherited definition",
29912988attributeName)));
29922989else
29932990ereport(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,
31183115else
31193116{
31203117/*
3121- * No, attach new column to resultschema
3118+ * No, attach new column to resultcolumns
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)
31343131ereport(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 */
31453142if (is_partition)
31463143{
3147- foreach(entry, saved_schema )
3144+ foreach(lc, saved_columns )
31483145{
3149- ColumnDef *restdef = lfirst(entry );
3146+ ColumnDef *restdef = lfirst(lc );
31503147boolfound = false;
31513148ListCell *l;
31523149
3153- foreach(l,schema )
3150+ foreach(l,columns )
31543151{
31553152ColumnDef *coldef = lfirst(l);
31563153
@@ -3222,9 +3219,9 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
32223219 */
32233220if (have_bogus_defaults)
32243221{
3225- foreach(entry, schema )
3222+ foreach(lc, columns )
32263223{
3227- ColumnDef *def = lfirst(entry );
3224+ ColumnDef *def = lfirst(lc );
32283225
32293226if (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- returnschema ;
3247+ returncolumns ;
32513248}
32523249
32533250
@@ -3402,22 +3399,20 @@ StoreCatalogInheritance1(Oid relationId, Oid parentOid,
34023399}
34033400
34043401/*
3405- * Look for an existingschema entry with the given name.
3402+ * Look for an existingcolumn entry with the given name.
34063403 *
3407- * Returns the index (starting with 1) if attribute already exists inschema ,
3404+ * Returns the index (starting with 1) if attribute already exists incolumns ,
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 ;
34143411inti = 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)
34213416return i;
34223417
34233418i++;