1 /*-------------------------------------------------------------------------
2  *
3  * nodeFuncs.h
4  *		Various general-purpose manipulations of Node trees
5  *
6  * Portions Copyright (c) 1996-2016, 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			0x10		/* examine RTEs */
26 #define QTW_DONT_COPY_QUERY			0x20		/* do not copy top Query */
27 #define QTW_EXAMINE_SORTGROUP		0x80	/* include SortGroupNode lists */
28 
29 /* callback function for check_functions_in_node */
30 typedef bool (*check_function_callback) (Oid func_id, void *context);
31 
32 
33 extern Oid	exprType(const Node *expr);
34 extern int32 exprTypmod(const Node *expr);
35 extern bool exprIsLengthCoercion(const Node *expr, int32 *coercedTypmod);
36 extern Node *relabel_to_typmod(Node *expr, int32 typmod);
37 extern Node *strip_implicit_coercions(Node *node);
38 extern bool expression_returns_set(Node *clause);
39 
40 extern Oid	exprCollation(const Node *expr);
41 extern Oid	exprInputCollation(const Node *expr);
42 extern void exprSetCollation(Node *expr, Oid collation);
43 extern void exprSetInputCollation(Node *expr, Oid inputcollation);
44 
45 extern int	exprLocation(const Node *expr);
46 
47 extern void fix_opfuncids(Node *node);
48 extern void set_opfuncid(OpExpr *opexpr);
49 extern void set_sa_opfuncid(ScalarArrayOpExpr *opexpr);
50 
51 extern bool check_functions_in_node(Node *node, check_function_callback checker,
52 						void *context);
53 
54 extern bool expression_tree_walker(Node *node, bool (*walker) (),
55 											   void *context);
56 extern Node *expression_tree_mutator(Node *node, Node *(*mutator) (),
57 												 void *context);
58 
59 extern bool query_tree_walker(Query *query, bool (*walker) (),
60 										  void *context, int flags);
61 extern Query *query_tree_mutator(Query *query, Node *(*mutator) (),
62 											 void *context, int flags);
63 
64 extern bool range_table_walker(List *rtable, bool (*walker) (),
65 										   void *context, int flags);
66 extern List *range_table_mutator(List *rtable, Node *(*mutator) (),
67 											 void *context, int flags);
68 
69 extern bool query_or_expression_tree_walker(Node *node, bool (*walker) (),
70 												   void *context, int flags);
71 extern Node *query_or_expression_tree_mutator(Node *node, Node *(*mutator) (),
72 												   void *context, int flags);
73 
74 extern bool raw_expression_tree_walker(Node *node, bool (*walker) (),
75 												   void *context);
76 
77 struct PlanState;
78 extern bool planstate_tree_walker(struct PlanState *planstate, bool (*walker) (),
79 											  void *context);
80 
81 #endif   /* NODEFUNCS_H */
82