pgsql: Fix oversight in flattening of subqueries with empty FROM.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Fix oversight in flattening of subqueries with empty FROM.
Date: 2015-07-26 21:44:37
Message-ID: E1ZJTin-00025n-Np@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix oversight in flattening of subqueries with empty FROM.

I missed a restriction that commit f4abd0241de20d5d6a79b84992b9e88603d44134
should have enforced: we can't pull up an empty-FROM subquery if it's under
an outer join, because then we'd need to wrap its output columns in
PlaceHolderVars. As the code currently stands, the PHVs end up with empty
relid sets, which doesn't work (and is correctly caught by an Assert).

It's possible that this could be fixed by assigning the PHVs the relid
sets of the parent FromExpr/JoinExpr, but getting that to work is more
complication than I care to add right now; indeed it's likely that
we'll never bother, since pulling up empty-FROM subqueries is a rather
marginal optimization anyway.

Per report from Andreas Seltenreich. Back-patch to 9.5 where the faulty
code was added.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/fca8e59c1c582030dd7a3c870e1c3c70e8a193aa

Modified Files
--------------
src/backend/optimizer/prep/prepjointree.c | 52 +++++++++++++++++++----------
src/test/regress/expected/join.out | 34 +++++++++++++++++++
src/test/regress/sql/join.sql | 13 ++++++++
3 files changed, 81 insertions(+), 18 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Heikki Linnakangas 2015-07-27 08:53:18 pgsql: Remove false comment about speculative insertion.
Previous Message Tom Lane 2015-07-26 20:19:28 pgsql: Make entirely-dummy appendrels get marked as such in set_append_