PostgreSQL Source Code  git master
nodeFuncs.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * nodeFuncs.h
4  * Various general-purpose manipulations of Node trees
5  *
6  * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  * src/include/nodes/nodeFuncs.h
10  *
11  *-------------------------------------------------------------------------
12  */
13 #ifndef NODEFUNCS_H
14 #define NODEFUNCS_H
15 
16 #include "nodes/parsenodes.h"
17 
18 
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
26  * contents */
27 #define QTW_EXAMINE_RTES_AFTER 0x20 /* examine RTE nodes after their
28  * contents */
29 #define QTW_DONT_COPY_QUERY 0x40 /* do not copy top Query */
30 #define QTW_EXAMINE_SORTGROUP 0x80 /* include SortGroupNode lists */
31 
32 /* callback function for check_functions_in_node */
33 typedef bool (*check_function_callback) (Oid func_id, void *context);
34 
35 
36 extern Oid exprType(const Node *expr);
37 extern int32 exprTypmod(const Node *expr);
38 extern bool exprIsLengthCoercion(const Node *expr, int32 *coercedTypmod);
39 extern Node *applyRelabelType(Node *arg, Oid rtype, int32 rtypmod, Oid rcollid,
40  CoercionForm rformat, int rlocation,
41  bool overwrite_ok);
42 extern Node *relabel_to_typmod(Node *expr, int32 typmod);
43 extern Node *strip_implicit_coercions(Node *node);
44 extern bool expression_returns_set(Node *clause);
45 
46 extern Oid exprCollation(const Node *expr);
47 extern Oid exprInputCollation(const Node *expr);
48 extern void exprSetCollation(Node *expr, Oid collation);
49 extern void exprSetInputCollation(Node *expr, Oid inputcollation);
50 
51 extern int exprLocation(const Node *expr);
52 
53 extern void fix_opfuncids(Node *node);
54 extern void set_opfuncid(OpExpr *opexpr);
55 extern void set_sa_opfuncid(ScalarArrayOpExpr *opexpr);
56 
57 /* Is clause a FuncExpr clause? */
58 static inline bool
59 is_funcclause(const void *clause)
60 {
61  return clause != NULL && IsA(clause, FuncExpr);
62 }
63 
64 /* Is clause an OpExpr clause? */
65 static inline bool
66 is_opclause(const void *clause)
67 {
68  return clause != NULL && IsA(clause, OpExpr);
69 }
70 
71 /* Extract left arg of a binary opclause, or only arg of a unary opclause */
72 static inline Node *
73 get_leftop(const void *clause)
74 {
75  const OpExpr *expr = (const OpExpr *) clause;
76 
77  if (expr->args != NIL)
78  return (Node *) linitial(expr->args);
79  else
80  return NULL;
81 }
82 
83 /* Extract right arg of a binary opclause (NULL if it's a unary opclause) */
84 static inline Node *
85 get_rightop(const void *clause)
86 {
87  const OpExpr *expr = (const OpExpr *) clause;
88 
89  if (list_length(expr->args) >= 2)
90  return (Node *) lsecond(expr->args);
91  else
92  return NULL;
93 }
94 
95 /* Is clause an AND clause? */
96 static inline bool
97 is_andclause(const void *clause)
98 {
99  return (clause != NULL &&
100  IsA(clause, BoolExpr) &&
101  ((const BoolExpr *) clause)->boolop == AND_EXPR);
102 }
103 
104 /* Is clause an OR clause? */
105 static inline bool
106 is_orclause(const void *clause)
107 {
108  return (clause != NULL &&
109  IsA(clause, BoolExpr) &&
110  ((const BoolExpr *) clause)->boolop == OR_EXPR);
111 }
112 
113 /* Is clause a NOT clause? */
114 static inline bool
115 is_notclause(const void *clause)
116 {
117  return (clause != NULL &&
118  IsA(clause, BoolExpr) &&
119  ((const BoolExpr *) clause)->boolop == NOT_EXPR);
120 }
121 
122 /* Extract argument from a clause known to be a NOT clause */
123 static inline Expr *
124 get_notclausearg(const void *notclause)
125 {
126  return (Expr *) linitial(((const BoolExpr *) notclause)->args);
127 }
128 
129 extern bool check_functions_in_node(Node *node, check_function_callback checker,
130  void *context);
131 
132 extern bool expression_tree_walker(Node *node, bool (*walker) (),
133  void *context);
134 extern Node *expression_tree_mutator(Node *node, Node *(*mutator) (),
135  void *context);
136 
137 extern bool query_tree_walker(Query *query, bool (*walker) (),
138  void *context, int flags);
139 extern Query *query_tree_mutator(Query *query, Node *(*mutator) (),
140  void *context, int flags);
141 
142 extern bool range_table_walker(List *rtable, bool (*walker) (),
143  void *context, int flags);
144 extern List *range_table_mutator(List *rtable, Node *(*mutator) (),
145  void *context, int flags);
146 
147 extern bool range_table_entry_walker(RangeTblEntry *rte, bool (*walker) (),
148  void *context, int flags);
149 
150 extern bool query_or_expression_tree_walker(Node *node, bool (*walker) (),
151  void *context, int flags);
152 extern Node *query_or_expression_tree_mutator(Node *node, Node *(*mutator) (),
153  void *context, int flags);
154 
155 extern bool raw_expression_tree_walker(Node *node, bool (*walker) (),
156  void *context);
157 
158 struct PlanState;
159 extern bool planstate_tree_walker(struct PlanState *planstate, bool (*walker) (),
160  void *context);
161 
162 #endif /* NODEFUNCS_H */
Query * query_tree_mutator(Query *query, Node *(*mutator)(), void *context, int flags)
Definition: nodeFuncs.c:3251
#define NIL
Definition: pg_list.h:65
Datum boolop(PG_FUNCTION_ARGS)
Definition: _int_bool.c:419
#define IsA(nodeptr, _type_)
Definition: nodes.h:579
Node * relabel_to_typmod(Node *expr, int32 typmod)
Definition: nodeFuncs.c:644
static bool is_orclause(const void *clause)
Definition: nodeFuncs.h:106
static bool is_andclause(const void *clause)
Definition: nodeFuncs.h:97
Definition: nodes.h:528
unsigned int Oid
Definition: postgres_ext.h:31
Node * expression_tree_mutator(Node *node, Node *(*mutator)(), void *context)
Definition: nodeFuncs.c:2565
bool planstate_tree_walker(struct PlanState *planstate, bool(*walker)(), void *context)
Definition: nodeFuncs.c:3931
#define lsecond(l)
Definition: pg_list.h:179
signed int int32
Definition: c.h:363
static bool is_funcclause(const void *clause)
Definition: nodeFuncs.h:59
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:41
Node * applyRelabelType(Node *arg, Oid rtype, int32 rtypmod, Oid rcollid, CoercionForm rformat, int rlocation, bool overwrite_ok)
Definition: nodeFuncs.c:591
#define linitial(l)
Definition: pg_list.h:174
void fix_opfuncids(Node *node)
Definition: nodeFuncs.c:1636
bool exprIsLengthCoercion(const Node *expr, int32 *coercedTypmod)
Definition: nodeFuncs.c:512
bool check_functions_in_node(Node *node, check_function_callback checker, void *context)
Definition: nodeFuncs.c:1705
Node * query_or_expression_tree_mutator(Node *node, Node *(*mutator)(), void *context, int flags)
Definition: nodeFuncs.c:3435
static Node * get_leftop(const void *clause)
Definition: nodeFuncs.h:73
Oid exprCollation(const Node *expr)
Definition: nodeFuncs.c:768
void set_sa_opfuncid(ScalarArrayOpExpr *opexpr)
Definition: nodeFuncs.c:1678
bool raw_expression_tree_walker(Node *node, bool(*walker)(), void *context)
Definition: nodeFuncs.c:3466
int32 exprTypmod(const Node *expr)
Definition: nodeFuncs.c:275
Node * strip_implicit_coercions(Node *node)
Definition: nodeFuncs.c:660
bool expression_returns_set(Node *clause)
Definition: nodeFuncs.c:718
static bool is_notclause(const void *clause)
Definition: nodeFuncs.h:115
bool query_tree_walker(Query *query, bool(*walker)(), void *context, int flags)
Definition: nodeFuncs.c:2322
bool expression_tree_walker(Node *node, bool(*walker)(), void *context)
Definition: nodeFuncs.c:1888
void exprSetInputCollation(Node *expr, Oid inputcollation)
Definition: nodeFuncs.c:1176
Oid exprInputCollation(const Node *expr)
Definition: nodeFuncs.c:973
static Node * get_rightop(const void *clause)
Definition: nodeFuncs.h:85
List * range_table_mutator(List *rtable, Node *(*mutator)(), void *context, int flags)
Definition: nodeFuncs.c:3340
int exprLocation(const Node *expr)
Definition: nodeFuncs.c:1240
static Expr * get_notclausearg(const void *notclause)
Definition: nodeFuncs.h:124
bool query_or_expression_tree_walker(Node *node, bool(*walker)(), void *context, int flags)
Definition: nodeFuncs.c:3412
static int list_length(const List *l)
Definition: pg_list.h:149
bool(* check_function_callback)(Oid func_id, void *context)
Definition: nodeFuncs.h:33
bool range_table_entry_walker(RangeTblEntry *rte, bool(*walker)(), void *context, int flags)
Definition: nodeFuncs.c:2442
void exprSetCollation(Node *expr, Oid collation)
Definition: nodeFuncs.c:1021
void * arg
bool range_table_walker(List *rtable, bool(*walker)(), void *context, int flags)
Definition: nodeFuncs.c:2421
void set_opfuncid(OpExpr *opexpr)
Definition: nodeFuncs.c:1667
static bool is_opclause(const void *clause)
Definition: nodeFuncs.h:66
List * args
Definition: primnodes.h:522
CoercionForm
Definition: primnodes.h:456
Definition: pg_list.h:50
unsigned char bool
Definition: c.h:325