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 #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 *relabel_to_typmod(Node *expr, int32 typmod);
40 extern Node *strip_implicit_coercions(Node *node);
41 extern bool expression_returns_set(Node *clause);
42 
43 extern Oid exprCollation(const Node *expr);
44 extern Oid exprInputCollation(const Node *expr);
45 extern void exprSetCollation(Node *expr, Oid collation);
46 extern void exprSetInputCollation(Node *expr, Oid inputcollation);
47 
48 extern int exprLocation(const Node *expr);
49 
50 extern void fix_opfuncids(Node *node);
51 extern void set_opfuncid(OpExpr *opexpr);
52 extern void set_sa_opfuncid(ScalarArrayOpExpr *opexpr);
53 
54 /* Is clause a FuncExpr clause? */
55 static inline bool
56 is_funcclause(const void *clause)
57 {
58  return clause != NULL && IsA(clause, FuncExpr);
59 }
60 
61 /* Is clause an OpExpr clause? */
62 static inline bool
63 is_opclause(const void *clause)
64 {
65  return clause != NULL && IsA(clause, OpExpr);
66 }
67 
68 /* Extract left arg of a binary opclause, or only arg of a unary opclause */
69 static inline Node *
70 get_leftop(const void *clause)
71 {
72  const OpExpr *expr = (const OpExpr *) clause;
73 
74  if (expr->args != NIL)
75  return (Node *) linitial(expr->args);
76  else
77  return NULL;
78 }
79 
80 /* Extract right arg of a binary opclause (NULL if it's a unary opclause) */
81 static inline Node *
82 get_rightop(const void *clause)
83 {
84  const OpExpr *expr = (const OpExpr *) clause;
85 
86  if (list_length(expr->args) >= 2)
87  return (Node *) lsecond(expr->args);
88  else
89  return NULL;
90 }
91 
92 /* Is clause an AND clause? */
93 static inline bool
94 is_andclause(const void *clause)
95 {
96  return (clause != NULL &&
97  IsA(clause, BoolExpr) &&
98  ((const BoolExpr *) clause)->boolop == AND_EXPR);
99 }
100 
101 /* Is clause an OR clause? */
102 static inline bool
103 is_orclause(const void *clause)
104 {
105  return (clause != NULL &&
106  IsA(clause, BoolExpr) &&
107  ((const BoolExpr *) clause)->boolop == OR_EXPR);
108 }
109 
110 /* Is clause a NOT clause? */
111 static inline bool
112 is_notclause(const void *clause)
113 {
114  return (clause != NULL &&
115  IsA(clause, BoolExpr) &&
116  ((const BoolExpr *) clause)->boolop == NOT_EXPR);
117 }
118 
119 /* Extract argument from a clause known to be a NOT clause */
120 static inline Expr *
121 get_notclausearg(const void *notclause)
122 {
123  return (Expr *) linitial(((const BoolExpr *) notclause)->args);
124 }
125 
126 extern bool check_functions_in_node(Node *node, check_function_callback checker,
127  void *context);
128 
129 extern bool expression_tree_walker(Node *node, bool (*walker) (),
130  void *context);
131 extern Node *expression_tree_mutator(Node *node, Node *(*mutator) (),
132  void *context);
133 
134 extern bool query_tree_walker(Query *query, bool (*walker) (),
135  void *context, int flags);
136 extern Query *query_tree_mutator(Query *query, Node *(*mutator) (),
137  void *context, int flags);
138 
139 extern bool range_table_walker(List *rtable, bool (*walker) (),
140  void *context, int flags);
141 extern List *range_table_mutator(List *rtable, Node *(*mutator) (),
142  void *context, int flags);
143 
144 extern bool query_or_expression_tree_walker(Node *node, bool (*walker) (),
145  void *context, int flags);
146 extern Node *query_or_expression_tree_mutator(Node *node, Node *(*mutator) (),
147  void *context, int flags);
148 
149 extern bool raw_expression_tree_walker(Node *node, bool (*walker) (),
150  void *context);
151 
152 struct PlanState;
153 extern bool planstate_tree_walker(struct PlanState *planstate, bool (*walker) (),
154  void *context);
155 
156 #endif /* NODEFUNCS_H */
Query * query_tree_mutator(Query *query, Node *(*mutator)(), void *context, int flags)
Definition: nodeFuncs.c:3186
#define NIL
Definition: pg_list.h:65
Datum boolop(PG_FUNCTION_ARGS)
Definition: _int_bool.c:419
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
Node * relabel_to_typmod(Node *expr, int32 typmod)
Definition: nodeFuncs.c:587
static bool is_orclause(const void *clause)
Definition: nodeFuncs.h:103
static bool is_andclause(const void *clause)
Definition: nodeFuncs.h:94
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:2501
bool planstate_tree_walker(struct PlanState *planstate, bool(*walker)(), void *context)
Definition: nodeFuncs.c:3866
#define lsecond(l)
Definition: pg_list.h:200
signed int int32
Definition: c.h:347
static bool is_funcclause(const void *clause)
Definition: nodeFuncs.h:56
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:41
#define linitial(l)
Definition: pg_list.h:195
void fix_opfuncids(Node *node)
Definition: nodeFuncs.c:1587
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:1656
Node * query_or_expression_tree_mutator(Node *node, Node *(*mutator)(), void *context, int flags)
Definition: nodeFuncs.c:3370
static Node * get_leftop(const void *clause)
Definition: nodeFuncs.h:70
Oid exprCollation(const Node *expr)
Definition: nodeFuncs.c:719
void set_sa_opfuncid(ScalarArrayOpExpr *opexpr)
Definition: nodeFuncs.c:1629
bool raw_expression_tree_walker(Node *node, bool(*walker)(), void *context)
Definition: nodeFuncs.c:3401
int32 exprTypmod(const Node *expr)
Definition: nodeFuncs.c:275
Node * strip_implicit_coercions(Node *node)
Definition: nodeFuncs.c:611
bool expression_returns_set(Node *clause)
Definition: nodeFuncs.c:669
static bool is_notclause(const void *clause)
Definition: nodeFuncs.h:112
bool query_tree_walker(Query *query, bool(*walker)(), void *context, int flags)
Definition: nodeFuncs.c:2273
bool expression_tree_walker(Node *node, bool(*walker)(), void *context)
Definition: nodeFuncs.c:1839
void exprSetInputCollation(Node *expr, Oid inputcollation)
Definition: nodeFuncs.c:1127
Oid exprInputCollation(const Node *expr)
Definition: nodeFuncs.c:924
static Node * get_rightop(const void *clause)
Definition: nodeFuncs.h:82
List * range_table_mutator(List *rtable, Node *(*mutator)(), void *context, int flags)
Definition: nodeFuncs.c:3275
int exprLocation(const Node *expr)
Definition: nodeFuncs.c:1191
static Expr * get_notclausearg(const void *notclause)
Definition: nodeFuncs.h:121
bool query_or_expression_tree_walker(Node *node, bool(*walker)(), void *context, int flags)
Definition: nodeFuncs.c:3347
static int list_length(const List *l)
Definition: pg_list.h:169
bool(* check_function_callback)(Oid func_id, void *context)
Definition: nodeFuncs.h:33
void exprSetCollation(Node *expr, Oid collation)
Definition: nodeFuncs.c:972
bool range_table_walker(List *rtable, bool(*walker)(), void *context, int flags)
Definition: nodeFuncs.c:2372
void set_opfuncid(OpExpr *opexpr)
Definition: nodeFuncs.c:1618
static bool is_opclause(const void *clause)
Definition: nodeFuncs.h:63
List * args
Definition: primnodes.h:508
Definition: pg_list.h:50
unsigned char bool
Definition: c.h:309