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

From Tender Wang
Subject Re: "failed to build any N-way joins" from a five-relation query
Date
Msg-id CAHewXNn62w8WGJ8KHQNDXq+Jr08-3voxTmMAXRU+wKih=8OrHw@mail.gmail.com
Whole thread
In response to "failed to build any N-way joins" from a five-relation query  (Richard Guo <guofenglinux@gmail.com>)
Responses Re: "failed to build any N-way joins" from a five-relation query
List pgsql-hackers
Richard Guo <guofenglinux@gmail.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



pgsql-hackers by date:

Previous
From: solai v
Date:
Subject: Re: [PATCH] postgres_fdw: Fix cost estimation for semi join pushdown
Next
From: Hannu Krosing
Date:
Subject: Re: [PATCH] Extensible ReadyForQuery wire protocol message and C hook, for connection pools and WAIT FOR LSN