1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-07 19:06:32 +03:00

Tweak querytree-dependency-extraction code so that columns of tables

that are explicitly JOINed are not considered dependencies unless they
are actually used in the query: mere presence in the joinaliasvars
list of a JOIN RTE doesn't count as being used.  The patch touches
a number of files because I needed to generalize the API of
query_tree_walker to support an additional flag bit, but the changes
are otherwise quite small.
This commit is contained in:
Tom Lane
2002-09-11 14:48:55 +00:00
parent d634a5903f
commit 6fdc44be71
8 changed files with 89 additions and 55 deletions

View File

@@ -14,7 +14,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.78 2002/09/04 20:31:22 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.79 2002/09/11 14:48:55 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -774,7 +774,7 @@ adjust_inherited_attrs(Node *node,
if (newnode->resultRelation == old_rt_index)
newnode->resultRelation = new_rt_index;
query_tree_mutator(newnode, adjust_inherited_attrs_mutator,
(void *) &context, false);
(void *) &context, QTW_IGNORE_SUBQUERIES);
return (Node *) newnode;
}
else

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.108 2002/09/04 20:31:22 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.109 2002/09/11 14:48:54 tgl Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
@@ -1788,7 +1788,7 @@ simplify_op_or_func(Expr *expr, List *args)
* {
* adjust context for subquery;
* result = query_tree_walker((Query *) node, my_walker, context,
* true); // to visit subquery RTEs too
* 0); // to visit rtable items too
* restore context if needed;
* return result;
* }
@@ -1994,16 +1994,17 @@ expression_tree_walker(Node *node,
* walker intends to descend into subqueries. It is also useful for
* descending into subqueries within a walker.
*
* If visitQueryRTEs is true, the walker will also be called on sub-Query
* nodes present in subquery rangetable entries of the given Query. This
* is optional since some callers handle those sub-queries separately,
* or don't really want to see subqueries anyway.
* Some callers want to suppress visitation of certain items in the sub-Query,
* typically because they need to process them specially, or don't actually
* want to recurse into subqueries. This is supported by the flags argument,
* which is the bitwise OR of flag values to suppress visitation of
* indicated items. (More flag bits may be added as needed.)
*/
bool
query_tree_walker(Query *query,
bool (*walker) (),
void *context,
bool visitQueryRTEs)
int flags)
{
List *rt;
@@ -2028,13 +2029,14 @@ query_tree_walker(Query *query,
/* nothing to do */
break;
case RTE_SUBQUERY:
if (visitQueryRTEs)
if (! (flags & QTW_IGNORE_SUBQUERIES))
if (walker(rte->subquery, context))
return true;
break;
case RTE_JOIN:
if (walker(rte->joinaliasvars, context))
return true;
if (! (flags & QTW_IGNORE_JOINALIASES))
if (walker(rte->joinaliasvars, context))
return true;
break;
case RTE_FUNCTION:
if (walker(rte->funcexpr, context))
@@ -2388,16 +2390,17 @@ expression_tree_mutator(Node *node,
* if you don't want to change the original. All substructure is safely
* copied, however.
*
* If visitQueryRTEs is true, the mutator will also be called on sub-Query
* nodes present in subquery rangetable entries of the given Query. This
* is optional since some callers handle those sub-queries separately,
* or don't really want to see subqueries anyway.
* Some callers want to suppress mutating of certain items in the sub-Query,
* typically because they need to process them specially, or don't actually
* want to recurse into subqueries. This is supported by the flags argument,
* which is the bitwise OR of flag values to suppress mutating of
* indicated items. (More flag bits may be added as needed.)
*/
void
query_tree_mutator(Query *query,
Node *(*mutator) (),
void *context,
bool visitQueryRTEs)
int flags)
{
List *newrt = NIL;
List *rt;
@@ -2420,7 +2423,7 @@ query_tree_mutator(Query *query,
/* nothing to do, don't bother to make a copy */
break;
case RTE_SUBQUERY:
if (visitQueryRTEs)
if (! (flags & QTW_IGNORE_SUBQUERIES))
{
FLATCOPY(newrte, rte, RangeTblEntry);
CHECKFLATCOPY(newrte->subquery, rte->subquery, Query);
@@ -2429,9 +2432,12 @@ query_tree_mutator(Query *query,
}
break;
case RTE_JOIN:
FLATCOPY(newrte, rte, RangeTblEntry);
MUTATE(newrte->joinaliasvars, rte->joinaliasvars, List *);
rte = newrte;
if (! (flags & QTW_IGNORE_JOINALIASES))
{
FLATCOPY(newrte, rte, RangeTblEntry);
MUTATE(newrte->joinaliasvars, rte->joinaliasvars, List *);
rte = newrte;
}
break;
case RTE_FUNCTION:
FLATCOPY(newrte, rte, RangeTblEntry);

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/var.c,v 1.39 2002/09/04 20:31:22 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/var.c,v 1.40 2002/09/11 14:48:54 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -82,7 +82,7 @@ pull_varnos(Node *node)
*/
if (node && IsA(node, Query))
query_tree_walker((Query *) node, pull_varnos_walker,
(void *) &context, true);
(void *) &context, 0);
else
pull_varnos_walker(node, &context);
@@ -128,7 +128,7 @@ pull_varnos_walker(Node *node, pull_varnos_context *context)
context->sublevels_up++;
result = query_tree_walker((Query *) node, pull_varnos_walker,
(void *) context, true);
(void *) context, 0);
context->sublevels_up--;
return result;
}
@@ -165,7 +165,7 @@ contain_var_reference(Node *node, int varno, int varattno, int levelsup)
if (node && IsA(node, Query))
return query_tree_walker((Query *) node,
contain_var_reference_walker,
(void *) &context, true);
(void *) &context, 0);
else
return contain_var_reference_walker(node, &context);
}
@@ -212,7 +212,7 @@ contain_var_reference_walker(Node *node,
context->sublevels_up++;
result = query_tree_walker((Query *) node,
contain_var_reference_walker,
(void *) context, true);
(void *) context, 0);
context->sublevels_up--;
return result;
}