support fast default for domain with constraints
jian he <jian.universality@gmail.com>
From: jian he <jian.universality@gmail.com>
To: PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2025-03-05T02:56:42Z
Lists: pgsql-hackers
Attachments
- v1-0002-support-fast-default-for-domain-with-constraints.patch (text/x-patch) patch v1-0002
- v1-0001-add-soft-error-variant-of-ExecPrepareExpr-ExecIni.patch (text/x-patch) patch v1-0001
hi. Thanks to commit aaaf9449ec6be62cb0d30ed3588dc384f56274bf[1], ExprState.escontext (ErrorSaveContext) was added, and ExecEvalConstraintNotNull, ExecEvalConstraintCheck were changed to use errsave instead of hard error. Now we can use it to evaluate CoerceToDomain in a soft error way, that is what this patch intended to do. previously ExprState.escontext was mainly used in SQL/JSON related patches. To achieve that, we have to populate ExprState.escontext before passing it to ExecInitExprRec. So I created two functions: ExecInitExprSafe, ExecPrepareExprSafe. ExecPrepareExprSafe is an error safe variant of ExecPrepareExpr. within ExecPrepareExprSafe, we use ExecInitExprSafe. ExecInitExprSafe differs from ExecInitExpr is that the output ExprState has its escontext set to a valid ErrorSaveContext. demo: CREATE DOMAIN domain5 AS int check(value > 10); -- stable create domain domain6 as int not null; CREATE TABLE t3(a int); ALTER TABLE t3 ADD COLUMN b domain5 default 1; --should not fail. INSERT INTO t3 DEFAULT VALUES; --should fail. ALTER TABLE t3 DROP COLUMN b; --need drop it for the following tests INSERT INTO t3 VALUES(1),(2); ALTER TABLE t3 ADD COLUMN b domain6; --table rewrite. then fail. ALTER TABLE t3 ADD COLUMN c domain6 default 13; --no table rewrite. fast default applied. attmissingval is stored. [1] https://git.postgresql.org/cgit/postgresql.git/commit/?id=aaaf9449ec6be62cb0d30ed3588dc384f56274bf
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