BUG #19460: FULL JOIN rewriting issue on empty queries

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: francois(dot)jehl(at)pigment(dot)com
Subject: BUG #19460: FULL JOIN rewriting issue on empty queries
Date: 2026-04-19 17:57:59
Message-ID: 19460-5625143cef66012f@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: 19460
Logged by: François Jehl
Email address: francois(dot)jehl(at)pigment(dot)com
PostgreSQL version: 17.9
Operating system: Linux
Description:

Good evening,

After migrating from version 15 to 17.9, the following query fails with:

ERROR: FULL JOIN is only supported with merge-joinable or hash-joinable join
conditions

This is weird because the FULL JOIN is a basic equi-join that succeeds on
PG15 (we tested it; it also fails on 16).

It requires a table t(id UUID PRIMARY KEY) but here is a repro on DbFiddle
https://www.db-fiddle.com/f/hCq5S13Zs3EV8f86Mxxh3B/3.

SELECT COALESCE(lhs.id, rhs.id) AS id
FROM (SELECT gen_random_uuid() AS id) AS lhs
FULL OUTER JOIN (
SELECT sub.id
FROM (
SELECT empty_source.id
FROM (SELECT NULL::UUID AS id WHERE FALSE) AS empty_source
LEFT OUTER JOIN (
SELECT t.id FROM t WHERE t.id =
'26c5112c-0a8f-4315-9ff5-7dcb59b8359e'::UUID
) AS sub ON sub.id = empty_source.id
) AS sub
) AS rhs ON rhs.id = lhs.id;

Adding OFFSET 0 to the empty subquery on the RHS prevents the error,
suggesting the query rewriter is doing something it should not!
Another thing: removing the PK constraint on t.id, or removing/changing the
WHERE filter to a non-PK column, makes the query succeed. The PK equality
filter is required to trigger the failure (maybe because it generates some
additional inlining, which then allows the empty subquery to collapse).

We're happy to provide more context or test patches if helpful.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2026-04-19 21:10:20 Re: BUG #19460: FULL JOIN rewriting issue on empty queries
Previous Message Andrei Lepikhov 2026-04-17 21:26:45 Re: TRAP: failed Assert("offsets[i] > offsets[i - 1]"), File: "tidstore.c"