Re: support fast default for domain with constraints
jian he <jian.universality@gmail.com>
From: jian he <jian.universality@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2025-03-05T12:53:04Z
Lists: pgsql-hackers
Attachments
- v2-0002-fast-default-for-domain-with-constraints.patch (text/x-patch) patch v2-0002
- v2-0001-soft-error-variant-of-ExecPrepareExpr-ExecInitExp.patch (text/x-patch) patch v2-0001
- v2-0003-no-fast-default-for-domain-with-voltile-constrain.patch (text/x-patch) patch v2-0003
On Wed, Mar 5, 2025 at 11:13 AM Tom Lane <tgl@sss.pgh.pa.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.
Commits
-
Enable fast default for domains with non-volatile constraints
- a0b6ef29a518 19 (unreleased) landed
-
Extend DomainHasConstraints() to optionally check constraint volatility
- 487cf2cbd2f5 19 (unreleased) landed
-
Restrict virtual columns to use built-in functions and types
- 0cd69b3d7ef3 18.0 cited
-
Replace EEOP_DONE with special steps for return/no return
- 8dd7c7cd0a26 18.0 cited
-
Add soft error handling to some expression nodes
- aaaf9449ec6b 17.0 cited