Skip to content

Commit 993b145

Browse files
committed
Avoid pulling up sublinks from a subselect's targetlist. Works around
problems that occur if sublink is referenced via a join alias variable. Perhaps this can be improved later, but a simple and safe fix is needed for 7.3.1.
1 parent fae2f14 commit 993b145

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/backend/optimizer/plan/planner.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.132 2002/11/29 21:39:11 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.133 2002/12/05 21:46:37 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -357,10 +357,14 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join)
357357
* nothing will happen after the first time. We do have to be
358358
* careful to copy everything we pull up, however, or risk
359359
* having chunks of structure multiply linked.
360+
*
361+
* Note: 'false' is correct here even if we are within an outer
362+
* join in the upper query; the lower query starts with a clean
363+
* slate for outer-join semantics.
360364
*/
361365
subquery->jointree = (FromExpr *)
362366
pull_up_subqueries(subquery, (Node *) subquery->jointree,
363-
below_outer_join);
367+
false);
364368

365369
/*
366370
* Now make a modifiable copy of the subquery that we can run
@@ -542,6 +546,20 @@ is_simple_subquery(Query *subquery)
542546
if (expression_returns_set((Node *) subquery->targetList))
543547
return false;
544548

549+
/*
550+
* Don't pull up a subquery that has any sublinks in its targetlist,
551+
* either. As of PG 7.3 this creates problems because the pulled-up
552+
* expressions may go into join alias lists, and the sublinks would
553+
* not get fixed because we do flatten_join_alias_vars() too late.
554+
* Eventually we should do a complete flatten_join_alias_vars as the
555+
* first step of preprocess_expression, and then we could probably
556+
* support this. (BUT: it might be a bad idea anyway, due to possibly
557+
* causing multiple evaluations of an expensive sublink.)
558+
*/
559+
if (subquery->hasSubLinks &&
560+
contain_subplans((Node *) subquery->targetList))
561+
return false;
562+
545563
/*
546564
* Hack: don't try to pull up a subquery with an empty jointree.
547565
* query_planner() will correctly generate a Result plan for a

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy