Assert failure in find_var_for_subquery_tle - Mailing list pgsql-hackers

From Richard Guo
Subject Assert failure in find_var_for_subquery_tle
Date
Msg-id CAMbWs48fFiPi7Q5yJCoM_nAs47zd5XgvPHd9nZyM_ewq+k_jpQ@mail.gmail.com
Whole thread
Responses Re: Assert failure in find_var_for_subquery_tle
List pgsql-hackers
The following query, run in the regression database, trips an Assert:

select ss.v from int8_tbl x,
  lateral (select x.q1 from (select distinct q2 from int8_tbl) s
           union all
           select q2 from int8_tbl) ss(v);

TRAP: failed Assert("var->varno == rel->relid"), File: "pathkeys.c"

In set_append_rel_size(), we have this comment:

    * NB: the resulting childrel->reltarget->exprs may contain arbitrary
    * expressions, which otherwise would not occur in a rel's targetlist.
    * Code that might be looking at an appendrel child must cope with
    * such.  (Normally, a rel's targetlist would only include Vars and
    * PlaceHolderVars.)

Apparently find_var_for_subquery_tle() did not get this memo, and
assumes that every Var in a subquery rel's targetlist belongs to that
rel.

To fix, I think we can just ignore Vars that do not belong to the
subquery rel.  Such a Var cannot be a reference to the subquery's
output, so it should never be treated as a match.

Any thoughts?

- Richard

Attachment

pgsql-hackers by date:

Previous
From: "zengxx"
Date:
Subject: Re: Skip a redundant singleton GROUP BY node
Next
From: Michael Paquier
Date:
Subject: Re: pgstat: allow a stats kind to use its own dedicated dsa/dshash