pgsql: Simplify some logic around setting pg_attribute.atthasdef.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Simplify some logic around setting pg_attribute.atthasdef.
Date: 2025-03-03 18:35:58
Message-ID: E1tpAdy-000cdw-0v@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(dot)universality(at)gmail(dot)com>
Discussion: https://postgr.es/m/CACJufxHFssPvkP1we7WMhPD_1kwgbG52o=kQgL+TnVoX5LOyCQ@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/35c8dd9e1176ae0c3cb060b0da9cb2bba925363c

Modified Files
--------------
src/backend/catalog/pg_attrdef.c | 20 +++++++++-----------
src/backend/commands/tablecmds.c | 14 +-------------
2 files changed, 10 insertions(+), 24 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Melanie Plageman 2025-03-03 19:45:31 pgsql: Trigger more frequent autovacuums with relallfrozen
Previous Message Andres Freund 2025-03-03 18:02:35 Re: pgsql: Set amcancrosscompare to true for hash