1/*-------------------------------------------------------------------------
2 *
3 * nodeFuncs.h
4 * Various general-purpose manipulations of PGNode trees
5 *
6 * Portions Copyright (c) 1996-2017, PostgreSQL Global Development PGGroup
7 * Portions Copyright (c) 1994, Regents of the University of California
8 *
9 * src/include/nodes/nodeFuncs.h
10 *
11 *-------------------------------------------------------------------------
12 */
13#pragma once
14
15#include "nodes/parsenodes.hpp"
16
17
18/* flags bits for query_tree_walker and query_tree_mutator */
19#define QTW_IGNORE_RT_SUBQUERIES 0x01 /* subqueries in rtable */
20#define QTW_IGNORE_CTE_SUBQUERIES 0x02 /* subqueries in cteList */
21#define QTW_IGNORE_RC_SUBQUERIES 0x03 /* both of above */
22#define QTW_IGNORE_JOINALIASES 0x04 /* JOIN alias var lists */
23#define QTW_IGNORE_RANGE_TABLE 0x08 /* skip rangetable entirely */
24#define QTW_EXAMINE_RTES 0x10 /* examine RTEs */
25#define QTW_DONT_COPY_QUERY 0x20 /* do not copy top PGQuery */
26
27/* callback function for check_functions_in_node */
28typedef bool (*check_function_callback) (PGOid func_id, void *context);
29
30
31extern PGOid exprType(const PGNode *expr);
32extern int32_t exprTypmod(const PGNode *expr);
33extern bool exprIsLengthCoercion(const PGNode *expr, int32_t *coercedTypmod);
34extern PGNode *relabel_to_typmod(PGNode *expr, int32_t typmod);
35extern PGNode *strip_implicit_coercions(PGNode *node);
36extern bool expression_returns_set(PGNode *clause);
37
38extern PGOid exprCollation(const PGNode *expr);
39extern PGOid exprInputCollation(const PGNode *expr);
40extern void exprSetCollation(PGNode *expr, PGOid collation);
41extern void exprSetInputCollation(PGNode *expr, PGOid inputcollation);
42
43extern int exprLocation(const PGNode *expr);
44
45extern void fix_opfuncids(PGNode *node);
46extern void set_opfuncid(PGOpExpr *opexpr);
47extern void set_sa_opfuncid(PGScalarArrayOpExpr *opexpr);
48
49extern bool check_functions_in_node(PGNode *node, check_function_callback checker,
50 void *context);
51
52extern bool expression_tree_walker(PGNode *node, bool (*walker) (),
53 void *context);
54extern PGNode *expression_tree_mutator(PGNode *node, PGNode *(*mutator) (),
55 void *context);
56
57extern bool query_tree_walker(PGQuery *query, bool (*walker) (),
58 void *context, int flags);
59extern PGQuery *query_tree_mutator(PGQuery *query, PGNode *(*mutator) (),
60 void *context, int flags);
61
62extern bool range_table_walker(PGList *rtable, bool (*walker) (),
63 void *context, int flags);
64extern PGList *range_table_mutator(PGList *rtable, PGNode *(*mutator) (),
65 void *context, int flags);
66
67extern bool query_or_expression_tree_walker(PGNode *node, bool (*walker) (),
68 void *context, int flags);
69extern PGNode *query_or_expression_tree_mutator(PGNode *node, PGNode *(*mutator) (),
70 void *context, int flags);
71
72extern bool raw_expression_tree_walker(PGNode *node, bool (*walker) (),
73 void *context);
74
75struct PlanState;
76extern bool planstate_tree_walker(struct PlanState *planstate, bool (*walker) (),
77 void *context);
78
79