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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Cope with lateral references in the quals of a subquery RTE.
Date: 2020-07-14 00:38:49
Message-ID: E1jv8y9-00066x-OW@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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_10_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/6443cd2e242175890ede181b96bf47b0d9b259ce

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(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2020-07-14 04:18:32 pgsql: Fix comments related to table AMs
Previous Message Alexander Korotkov 2020-07-13 19:55:43 Re: pgsql: Improvements to psql \dAo and \dAp commands