Re: support fast default for domain with constraints

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: support fast default for domain with constraints
Date: 2025-09-01 06:27:33
Message-ID: CACJufxGFP5VJJwPqTZJ_fQq_BKLqD_90JQ49AJH6fPqSmdFSnQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

hi.

in previous patches v6-0001 to v6-0003, we added support for ALTER TABLE ADD
COLUMN with fast defaults for domains having non-volatile constraints.

inspired by another patch of mine: https://commitfest.postgresql.org/patch/5907
I believe it's doable to perform only a table scan when using ALTER TABLE ADD
COLUMN with a domain that has volatile constraints.

some example:
CREATE DOMAIN domain8 as int check((value + random(min=>11::int,
max=>11)) > 12);
CREATE TABLE t3(a int);
INSERT INTO t3 VALUES(1),(2);
ALTER TABLE t3 ADD COLUMN f domain8 default 1; --error while coercing to domain
ALTER TABLE t3 ADD COLUMN f domain8 default 20; --ok

The idea is the same as mentioned in [1],
for struct NewColumnValue, add another field (scan_only) to indicate
that we use table scan to evaluate the CoerceToDomain node.

summary of the attached v7.
v7-0001, v7-00002: preparatory patch.
v7-0003 adds fast default support for ALTER TABLE ADD COLUMN when the domain has
non-volatile constraints.
A table rewrite is still required for domains with volatile constraints.

v7-0004 skip table rewrite (table scan only) for ALTER TABLE ADD
COLUMN with domains has volatile constraints.

[1] https://postgr.es/m/CACJufxFhWyWzf2sJS9txSKeyA8hstxGDb8q2QWWwbo5Q1smPMA@mail.gmail.com

Attachment Content-Type Size
v7-0003-fast-default-for-domain-with-constraints.patch text/x-patch 9.9 KB
v7-0004-table-scan-only-when-adding-domain-with-volatile-constraints.patch text/x-patch 9.0 KB
v7-0002-add-function-DomainHaveVolatileConstraints.patch text/x-patch 2.7 KB
v7-0001-soft-error-variant-of-ExecPrepareExpr-ExecInitExpr.patch text/x-patch 3.9 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2025-09-01 06:47:17 new warnings with clang-21 / how const is Datum
Previous Message Michael Paquier 2025-09-01 06:19:46 Re: pg_upgrade: transfer pg_largeobject_metadata's files when possible