Re: [PATCH] no table rewrite when set column type to constrained domain
jian he <jian.universality@gmail.com>
From: jian he <jian.universality@gmail.com>
To: PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2025-08-26T03:26:16Z
Lists: pgsql-hackers
Attachments
- v2-0001-skip-table-rewrite-when-change-column-type-to-constrained-domain.patch (text/x-patch) patch v2-0001
On Thu, Jul 10, 2025 at 2:00 AM jian he <jian.universality@gmail.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;