Re: support fast default for domain with constraints - Mailing list pgsql-hackers

From jian he
Subject Re: support fast default for domain with constraints
Date
Msg-id CACJufxECb4nVjssRPknepNmqF2CR0ycPzTmJZPxoWYK4JD-mFQ@mail.gmail.com
Whole thread Raw
In response to Re: support fast default for domain with constraints  (jian he <jian.universality@gmail.com>)
List pgsql-hackers
On Thu, Mar 6, 2025 at 11:04 AM jian he <jian.universality@gmail.com> wrote:
>
> hi.
>
> rearrange the patch.
> v3-0001 and v3-0002 is preparare patches.
> v3-0001 add function: ExecPrepareExprSafe and ExecInitExprSafe.
> v3-0002 add function: DomainHaveVolatileConstraints
>

i actually do need DomainHaveVolatileConstraints
for virtual generated columns over domain with constraints in [1],
which I am working on.

for example:
create domain d1 as int check(value > random(min=>11::int, max=>12));
create domain d2 as int check(value > 12);
create table t(a int);
insert into t select g from generate_series(1, 10) g;

----we do need table rewrite in phase 3.
alter table t add column b d1 generated always as (a+11) virtual;

--we can only do table scan in phase 3.
alter table t add column c d2 generated always as (a + 12) virtual;

Generally, table rewrite is more expensive than table scan.
In the above case, if domain constraints are not volatile, table scan
should be fine.

[1]: https://postgr.es/m/CACJufxHArQysbDkWFmvK+D1TPHQWWTxWN15cMuUaTYX3xhQXgg@mail.gmail.com



pgsql-hackers by date:

Previous
From: Andrew Dunstan
Date:
Subject: Re: jsonb_strip_nulls with arrays?
Next
From: Andreas Karlsson
Date:
Subject: Re: dblink query interruptibility