diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2025-03-03 13:35:48 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2025-03-03 13:35:48 -0500 |
commit | 35c8dd9e1176ae0c3cb060b0da9cb2bba925363c (patch) | |
tree | 38acfc9333224ef84b6a1329bcf24751d5232d17 /src/backend/commands/tablecmds.c | |
parent | 4528768d98f83070d625207dcb526982fb18f1ce (diff) | |
download | postgresql-35c8dd9e1176ae0c3cb060b0da9cb2bba925363c.tar.gz postgresql-35c8dd9e1176ae0c3cb060b0da9cb2bba925363c.zip |
Simplify some logic around setting pg_attribute.atthasdef.
DefineRelation was of the opinion that it could usefully pre-fill
atthasdef flags to eliminate work for StoreAttrDefault. This is not
the case, however: the tupledesc that it's filling is not the one that
InsertPgAttributeTuples will work from. The tupledesc used there is
made by RelationBuildLocalRelation, which deliberately doesn't copy
atthasdef. Moreover, if this did happen as the code thinks, it would
be wrong for the case of plain "DEFAULT NULL" clauses, since we detect
and ignore simple-null-Const defaults later on. Hence, remove the
useless code.
It also emerges that it's not really worth a special-case path in
StoreAttrDefault() for atthasdef already being set, because as far as
we can see that never happens: cases where an existing default gets
updated always do RemoveAttrDefault first, so as to clean up
possibly-no-longer-correct dependency entries. If it were the case
the code would still work, anyway.
Also remove a nearby comment made moot by 5eaa0e92e.
Author: jian he <jian.universality@gmail.com>
Discussion: https://postgr.es/m/CACJufxHFssPvkP1we7WMhPD_1kwgbG52o=kQgL+TnVoX5LOyCQ@mail.gmail.com
Diffstat (limited to 'src/backend/commands/tablecmds.c')
-rw-r--r-- | src/backend/commands/tablecmds.c | 14 |
1 files changed, 1 insertions, 13 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 7b7b09baaa8..13156391241 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -941,10 +941,6 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId, * while raw defaults go into a list of RawColumnDefault structs that will * be processed by AddRelationNewConstraints. (We can't deal with raw * expressions until we can do transformExpr.) - * - * We can set the atthasdef flags now in the tuple descriptor; this just - * saves StoreAttrDefault from having to do an immediate update of the - * pg_attribute rows. */ rawDefaults = NIL; cookedDefaults = NIL; @@ -953,11 +949,8 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId, foreach(listptr, stmt->tableElts) { ColumnDef *colDef = lfirst(listptr); - Form_pg_attribute attr; attnum++; - attr = TupleDescAttr(descriptor, attnum - 1); - if (colDef->raw_default != NULL) { RawColumnDefault *rawEnt; @@ -969,7 +962,6 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId, rawEnt->raw_default = colDef->raw_default; rawEnt->generated = colDef->generated; rawDefaults = lappend(rawDefaults, rawEnt); - attr->atthasdef = true; } else if (colDef->cooked_default != NULL) { @@ -987,10 +979,7 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId, cooked->inhcount = 0; /* ditto */ cooked->is_no_inherit = false; cookedDefaults = lappend(cookedDefaults, cooked); - attr->atthasdef = true; } - - populate_compact_attribute(descriptor, attnum - 1); } /* @@ -7363,8 +7352,7 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel, * and the later subcommands had been issued in new ALTER TABLE commands. * * We can skip this entirely for relations without storage, since Phase 3 - * is certainly not going to touch them. System attributes don't have - * interesting defaults, either. + * is certainly not going to touch them. */ if (RELKIND_HAS_STORAGE(relkind)) { |