Thread

Commits

  1. Prevent overly-aggressive collapsing of joins to RTE_RESULT relations.

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

    Will Leinweber <will@bitfission.com> — 2019-12-12T23:32:05Z

    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
    
    
    
    
  2. Re: Errors "failed to construct the join relation" and "failed to build any 2-way joins"

    Tom Lane <tgl@sss.pgh.pa.us> — 2019-12-13T06:26:11Z

    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
    
    
    
    
  3. Re: Errors "failed to construct the join relation" and "failed to build any 2-way joins"

    Tom Lane <tgl@sss.pgh.pa.us> — 2019-12-13T23:09:21Z

    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