|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * 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 $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
@@ -357,10 +357,14 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join)
|
357 | 357 | * nothing will happen after the first time. We do have to be
|
358 | 358 | * careful to copy everything we pull up, however, or risk
|
359 | 359 | * 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. |
360 | 364 | */
|
361 | 365 | subquery->jointree = (FromExpr *)
|
362 | 366 | pull_up_subqueries(subquery, (Node *) subquery->jointree,
|
363 |
| - below_outer_join); |
| 367 | + false); |
364 | 368 |
|
365 | 369 | /*
|
366 | 370 | * Now make a modifiable copy of the subquery that we can run
|
@@ -542,6 +546,20 @@ is_simple_subquery(Query *subquery)
|
542 | 546 | if (expression_returns_set((Node *) subquery->targetList))
|
543 | 547 | return false;
|
544 | 548 |
|
| 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 | + |
545 | 563 | /*
|
546 | 564 | * Hack: don't try to pull up a subquery with an empty jointree.
|
547 | 565 | * query_planner() will correctly generate a Result plan for a
|
|
0 commit comments