From: | jian he <jian(dot)universality(at)gmail(dot)com> |
---|---|
To: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: bug in stored generated column over domain with constraints. |
Date: | 2025-04-10 08:53:12 |
Message-ID: | CACJufxF0xJ1D6ZBvqopMA=vKRKbFrtUbaMJ8bm0b8d9KLDC4Ag@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
hi.
new patch attached.
rewriteTargetListIU, expand_insert_targetlist these two places can
make a null Const TargetEntry for the generated column in an INSERT
operation.
but since this problem only occurs in INSERT, so i placed the logic
within expand_insert_targetlist would be appropriate?
The following are excerpts of the commit message.
--------------------------------
create domain d3 as int check (value is not null);
create table t0(b int, a d3 GENERATED ALWAYS as (b + 11) stored);
insert into t0 values (1, default);
ERROR: value for domain d3 violates check constraint "d3_check"
explain(costs off, verbose) insert into t0 values (1, default);
QUERY PLAN
---------------------------------------
Insert on public.t0
-> Result
Output: 1, NULL::integer
For INSERT operation, for Query->targetList, we should not make a
generated column
over domain with constraint to a CoerceToDomain node, instead, we make it as a
simple null Const over domain's base type.
When a column is a generated column in an INSERT, expand_insert_targetlist
should unconditionally generate a null Const to be inserted. If we are not
doing this way, we might end up wrapping the null Const in a CoerceToDomain
node, which may trigger runtime error earlier if the domain has a NOT NULL
constraint. That's not fine, as generated columns are already handled in
ExecComputeStoredGenerated.
--------------------------------
Attachment | Content-Type | Size |
---|---|---|
v3-0001-fix-INSERT-generated-column-over-domain-with-cons.patch | text/x-patch | 9.4 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | jian he | 2025-04-10 08:57:20 | wrong comments in rewriteTargetListIU |
Previous Message | Tender Wang | 2025-04-10 08:44:24 | Re: Consistently use macro HeapTupleIsValid to check the validity of tuples in tablecmds.c |