Re: [PATCH] no table rewrite when set column type to constrained domain

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH] no table rewrite when set column type to constrained domain
Date: 2025-08-26 03:26:16
Message-ID: CACJufxFhWyWzf2sJS9txSKeyA8hstxGDb8q2QWWwbo5Q1smPMA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Jul 10, 2025 at 2:00 AM jian he <jian(dot)universality(at)gmail(dot)com> wrote:
>
> we can add a new boolean field, coerce_to_domain, to NewColumnValue. this field
> is set to true only when changing an existing column's type to a constrained
> domain. In such cases, a table scan is enough—no table rewrite is needed.
> coerce_to_domain will set to false, if table rewrite is required.

I realized that "coerce_to_domain" is not so good in this context.
maybe there are other scenarios, we added a NewColumnValue and we also
only need table scan.
so I changed it to scan_only.

/*
* ....
* If scan_only is true, it means only a table scan is required.
* Currently, this is supported only by the ALTER COLUMN SET DATA TYPE command,
* where the column's data type is being changed to a constrained domain.
*/
typedef struct NewColumnValue
{
AttrNumber attnum; /* which column */
Expr *expr; /* expression to compute */
ExprState *exprstate; /* execution state */
bool is_generated; /* is it a GENERATED expression? */
bool scan_only; /* table scan only */
} NewColumnValue;

Attachment Content-Type Size
v2-0001-skip-table-rewrite-when-change-column-type-to-constrained-domain.patch text/x-patch 11.9 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas Munro 2025-08-26 03:45:25 Re: Non-reproducible AIO failure
Previous Message Thomas Munro 2025-08-26 03:21:34 Re: Non-reproducible AIO failure