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

Alexander Law <exclusion@gmail.com>

From: Alexander Lakhin <exclusion@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>, jian he <jian.universality@gmail.com>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2025-04-01T18:00:00Z
Lists: pgsql-hackers
Hello Tom,

03.03.2025 20:38, Tom Lane wrote:
> Pushed with that adjustment and some other minor polishing.

I've discovered that 95f650674 introduced a defect similar to bug #18297,
but this time with DEFAULT. Namely, the following script:
CREATE TABLE a (aa text);
CREATE TABLE c (cc text) INHERITS (a);
CREATE TABLE d (dd text) INHERITS (c, a);
ALTER TABLE a ADD COLUMN i int DEFAULT 1;

fails with:
ERROR:  XX000: tuple already updated by self
LOCATION:  simple_heap_update, heapam.c:4421

Best regards,
Alexander Lakhin
Neon (https://neon.tech)

Commits

  1. Need to do CommandCounterIncrement after StoreAttrMissingVal.

  2. Simplify some logic around setting pg_attribute.atthasdef.

  3. Remove now-dead code in StoreAttrDefault().

  4. Fix broken handling of domains in atthasmissing logic.