mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
Fix problems with rewriter failing to set Query.hasSubLinks when inserting
a SubLink expression into a rule query. Pre-8.1 we essentially did this unconditionally; 8.1 tries to do it only when needed, but was missing a couple of cases. Per report from Kyle Bateman. Add some regression test cases covering this area.
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/rewrite/rewriteHandler.c,v 1.159 2005/11/22 18:17:19 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/rewrite/rewriteHandler.c,v 1.160 2005/11/23 17:21:03 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -374,6 +374,14 @@ rewriteRuleAction(Query *parsetree,
|
||||
|
||||
sub_action->jointree->fromlist =
|
||||
list_concat(newjointree, sub_action->jointree->fromlist);
|
||||
|
||||
/*
|
||||
* There could have been some SubLinks in newjointree, in which
|
||||
* case we'd better mark the sub_action correctly.
|
||||
*/
|
||||
if (parsetree->hasSubLinks && !sub_action->hasSubLinks)
|
||||
sub_action->hasSubLinks =
|
||||
checkExprHasSubLink((Node *) newjointree);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/rewrite/rewriteManip.c,v 1.93 2005/11/22 18:17:19 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/rewrite/rewriteManip.c,v 1.94 2005/11/23 17:21:03 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -930,6 +930,7 @@ ResolveNew(Node *node, int target_varno, int sublevels_up,
|
||||
RangeTblEntry *target_rte,
|
||||
List *targetlist, int event, int update_varno)
|
||||
{
|
||||
Node *result;
|
||||
ResolveNew_context context;
|
||||
|
||||
context.target_varno = target_varno;
|
||||
@@ -944,8 +945,21 @@ ResolveNew(Node *node, int target_varno, int sublevels_up,
|
||||
* Must be prepared to start with a Query or a bare expression tree; if
|
||||
* it's a Query, we don't want to increment sublevels_up.
|
||||
*/
|
||||
return query_or_expression_tree_mutator(node,
|
||||
ResolveNew_mutator,
|
||||
(void *) &context,
|
||||
0);
|
||||
result = query_or_expression_tree_mutator(node,
|
||||
ResolveNew_mutator,
|
||||
(void *) &context,
|
||||
0);
|
||||
|
||||
if (context.inserted_sublink)
|
||||
{
|
||||
if (IsA(result, Query))
|
||||
((Query *) result)->hasSubLinks = true;
|
||||
/*
|
||||
* Note: if we're called on a non-Query node then it's the caller's
|
||||
* responsibility to update hasSubLinks in the ancestor Query.
|
||||
* This is pretty fragile and perhaps should be rethought ...
|
||||
*/
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
Reference in New Issue
Block a user