| From: | PG Bug reporting form <noreply(at)postgresql(dot)org> |
|---|---|
| To: | pgsql-bugs(at)lists(dot)postgresql(dot)org |
| Cc: | tharakan(at)gmail(dot)com |
| Subject: | BUG #19929: RETURNING OLD/NEW: segfault when used only inside a hashed subplan |
| Date: | 2026-11-21 22:37:18 |
| Message-ID: | 19929-85ce6f65d351c7a2@postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
The following bug has been logged on the website:
Bug reference: 19929
Logged by: Robins Tharakan
Email address: tharakan(at)gmail(dot)com
PostgreSQL version: Unsupported/Unknown
Operating system: Debian 13 (x86_64)
Description:
A DELETE whose RETURNING list reads NEW only inside a sub-select that
the planner hashes makes the client backend dereference a NULL slot
pointer and die with signal 11; the postmaster then restarts the other
backends. The same happens for OLD in an INSERT, and for MERGE's DELETE
and INSERT actions:
LOG: client backend (PID 1488746) was terminated by signal 11:
Segmentation fault
DETAIL: Failed process was running: DELETE FROM t RETURNING
EXISTS (SELECT WHERE new.a = 1);
In a DELETE, NEW is all NULL, so the query should return one row, f.
With new.a also in the RETURNING list itself, it does: (NULL, f).
SQL
===
CREATE TABLE t (a int);
INSERT INTO t VALUES (1);
-- In a DELETE, NEW is all NULL, so this should return f.
DELETE FROM t RETURNING EXISTS (SELECT WHERE new.a = 1);
-- Variants, each crashes the same way (run one at a time):
-- OLD in an INSERT (OLD is all NULL there)
INSERT INTO t VALUES (2) RETURNING old.a IN (SELECT 1);
-- NEW in a DELETE, with IN instead of EXISTS
DELETE FROM t RETURNING new.a IN (SELECT 1);
-- MERGE's DELETE action
MERGE INTO t USING (VALUES (1)) v(x) ON t.a = v.x
WHEN MATCHED THEN DELETE
RETURNING EXISTS (SELECT WHERE new.a = 1);
-- Doesn't crash: new.a also in the RETURNING list (returns NULL, f)
DELETE FROM t RETURNING new.a, EXISTS (SELECT WHERE new.a = 1);
The plan shows the hashed subplan:
Delete on public.t
Output: (ANY (new.a = (hashed SubPlan exists_to_any_1).col1))
-> Seq Scan on public.t
Output: t.ctid
SubPlan exists_to_any_1
-> Result
Output: 1
Commit
======
Started: 80feb727c86
Reproducible: HEAD (9b5d4e33317) through REL_18_STABLE
v17 and older don't have OLD/NEW in RETURNING.
A release build (-O2, no --enable-cassert) crashes the same way.
Error Log
=========
LOG: client backend (PID 1488746) was terminated by signal 11:
Segmentation fault
DETAIL: Failed process was running: DELETE FROM t RETURNING
EXISTS (SELECT WHERE new.a = 1);
LOG: terminating any other active server processes
LOG: all server processes terminated; reinitializing
Backtrace
=========
#0 slot_getsomeattrs (slot=0x0, attnum=1) at tuptable.h:379
#1 ExecInterpExpr (...) at execExprInterp.c:684
#2 ExecInterpExprStillValid (...) at execExprInterp.c:2309
#3 ExecEvalExprNoReturn (...) at executor.h:431
#4 ExecEvalExprNoReturnSwitchContext (...) at executor.h:472
#5 ExecProject (projInfo=...) at executor.h:504
#6 ExecProcessReturning (..., isDelete=true, oldSlot=...,
newSlot=0x0, ...) at nodeModifyTable.c:366
#7 ExecDelete (...) at nodeModifyTable.c:1936
#8 ExecModifyTable (...) at nodeModifyTable.c:4809
#9 ExecProcNodeFirst (...) at execProcnode.c:469
For the INSERT variant, the same frames with isDelete=false,
oldSlot=0x0, from ExecInsert().
I see a partial signature overlap with bug #19752[1], but
that was a GROUP BY, and think it doesn't hurt to submit this
nonetheless.
Found using SQLsmith, SQLReduce, creduce and Claude.
-
Robins Tharakan
Databricks
Reference:
1. https://commitfest.postgresql.org/patch/7545/
| From | Date | Subject | |
|---|---|---|---|
| Next Message | wangyang25 | 2026-11-22 08:55:56 | Duplicate VOLATILE predicates in a WHERE OR clause can change query results |
| Previous Message | shihao zhong | 2026-11-21 18:51:38 | Re: pg_rewind and hint bits leads to visibility corruption |