Simplify some logic around setting pg_attribute.atthasdef.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 3 Mar 2025 18:35:48 +0000 (13:35 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 3 Mar 2025 18:35:48 +0000 (13:35 -0500)
commit35c8dd9e1176ae0c3cb060b0da9cb2bba925363c
tree38acfc9333224ef84b6a1329bcf24751d5232d17
parent4528768d98f83070d625207dcb526982fb18f1ce
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
src/backend/catalog/pg_attrdef.c
src/backend/commands/tablecmds.c