pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: lauri.kajan@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #18152: Join condition is not pushed down to union all subquery
Date: Tue, 10 Oct 2023 12:06:20 -0400
Message-ID: <335646.1696953980@sss.pgh.pa.us> (raw)
In-Reply-To: <18152-72d0fe42ca4283d9@postgresql.org>
References: <18152-72d0fe42ca4283d9@postgresql.org>

PG Bug reporting form <noreply@postgresql.org> writes:
> The join condition is not pushed down to a subquery containing UNION ALL
> when even a single query within the subquery contains a WHERE clause.

I think this is less about "can't push down" than "can't pull up",
specifically that prepjointree.c fails to flatten that subquery
into an "appendrel member", per the comments in is_safe_append_member:

     * It's only safe to pull up the child if its jointree contains exactly
     * one RTE, else the AppendRelInfo data structure breaks. The one base RTE
     * could be buried in several levels of FromExpr, however.  Also, if the
     * child's jointree is completely empty, we can pull up because
     * pull_up_simple_subquery will insert a single RTE_RESULT RTE instead.
     *
     * Also, the child can't have any WHERE quals because there's no place to
     * put them in an appendrel.  (This is a bit annoying...)

I don't recall at the moment if there are fundamental reasons not to
have per-child quals in appendrels, or if it could be done with the
application of enough elbow grease.  But it's probably not trivial.
That comment has been there quite awhile.

			regards, tom lane





view thread (3+ messages)  latest in thread

Message-ID: <335646.1696953980@sss.pgh.pa.us>
Permalink:  ../335646.1696953980@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/335646.1696953980@sss.pgh.pa.us

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, lauri.kajan@gmail.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #18152: Join condition is not pushed down to union all subquery
  In-Reply-To: <335646.1696953980@sss.pgh.pa.us>

* 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