diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2002-12-05 21:46:37 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2002-12-05 21:46:37 +0000 |
commit | 993b145d7ff99231128e83b51317094821314e32 (patch) | |
tree | 6509a3532ac0f3912b02bdbbe5f638612c51c130 /src | |
parent | fae2f14cddcaad0419de794c894c369e83fedbef (diff) | |
download | postgresql-993b145d7ff99231128e83b51317094821314e32.tar.gz postgresql-993b145d7ff99231128e83b51317094821314e32.zip |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/optimizer/plan/planner.c | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index 0e5afccae3a..ebb9f3d2092 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.132 2002/11/29 21:39:11 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.133 2002/12/05 21:46:37 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -357,10 +357,14 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join) * nothing will happen after the first time. We do have to be * careful to copy everything we pull up, however, or risk * having chunks of structure multiply linked. + * + * Note: 'false' is correct here even if we are within an outer + * join in the upper query; the lower query starts with a clean + * slate for outer-join semantics. */ subquery->jointree = (FromExpr *) pull_up_subqueries(subquery, (Node *) subquery->jointree, - below_outer_join); + false); /* * Now make a modifiable copy of the subquery that we can run @@ -543,6 +547,20 @@ is_simple_subquery(Query *subquery) return false; /* + * Don't pull up a subquery that has any sublinks in its targetlist, + * either. As of PG 7.3 this creates problems because the pulled-up + * expressions may go into join alias lists, and the sublinks would + * not get fixed because we do flatten_join_alias_vars() too late. + * Eventually we should do a complete flatten_join_alias_vars as the + * first step of preprocess_expression, and then we could probably + * support this. (BUT: it might be a bad idea anyway, due to possibly + * causing multiple evaluations of an expensive sublink.) + */ + if (subquery->hasSubLinks && + contain_subplans((Node *) subquery->targetList)) + return false; + + /* * Hack: don't try to pull up a subquery with an empty jointree. * query_planner() will correctly generate a Result plan for a * jointree that's totally empty, but I don't think the right things |