1 /*-------------------------------------------------------------------------
4 * Querytree manipulation subroutines for query rewriter.
7 * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * src/include/rewrite/rewriteManip.h
12 *-------------------------------------------------------------------------
14 #ifndef REWRITEMANIP_H
15 #define REWRITEMANIP_H
17 #include "nodes/parsenodes.h"
20 typedef struct replace_rte_variables_context replace_rte_variables_context;
22 typedef Node *(*replace_rte_variables_callback) (Var *var,
23 replace_rte_variables_context *context);
25 struct replace_rte_variables_context
27 replace_rte_variables_callback callback; /* callback function */
28 void *callback_arg; /* context data for callback function */
29 int target_varno; /* RTE index to search for */
30 int sublevels_up; /* (current) nesting depth */
31 bool inserted_sublink; /* have we inserted a SubLink? */
34 typedef enum ReplaceVarsNoMatchOption
36 REPLACEVARS_REPORT_ERROR, /* throw error if no match */
37 REPLACEVARS_CHANGE_VARNO, /* change the Var's varno, nothing else */
38 REPLACEVARS_SUBSTITUTE_NULL /* replace with a NULL Const */
39 } ReplaceVarsNoMatchOption;
42 extern void OffsetVarNodes(Node *node, int offset, int sublevels_up);
43 extern void ChangeVarNodes(Node *node, int old_varno, int new_varno,
45 extern void IncrementVarSublevelsUp(Node *node, int delta_sublevels_up,
46 int min_sublevels_up);
47 extern void IncrementVarSublevelsUp_rtable(List *rtable,
48 int delta_sublevels_up, int min_sublevels_up);
50 extern bool rangeTableEntry_used(Node *node, int rt_index,
53 extern Query *getInsertSelectQuery(Query *parsetree, Query ***subquery_ptr);
55 extern void AddQual(Query *parsetree, Node *qual);
56 extern void AddInvertedQual(Query *parsetree, Node *qual);
58 extern bool contain_aggs_of_level(Node *node, int levelsup);
59 extern int locate_agg_of_level(Node *node, int levelsup);
60 extern bool contain_windowfuncs(Node *node);
61 extern int locate_windowfunc(Node *node);
62 extern bool checkExprHasSubLink(Node *node);
64 extern Node *replace_rte_variables(Node *node,
65 int target_varno, int sublevels_up,
66 replace_rte_variables_callback callback,
68 bool *outer_hasSubLinks);
69 extern Node *replace_rte_variables_mutator(Node *node,
70 replace_rte_variables_context *context);
72 extern Node *map_variable_attnos(Node *node,
73 int target_varno, int sublevels_up,
74 const AttrNumber *attno_map, int map_length,
75 bool *found_whole_row);
77 extern Node *ReplaceVarsFromTargetList(Node *node,
78 int target_varno, int sublevels_up,
79 RangeTblEntry *target_rte,
81 ReplaceVarsNoMatchOption nomatch_option,
83 bool *outer_hasSubLinks);
85 #endif /* REWRITEMANIP_H */