mirror of
https://github.com/postgres/postgres.git
synced 2025-06-29 10:41:53 +03:00
Refactor to reduce code duplication for function property checking.
As noted by Andres Freund, we'd accumulated quite a few similar functions in clauses.c that examine all functions in an expression tree to see if they satisfy some boolean test. Reduce the duplication by inventing a function check_functions_in_node() that applies a simple callback function to each SQL function OID appearing in a given expression node. This also fixes some arguable oversights; for example, contain_mutable_functions() did not check aggregate or window functions for mutability. I doubt that that represents a live bug at the moment, because we don't really consider mutability for aggregates; but it might someday be one. I chose to put check_functions_in_node() in nodeFuncs.c because it seemed like other modules might wish to use it in future. That in turn forced moving set_opfuncid() et al into nodeFuncs.c, as the alternative was for nodeFuncs.c to depend on optimizer/setrefs.c which didn't seem very clean. In passing, teach contain_leaked_vars_walker() about a few more expression node types it can safely look through, and improve the rather messy and undercommented code in has_parallel_hazard_walker(). Discussion: <20160527185853.ziol2os2zskahl7v@alap3.anarazel.de>
This commit is contained in:
@ -147,7 +147,6 @@ static List *set_returning_clause_references(PlannerInfo *root,
|
||||
Plan *topplan,
|
||||
Index resultRelation,
|
||||
int rtoffset);
|
||||
static bool fix_opfuncids_walker(Node *node, void *context);
|
||||
static bool extract_query_dependencies_walker(Node *node,
|
||||
PlannerInfo *context);
|
||||
|
||||
@ -2556,68 +2555,6 @@ set_returning_clause_references(PlannerInfo *root,
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* OPERATOR REGPROC LOOKUP
|
||||
*****************************************************************************/
|
||||
|
||||
/*
|
||||
* fix_opfuncids
|
||||
* Calculate opfuncid field from opno for each OpExpr node in given tree.
|
||||
* The given tree can be anything expression_tree_walker handles.
|
||||
*
|
||||
* The argument is modified in-place. (This is OK since we'd want the
|
||||
* same change for any node, even if it gets visited more than once due to
|
||||
* shared structure.)
|
||||
*/
|
||||
void
|
||||
fix_opfuncids(Node *node)
|
||||
{
|
||||
/* This tree walk requires no special setup, so away we go... */
|
||||
fix_opfuncids_walker(node, NULL);
|
||||
}
|
||||
|
||||
static bool
|
||||
fix_opfuncids_walker(Node *node, void *context)
|
||||
{
|
||||
if (node == NULL)
|
||||
return false;
|
||||
if (IsA(node, OpExpr))
|
||||
set_opfuncid((OpExpr *) node);
|
||||
else if (IsA(node, DistinctExpr))
|
||||
set_opfuncid((OpExpr *) node); /* rely on struct equivalence */
|
||||
else if (IsA(node, NullIfExpr))
|
||||
set_opfuncid((OpExpr *) node); /* rely on struct equivalence */
|
||||
else if (IsA(node, ScalarArrayOpExpr))
|
||||
set_sa_opfuncid((ScalarArrayOpExpr *) node);
|
||||
return expression_tree_walker(node, fix_opfuncids_walker, context);
|
||||
}
|
||||
|
||||
/*
|
||||
* set_opfuncid
|
||||
* Set the opfuncid (procedure OID) in an OpExpr node,
|
||||
* if it hasn't been set already.
|
||||
*
|
||||
* Because of struct equivalence, this can also be used for
|
||||
* DistinctExpr and NullIfExpr nodes.
|
||||
*/
|
||||
void
|
||||
set_opfuncid(OpExpr *opexpr)
|
||||
{
|
||||
if (opexpr->opfuncid == InvalidOid)
|
||||
opexpr->opfuncid = get_opcode(opexpr->opno);
|
||||
}
|
||||
|
||||
/*
|
||||
* set_sa_opfuncid
|
||||
* As above, for ScalarArrayOpExpr nodes.
|
||||
*/
|
||||
void
|
||||
set_sa_opfuncid(ScalarArrayOpExpr *opexpr)
|
||||
{
|
||||
if (opexpr->opfuncid == InvalidOid)
|
||||
opexpr->opfuncid = get_opcode(opexpr->opno);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* QUERY DEPENDENCY MANAGEMENT
|
||||
*****************************************************************************/
|
||||
|
Reference in New Issue
Block a user