Errors "failed to construct the join relation" and "failed to build any 2-way joins"

Started by Will Leinweberover 6 years ago3 messageshackers
Jump to latest
#1Will Leinweber
will@bitfission.com

On 12.1, fresh initdb the following query gives me the error
"ERROR: failed to construct the join relation"

SELECT FROM (
SELECT FROM pg_catalog.pg_stat_bgwriter AS ref_0
LEFT JOIN pg_catalog.pg_stat_bgwriter AS ref_1 ON (true), LATERAL (
SELECT FROM pg_catalog.pg_publication AS ref_2, LATERAL (
SELECT FROM pg_catalog.pg_class
WHERE ref_1.buffers_alloc IS NOT NULL
) AS subq_0
WHERE true
LIMIT 1
) AS subq_1
WHERE true
) AS subq_2

If you move the limit up into subq_0, then the error changes to
"ERROR: failed to build any 2-way joins"

SELECT FROM (
SELECT FROM pg_catalog.pg_stat_bgwriter AS ref_0
LEFT JOIN pg_catalog.pg_stat_bgwriter AS ref_1 ON (true), LATERAL (
SELECT FROM pg_catalog.pg_publication AS ref_2, LATERAL (
SELECT FROM pg_catalog.pg_class
WHERE ref_1.buffers_alloc IS NOT NULL
LIMIT 1
) AS subq_0
WHERE true
) AS subq_1
WHERE true
) AS subq_2

I'm unable to reproduce either of the errors on 11.6 or 11.4. I haven't tried
any other versions. The actual value of the limit doesn't appear to matter,
just if it's present or not.

— Will

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Will Leinweber (#1)
Re: Errors "failed to construct the join relation" and "failed to build any 2-way joins"

Will Leinweber <will@bitfission.com> writes:

On 12.1, fresh initdb the following query gives me the error
"ERROR: failed to construct the join relation"

I'm getting an assertion failure in an assert-enabled build, here:

(gdb) f 3
#3 0x00000000006f382a in create_lateral_join_info (root=0x2d380c8)
at initsplan.c:637
637 Assert(!bms_is_member(rti, lateral_relids));

Eyeing the plan produced by v11, I'm suspecting some oversight in
the RTE_RESULT changes (4be058fe9); but I haven't actually bisected.
Too tired to look closer right now.

regards, tom lane

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Tom Lane (#2)
Re: Errors "failed to construct the join relation" and "failed to build any 2-way joins"

I wrote:

Will Leinweber <will@bitfission.com> writes:

On 12.1, fresh initdb the following query gives me the error
"ERROR: failed to construct the join relation"

Eyeing the plan produced by v11, I'm suspecting some oversight in
the RTE_RESULT changes (4be058fe9); but I haven't actually bisected.

Yup: it's folding the join tree to the point where a PlaceHolderVar ends
up marked as to be evaluated by the same relation that uses it, and then
things go all pear-shaped. Here's a proposed patch for that.

regards, tom lane

Attachments:

restrict-RESULT-RTE-removal-a-bit.patchtext/x-diff; charset=us-ascii; name=restrict-RESULT-RTE-removal-a-bit.patchDownload+166-51