pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Cope with lateral references in the quals of a subquery RTE.
Date: Tue, 14 Jul 2020 00:38:49 +0000
Message-ID: <E1jv8y9-00066u-O7@gemulon.postgresql.org> (raw)

Cope with lateral references in the quals of a subquery RTE.

The qual pushdown logic assumed that all Vars in a restriction clause
must be Vars referencing subquery outputs; but since we introduced
LATERAL, it's possible for such a Var to be a lateral reference instead.
This led to an assertion failure in debug builds.  In a non-debug
build, there might be no ill effects (if qual_is_pushdown_safe decided
the qual was unsafe anyway), or we could get failures later due to
construction of an invalid plan.  I've not gone to much length to
characterize the possible failures, but at least segfaults in the
executor have been observed.

Given that this has been busted since 9.3 and it took this long for
anybody to notice, I judge that the case isn't worth going to great
lengths to optimize.  Hence, fix by just teaching qual_is_pushdown_safe
that such quals are unsafe to push down, matching the previous behavior
when it accidentally didn't fail.

Per report from Tom Ellis.  Back-patch to all supported branches.

Discussion: https://postgr.es/m/20200713175124.GQ8220@cloudinit-builder

Branch
------
REL_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/3753df8f8ae8e16bf81bc809514982b35a94f4a1

Modified Files
--------------
src/backend/optimizer/path/allpaths.c   | 20 +++++++++++--
src/test/regress/expected/subselect.out | 53 +++++++++++++++++++++++++++++++++
src/test/regress/sql/subselect.sql      | 26 ++++++++++++++++
3 files changed, 96 insertions(+), 3 deletions(-)



view thread (7+ messages)  latest in thread

Message-ID: <E1jv8y9-00066u-O7@gemulon.postgresql.org>
Permalink:  ../E1jv8y9-00066u-O7@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1jv8y9-00066u-O7@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Cope with lateral references in the quals of a subquery RTE.
  In-Reply-To: <E1jv8y9-00066u-O7@gemulon.postgresql.org>
  References: <E1jv8y9-00066u-O7@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox