提交 83fd58df 编写于 作者: T Tom Lane

Add missing correction of sublevelsup when pulling up a subquery.

Fixes problem with cases like
SELECT * FROM foo t WHERE NOT EXISTS (SELECT remoteid FROM
(SELECT f1 as remoteid FROM foo WHERE f1 = t.f1) AS t1)
上级 44f68fc7
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.124 2002/09/04 20:31:21 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.125 2002/09/24 18:38:23 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -337,17 +337,23 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join) ...@@ -337,17 +337,23 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join)
/* /*
* Now make a modifiable copy of the subquery that we can run * Now make a modifiable copy of the subquery that we can run
* OffsetVarNodes on. * OffsetVarNodes and IncrementVarSublevelsUp on.
*/ */
subquery = copyObject(subquery); subquery = copyObject(subquery);
/* /*
* Adjust varnos in subquery so that we can append its * Adjust level-0 varnos in subquery so that we can append its
* rangetable to upper query's. * rangetable to upper query's.
*/ */
rtoffset = length(parse->rtable); rtoffset = length(parse->rtable);
OffsetVarNodes((Node *) subquery, rtoffset, 0); OffsetVarNodes((Node *) subquery, rtoffset, 0);
/*
* Upper-level vars in subquery are now one level closer to their
* parent than before.
*/
IncrementVarSublevelsUp((Node *) subquery, -1, 1);
/* /*
* Replace all of the top query's references to the subquery's * Replace all of the top query's references to the subquery's
* outputs with copies of the adjusted subtlist items, being * outputs with copies of the adjusted subtlist items, being
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册