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-2019, 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 
31 /* callback function for check_functions_in_node */
32 typedef bool (*check_function_callback) (Oid func_id, void *context);
33 
34 
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);
41 
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);
46 
47 extern int exprLocation(const Node *expr);
48 
49 extern void fix_opfuncids(Node *node);
50 extern void set_opfuncid(OpExpr *opexpr);
51 extern void set_sa_opfuncid(ScalarArrayOpExpr *opexpr);
52 
53 /* Is clause a FuncExpr clause? */
54 static inline bool
55 is_funcclause(const void *clause)
56 {
57  return clause != NULL && IsA(clause, FuncExpr);
58 }
59 
60 /* Is clause an OpExpr clause? */
61 static inline bool
62 is_opclause(const void *clause)
63 {
64  return clause != NULL && IsA(clause, OpExpr);
65 }
66 
67 /* Extract left arg of a binary opclause, or only arg of a unary opclause */
68 static inline Node *
69 get_leftop(const void *clause)
70 {
71  const OpExpr *expr = (const OpExpr *) clause;
72 
73  if (expr->args != NIL)
74  return (Node *) linitial(expr->args);
75  else
76  return NULL;
77 }
78 
79 /* Extract right arg of a binary opclause (NULL if it's a unary opclause) */
80 static inline Node *
81 get_rightop(const void *clause)
82 {
83  const OpExpr *expr = (const OpExpr *) clause;
84 
85  if (list_length(expr->args) >= 2)
86  return (Node *) lsecond(expr->args);
87  else
88  return NULL;
89 }
90 
91 /* Is clause an AND clause? */
92 static inline bool
93 is_andclause(const void *clause)
94 {
95  return (clause != NULL &&
96  IsA(clause, BoolExpr) &&
97  ((const BoolExpr *) clause)->boolop == AND_EXPR);
98 }
99 
100 /* Is clause an OR clause? */
101 static inline bool
102 is_orclause(const void *clause)
103 {
104  return (clause != NULL &&
105  IsA(clause, BoolExpr) &&
106  ((const BoolExpr *) clause)->boolop == OR_EXPR);
107 }
108 
109 /* Is clause a NOT clause? */
110 static inline bool
111 is_notclause(const void *clause)
112 {
113  return (clause != NULL &&
114  IsA(clause, BoolExpr) &&
115  ((const BoolExpr *) clause)->boolop == NOT_EXPR);
116 }
117 
118 /* Extract argument from a clause known to be a NOT clause */
119 static inline Expr *
120 get_notclausearg(const void *notclause)
121 {
122  return (Expr *) linitial(((const BoolExpr *) notclause)->args);
123 }
124 
125 extern bool check_functions_in_node(Node *node, check_function_callback checker,
126  void *context);
127 
128 extern bool expression_tree_walker(Node *node, bool (*walker) (),
129  void *context);
130 extern Node *expression_tree_mutator(Node *node, Node *(*mutator) (),
131  void *context);
132 
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);
137 
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);
142 
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);
147 
148 extern bool raw_expression_tree_walker(Node *node, bool (*walker) (),
149  void *context);
150 
151 struct PlanState;
152 extern bool planstate_tree_walker(struct PlanState *planstate, bool (*walker) (),
153  void *context);
154 
155 #endif /* NODEFUNCS_H */
Query * query_tree_mutator(Query *query, Node *(*mutator)(), void *context, int flags)
Definition: nodeFuncs.c:3132
#define NIL
Definition: pg_list.h:65
Datum boolop(PG_FUNCTION_ARGS)
Definition: _int_bool.c:420
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
Node * relabel_to_typmod(Node *expr, int32 typmod)
Definition: nodeFuncs.c:588
static bool is_orclause(const void *clause)
Definition: nodeFuncs.h:102
static bool is_andclause(const void *clause)
Definition: nodeFuncs.h:93
Definition: nodes.h:525
unsigned int Oid
Definition: postgres_ext.h:31
Node * expression_tree_mutator(Node *node, Node *(*mutator)(), void *context)
Definition: nodeFuncs.c:2447
bool planstate_tree_walker(struct PlanState *planstate, bool(*walker)(), void *context)
Definition: nodeFuncs.c:3762
#define lsecond(l)
Definition: pg_list.h:200
signed int int32
Definition: c.h:346
static bool is_funcclause(const void *clause)
Definition: nodeFuncs.h:55
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:42
#define linitial(l)
Definition: pg_list.h:195
void fix_opfuncids(Node *node)
Definition: nodeFuncs.c:1588
bool exprIsLengthCoercion(const Node *expr, int32 *coercedTypmod)
Definition: nodeFuncs.c:513
bool check_functions_in_node(Node *node, check_function_callback checker, void *context)
Definition: nodeFuncs.c:1657
Node * query_or_expression_tree_mutator(Node *node, Node *(*mutator)(), void *context, int flags)
Definition: nodeFuncs.c:3266
static Node * get_leftop(const void *clause)
Definition: nodeFuncs.h:69
Oid exprCollation(const Node *expr)
Definition: nodeFuncs.c:720
void set_sa_opfuncid(ScalarArrayOpExpr *opexpr)
Definition: nodeFuncs.c:1630
bool raw_expression_tree_walker(Node *node, bool(*walker)(), void *context)
Definition: nodeFuncs.c:3297
int32 exprTypmod(const Node *expr)
Definition: nodeFuncs.c:276
Node * strip_implicit_coercions(Node *node)
Definition: nodeFuncs.c:612
bool expression_returns_set(Node *clause)
Definition: nodeFuncs.c:670
static bool is_notclause(const void *clause)
Definition: nodeFuncs.h:111
bool query_tree_walker(Query *query, bool(*walker)(), void *context, int flags)
Definition: nodeFuncs.c:2274
bool expression_tree_walker(Node *node, bool(*walker)(), void *context)
Definition: nodeFuncs.c:1840
void exprSetInputCollation(Node *expr, Oid inputcollation)
Definition: nodeFuncs.c:1128
Oid exprInputCollation(const Node *expr)
Definition: nodeFuncs.c:925
static Node * get_rightop(const void *clause)
Definition: nodeFuncs.h:81
List * range_table_mutator(List *rtable, Node *(*mutator)(), void *context, int flags)
Definition: nodeFuncs.c:3171
int exprLocation(const Node *expr)
Definition: nodeFuncs.c:1192
static Expr * get_notclausearg(const void *notclause)
Definition: nodeFuncs.h:120
bool query_or_expression_tree_walker(Node *node, bool(*walker)(), void *context, int flags)
Definition: nodeFuncs.c:3243
static int list_length(const List *l)
Definition: pg_list.h:169
bool(* check_function_callback)(Oid func_id, void *context)
Definition: nodeFuncs.h:32
void exprSetCollation(Node *expr, Oid collation)
Definition: nodeFuncs.c:973
bool range_table_walker(List *rtable, bool(*walker)(), void *context, int flags)
Definition: nodeFuncs.c:2318
void set_opfuncid(OpExpr *opexpr)
Definition: nodeFuncs.c:1619
static bool is_opclause(const void *clause)
Definition: nodeFuncs.h:62
List * args
Definition: primnodes.h:508
Definition: pg_list.h:50
unsigned char bool
Definition: c.h:308