| From: | Kirill Reshke <reshkekirill(at)gmail(dot)com> |
|---|---|
| To: | 798604270(at)qq(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org |
| Subject: | Re: BUG #19942: SIGSEGV crash (and wrong results) in MERGE ... RETURNING WITH (OLD/NEW) with VIRTUAL generated colum |
| Date: | 2026-11-25 18:07:34 |
| Message-ID: | CALdSSPhxnhH27CtUBEWB8cdjO7=TgGTQkzMGq_QQmx23gs3hng@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
On Wed, 25 Nov 2026 at 22:54, PG Bug reporting form
<noreply(at)postgresql(dot)org> wrote:
>
> The following bug has been logged on the website:
>
> Bug reference: 19942
> Logged by: Chi Zhang
> Email address: 798604270(at)qq(dot)com
> PostgreSQL version: 19.0
> Operating system: Ubuntu 24.04
> Description:
>
> Hi,
>
> I found that executing MERGE ... RETURNING WITH (OLD AS o, NEW AS n) against
> a table containing a VIRTUAL generated column causes an immediate backend
> SIGSEGV crash (when the virtual column expression is non-strict, e.g.
> COALESCE(a, 999), or referenced via whole-row o/n), and silently returns
> wrong OLD/NEW values for constant virtual columns (e.g. GENERATED ALWAYS AS
> (42) VIRTUAL).
>
> This test case triggers a crash:
> ```
> CREATE TEMP TABLE t1( id int PRIMARY KEY, a int, g int GENERATED ALWAYS AS
> (COALESCE(a, 999)) VIRTUAL);
> INSERT INTO t1(id, a) VALUES (1, 10), (2, 20);
> MERGE INTO t1 t USING (VALUES (1, 100), (2, 200), (3, 300)) AS s(id, a) ON
> t.id = s.id WHEN MATCHED AND s.id = 1 THEN UPDATE SET a = s.a WHEN MATCHED
> AND s.id = 2 THEN DELETE WHEN NOT MATCHED THEN INSERT (id, a) VALUES (s.id,
> s.a) RETURNING WITH (OLD AS o, NEW AS n) merge_action(), o.g AS old_g, n.g
> AS new_g;
> ```
> The backend crashes immediately with signal 11: Segmentation fault (both
> release and --enable-cassert builds). GDB shows a NULL-slot dereference in
> CheckVarSlotCompatibility(slot=0x0)
> (src/backend/executor/execExprInterp.c:2409) while projecting the target
> scan node.
>
>
> This test case triggers a wrong result:
> ```
> CREATE TEMP TABLE t2(id int PRIMARY KEY, a int, g int GENERATED ALWAYS AS
> (42) VIRTUAL);
> INSERT INTO t2(id, a) VALUES (1, 10), (2, 20);
> MERGE INTO t2 t USING (VALUES (1, 100), (2, 200), (3, 300)) AS s(id, a) ON
> t.id = s.id WHEN MATCHED AND s.id = 1 THEN UPDATE SET a = s.a WHEN MATCHED
> AND s.id = 2 THEN DELETE WHEN NOT MATCHED THEN INSERT (id, a) VALUES (s.id,
> s.a) RETURNING WITH (OLD AS o, NEW AS n) merge_action(), o.g AS old_g, n.g
> AS new_g;
> ```
> The output is:
> ```
> merge_action | old_g | new_g
> -----------+-------+-------
> UPDATE | 42 | 42
> DELETE | 42 | 42
> INSERT | |
> ```
> I expect that DELETE should return old_g = 42, new_g = NULL, and INSERT
> should return old_g = NULL, new_g = 42.
>
>
>
>
Looks like regression since 17550c8a
--
Best regards,
Kirill Reshke
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2026-11-25 18:29:50 | Re: BUG #19948: Unqualified prefix <= operator is rejected despite being first in search_path |
| Previous Message | PG Bug reporting form | 2026-11-25 17:46:20 | BUG #19953: pg_stat_io exposes impossible rows for io worker backends |