1 /*-------------------------------------------------------------------------
4 * Various general-purpose manipulations of Node trees
6 * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
9 * src/include/nodes/nodeFuncs.h
11 *-------------------------------------------------------------------------
16 #include "nodes/parsenodes.h"
19 /* flags bits for query_tree_walker and query_tree_mutator */
20 #define QTW_IGNORE_RT_SUBQUERIES 0x01 /* subqueries in rtable */
21 #define QTW_IGNORE_CTE_SUBQUERIES 0x02 /* subqueries in cteList */
22 #define QTW_IGNORE_RC_SUBQUERIES 0x03 /* both of above */
23 #define QTW_IGNORE_JOINALIASES 0x04 /* JOIN alias var lists */
24 #define QTW_IGNORE_RANGE_TABLE 0x08 /* skip rangetable entirely */
25 #define QTW_EXAMINE_RTES_BEFORE 0x10 /* examine RTE nodes before their
27 #define QTW_EXAMINE_RTES_AFTER 0x20 /* examine RTE nodes after their
29 #define QTW_DONT_COPY_QUERY 0x40 /* do not copy top Query */
31 /* callback function for check_functions_in_node */
32 typedef bool (*check_function_callback) (Oid func_id, void *context);
35 extern Oid exprType(const Node *expr);
36 extern int32 exprTypmod(const Node *expr);
37 extern bool exprIsLengthCoercion(const Node *expr, int32 *coercedTypmod);
38 extern Node *relabel_to_typmod(Node *expr, int32 typmod);
39 extern Node *strip_implicit_coercions(Node *node);
40 extern bool expression_returns_set(Node *clause);
42 extern Oid exprCollation(const Node *expr);
43 extern Oid exprInputCollation(const Node *expr);
44 extern void exprSetCollation(Node *expr, Oid collation);
45 extern void exprSetInputCollation(Node *expr, Oid inputcollation);
47 extern int exprLocation(const Node *expr);
49 extern void fix_opfuncids(Node *node);
50 extern void set_opfuncid(OpExpr *opexpr);
51 extern void set_sa_opfuncid(ScalarArrayOpExpr *opexpr);
53 /* Is clause a FuncExpr clause? */
55 is_funcclause(const void *clause)
57 return clause != NULL && IsA(clause, FuncExpr);
60 /* Is clause an OpExpr clause? */
62 is_opclause(const void *clause)
64 return clause != NULL && IsA(clause, OpExpr);
67 /* Extract left arg of a binary opclause, or only arg of a unary opclause */
69 get_leftop(const void *clause)
71 const OpExpr *expr = (const OpExpr *) clause;
73 if (expr->args != NIL)
74 return (Node *) linitial(expr->args);
79 /* Extract right arg of a binary opclause (NULL if it's a unary opclause) */
81 get_rightop(const void *clause)
83 const OpExpr *expr = (const OpExpr *) clause;
85 if (list_length(expr->args) >= 2)
86 return (Node *) lsecond(expr->args);
91 /* Is clause an AND clause? */
93 is_andclause(const void *clause)
95 return (clause != NULL &&
96 IsA(clause, BoolExpr) &&
97 ((const BoolExpr *) clause)->boolop == AND_EXPR);
100 /* Is clause an OR clause? */
102 is_orclause(const void *clause)
104 return (clause != NULL &&
105 IsA(clause, BoolExpr) &&
106 ((const BoolExpr *) clause)->boolop == OR_EXPR);
109 /* Is clause a NOT clause? */
111 is_notclause(const void *clause)
113 return (clause != NULL &&
114 IsA(clause, BoolExpr) &&
115 ((const BoolExpr *) clause)->boolop == NOT_EXPR);
118 /* Extract argument from a clause known to be a NOT clause */
120 get_notclausearg(const void *notclause)
122 return (Expr *) linitial(((const BoolExpr *) notclause)->args);
125 extern bool check_functions_in_node(Node *node, check_function_callback checker,
128 extern bool expression_tree_walker(Node *node, bool (*walker) (),
130 extern Node *expression_tree_mutator(Node *node, Node *(*mutator) (),
133 extern bool query_tree_walker(Query *query, bool (*walker) (),
134 void *context, int flags);
135 extern Query *query_tree_mutator(Query *query, Node *(*mutator) (),
136 void *context, int flags);
138 extern bool range_table_walker(List *rtable, bool (*walker) (),
139 void *context, int flags);
140 extern List *range_table_mutator(List *rtable, Node *(*mutator) (),
141 void *context, int flags);
143 extern bool query_or_expression_tree_walker(Node *node, bool (*walker) (),
144 void *context, int flags);
145 extern Node *query_or_expression_tree_mutator(Node *node, Node *(*mutator) (),
146 void *context, int flags);
148 extern bool raw_expression_tree_walker(Node *node, bool (*walker) (),
152 extern bool planstate_tree_walker(struct PlanState *planstate, bool (*walker) (),
155 #endif /* NODEFUNCS_H */