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: support fast default for domain with constraints |
Date: | 2025-03-05 12:53:04 |
Message-ID: | CACJufxGZqTUqOCmwVveq4TGG6UXrMnODkMw7x5LV4DM4RkNRcw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Wed, Mar 5, 2025 at 11:13 AM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> This patch appears to summarily throw away a couple of
> backwards-compatibility concerns that the previous round
> took care to preserve:
>
> * not throwing an error if the default would fail the domain
> constraints, but the table is empty so there is no need to
> instantiate the default.
>
hi. Thanks for pointing this out.
I noticed an empty table scarenio, but didn't check it thoroughly.
The attached patch preserves this backwards-compatibility.
now it's aligned with master behavior, i think.
main gotcha is:
ALTER TABLE ADD COLUMN...
If no explicitly DEFAULT, the defval either comes from pg_type.typdefaultbin,
or constructed via makeNullConst branch.
In that case, we need to use soft error evaluation, because we allow
these cases for an empty table;
In other cases, we can directly evaluate explicitly the DEFAULT clause.
> * not assuming that the domain constraints are immutable.
>
> Now it's fair to question how important the second point is
> considering that we mostly treat domain constraints as immutable
> elsewhere. But I think the first point has actual practical uses
> --- for example, if you want to set things up so that inserts must
> specify that column explicitly. So I don't think it's okay to
> discard that behavior.
>
in v2-0003. I created a new function:
bool DomainHaveVolatileConstraints(Oid type_id, bool *have_volatile)
within DomainHaveVolatileConstraints
i use contain_volatile_functions to test whether check_expr is volatile or not.
contain_volatile_functions won't be expensive, i think.
if true then have_volatile is set to true.
if have_volatile is true then we need table rewrite.
Attachment | Content-Type | Size |
---|---|---|
v2-0002-fast-default-for-domain-with-constraints.patch | text/x-patch | 13.1 KB |
v2-0001-soft-error-variant-of-ExecPrepareExpr-ExecInitExp.patch | text/x-patch | 3.9 KB |
v2-0003-no-fast-default-for-domain-with-voltile-constrain.patch | text/x-patch | 8.0 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Alvaro Herrera | 2025-03-05 12:56:30 | Re: Support for NO INHERIT to INHERIT state change with named NOT NULL constraints |
Previous Message | Magnus Hagander | 2025-03-05 12:52:40 | Re: doc: expand note about pg_upgrade's --jobs option |