Re: bug when apply fast default mechanism for adding new column over domain with default value

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: bug when apply fast default mechanism for adding new column over domain with default value
Date: 2025-03-03 14:20:21
Message-ID: CACJufxFV5WssyAmh98LAXbjrzfUShMpouDzdhrXZkq2W8y9+Zw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Mar 3, 2025 at 4:45 PM jian he <jian(dot)universality(at)gmail(dot)com> wrote:
>
> looking at DefineRelation comments:
> * 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.
> this seems not right?
> DefineRelation->heap_create_with_catalog->heap_create->RelationBuildLocalRelation->CreateTupleDescCopy
> don't copy atthasdef.
> RelationBuildLocalRelation later didn't touch atthasdef.
> populate_compact_attribute didn't touch atthasdef.
> so StoreAttrDefault has to update that pg_attribute row.
>
CREATE TABLE (COLUMN x DEFAULT y):
for each (Relation rel, AttrNumber attnum), we can enter StoreAttrDefault once.
Also for the above quoted reason,
in DefineRelation, we didn't change pg_attribute.atthasdef before
entering StoreAttrDefault.

ALTER TABLE ALTER COLUMN SET/DROP DEFAULT:
in ATExecColumnDefault will first do RemoveAttrDefault, then re add
the default expression.
In this case, in StoreAttrDefault: attStruct->atthasdef will be false.

overall, i think DefineRelation about StoreAttrDefault comments can be removed.
and StoreAttrDefault, "if (!attStruct->atthasdef)" part logic can also
be changed.

The attached is the minor change I came up with, based on v3-0001 and v3-0002.

Attachment Content-Type Size
v3-0001-minor-refactoring-DefineRelation-StoreAttrDefa.no-cfbot application/octet-stream 3.7 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Melanie Plageman 2025-03-03 14:40:00 Re: Introduce "log_connection_stages" setting.
Previous Message Matthias van de Meent 2025-03-03 14:14:35 Re: making EXPLAIN extensible