Re: "failed to build any N-way joins" from a five-relation query

From: Tender Wang <tndrwang(at)gmail(dot)com>
To: Richard Guo <guofenglinux(at)gmail(dot)com>
Cc: Pg Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: "failed to build any N-way joins" from a five-relation query
Date: 2026-10-09 08:08:13
Message-ID: CAHewXNn62w8WGJ8KHQNDXq+Jr08-3voxTmMAXRU+wKih=8OrHw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Richard Guo <guofenglinux(at)gmail(dot)com> 于2026年10月8日周四 14:12写道:
>
> The following query fails on v14 to master:
>
> create table t (a int);
>
> select 1 from t t1 left join t t2 on true,
> lateral (select t2.a offset 0) s1 left join t t3 on s1.a = t3.a,
> lateral (select t3.a offset 0) s2
> where s2.a > t1.a;
> ERROR: failed to build any 5-way joins

I found a variant that still fails with the v1 patch applied.
Replacing the second LEFT JOIN with a FULL JOIN reproduces it:

CREATE TABLE t (a int);

SELECT 1
FROM t t1 LEFT JOIN t t2 ON true,
LATERAL (SELECT t2.a OFFSET 0) s1
FULL JOIN t t3 ON s1.a = t3.a,
LATERAL (SELECT t3.a OFFSET 0) s2
WHERE s2.a > t1.a;

This gives:

ERROR: failed to build any 4-way joins

It fails both with and without v1.

I haven't traced the exact cause yet, but wanted to flag this case.

--
Thanks,
Tender Wang

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Hannu Krosing 2026-10-09 08:13:56 Re: [PATCH] Extensible ReadyForQuery wire protocol message and C hook, for connection pools and WAIT FOR LSN
Previous Message solai v 2026-10-09 07:29:55 Re: [PATCH] postgres_fdw: Fix cost estimation for semi join pushdown