Reject wholerow references where ColumnRef is forbidden

From: Paul A Jungwirth <pj(at)illuminatedcomputing(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Andres Freund <andres(at)anarazel(dot)de>
Subject: Reject wholerow references where ColumnRef is forbidden
Date: 2026-10-31 17:20:22
Message-ID: CA+renyXoVubKLxGf=opu4ty_OYbEC1TkpX5rGfwDQpUiAga-=A@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Hackers,

Here is a fix to some crashes when using a wholerow reference to sneak
in a ColumnRef where it shouldn't be allowed. This was originally
reported in [0] by Andres while reviewing FOR PORTION OF, but it is
actually a problem on master, going back at least to v14. You can
reach a crash like so:

-- crashes
ALTER TABLE t ADD COLUMN b int DEFAULT (ROW(t.*)).f1;

-- crashes
CREATE TABLE p1 PARTITION OF p FOR VALUES IN ((ROW(p1.*)).f1);

-- wrongly accepted
CREATE TABLE t (a int, b int DEFAULT (ROW(t.*)).f1);
ALTER TABLE t ALTER COLUMN b SET DEFAULT (ROW(t.*)).f1;
INSERT INTO t (a) VALUES (1); -- crashes here instead

Today, we forbid some EXPR_KINDs in transformColumnRef, but we need to
do that in (or near) ExpandColumnRefStar as well. I factored out the
check to checkColumnRefAllowed to avoid future inconsistencies.

[0] https://www.postgresql.org/message-id/yfers7d2kizq6ockz4nu7e7avq3gj5anpd7ilxkazyvicv4qgy@3cesow2bbhnx

Yours,

--
Paul ~{:-)
pj(at)illuminatedcomputing(dot)com

Attachment Content-Type Size
v1-0001-Reject-whole-row-references-where-column-referenc.patch text/x-patch 10.9 KB

Browse pgsql-hackers by date

  From Date Subject
Previous Message Paul A Jungwirth 2026-10-31 17:17:36 Fix trigger memory leak