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: Rethink treatment of "postponed" quals in deconstruct_jointree()
Date: Sat, 04 Feb 2023 17:46:09 +0000
Message-ID: <E1pOMc4-001aGG-Gf@gemulon.postgresql.org> (raw)

Rethink treatment of "postponed" quals in deconstruct_jointree().

After pulling up LATERAL subqueries, we may have qual clauses that
refer to relations outside their syntactic scope.  Before doing any
such pullup, prepjointree.c checks to make sure that it wouldn't
create a semantically-invalid situation; but we leave it to
deconstruct_jointree() to actually move these quals up the join
tree to a place where they can be evaluated.  In commit 2489d76c4,
I (tgl) refactored deconstruct_jointree() in a way that caused
assertion failures while moving such quals, because the new logic
failed to distinguish "this jointree node is a parent of the source
one" from "this jointree node is processed after the source
one in depth-first order".

Fix this, and at the same time reduce the overhead a bit, by
getting rid of the common PostponedQual list and instead making each
JoinTreeItem contain a list of quals that needed to be postponed to
its level.  We can help distribute_qual_to_rels find the appropriate
JoinTreeItem efficiently by adding parent-item links to the
JoinTreeItem data structure.  This ends up being the same number
of relid subset checks as the original (pre-bug) logic, but less
list manipulation is required during multi-level postponements.

Richard Guo and Tom Lane, per bug #17768 from Robins Tharakan.

Discussion: https://postgr.es/m/17768-5ac8730ece54478f@postgresql.org

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/5840c2027264d5dfad743c50874e0ebf8b840f3f

Modified Files
--------------
src/backend/optimizer/plan/initsplan.c | 203 ++++++++++++++-------------------
src/test/regress/expected/join.out     |  22 ++++
src/test/regress/sql/join.sql          |   6 +
3 files changed, 111 insertions(+), 120 deletions(-)



Message-ID: <E1pOMc4-001aGG-Gf@gemulon.postgresql.org>
Permalink:  ../E1pOMc4-001aGG-Gf@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1pOMc4-001aGG-Gf@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: Rethink treatment of "postponed" quals in deconstruct_jointree()
  In-Reply-To: <E1pOMc4-001aGG-Gf@gemulon.postgresql.org>
  References: <E1pOMc4-001aGG-Gf@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