Update copyright for 2022
[pgsql.git] / src / include / rewrite / rewriteManip.h
blob98b9b3a2881b0cfc855dd289126d476b1821a9c5
1 /*-------------------------------------------------------------------------
3 * rewriteManip.h
4 * Querytree manipulation subroutines for query rewriter.
7 * Portions Copyright (c) 1996-2022, 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"
19 struct AttrMap; /* avoid including attmap.h here */
22 typedef struct replace_rte_variables_context replace_rte_variables_context;
24 typedef Node *(*replace_rte_variables_callback) (Var *var,
25 replace_rte_variables_context *context);
27 struct replace_rte_variables_context
29 replace_rte_variables_callback callback; /* callback function */
30 void *callback_arg; /* context data for callback function */
31 int target_varno; /* RTE index to search for */
32 int sublevels_up; /* (current) nesting depth */
33 bool inserted_sublink; /* have we inserted a SubLink? */
36 typedef enum ReplaceVarsNoMatchOption
38 REPLACEVARS_REPORT_ERROR, /* throw error if no match */
39 REPLACEVARS_CHANGE_VARNO, /* change the Var's varno, nothing else */
40 REPLACEVARS_SUBSTITUTE_NULL /* replace with a NULL Const */
41 } ReplaceVarsNoMatchOption;
44 extern void OffsetVarNodes(Node *node, int offset, int sublevels_up);
45 extern void ChangeVarNodes(Node *node, int old_varno, int new_varno,
46 int sublevels_up);
47 extern void IncrementVarSublevelsUp(Node *node, int delta_sublevels_up,
48 int min_sublevels_up);
49 extern void IncrementVarSublevelsUp_rtable(List *rtable,
50 int delta_sublevels_up, int min_sublevels_up);
52 extern bool rangeTableEntry_used(Node *node, int rt_index,
53 int sublevels_up);
55 extern Query *getInsertSelectQuery(Query *parsetree, Query ***subquery_ptr);
57 extern void AddQual(Query *parsetree, Node *qual);
58 extern void AddInvertedQual(Query *parsetree, Node *qual);
60 extern bool contain_aggs_of_level(Node *node, int levelsup);
61 extern int locate_agg_of_level(Node *node, int levelsup);
62 extern bool contain_windowfuncs(Node *node);
63 extern int locate_windowfunc(Node *node);
64 extern bool checkExprHasSubLink(Node *node);
66 extern Node *replace_rte_variables(Node *node,
67 int target_varno, int sublevels_up,
68 replace_rte_variables_callback callback,
69 void *callback_arg,
70 bool *outer_hasSubLinks);
71 extern Node *replace_rte_variables_mutator(Node *node,
72 replace_rte_variables_context *context);
74 extern Node *map_variable_attnos(Node *node,
75 int target_varno, int sublevels_up,
76 const struct AttrMap *attno_map,
77 Oid to_rowtype, bool *found_whole_row);
79 extern Node *ReplaceVarsFromTargetList(Node *node,
80 int target_varno, int sublevels_up,
81 RangeTblEntry *target_rte,
82 List *targetlist,
83 ReplaceVarsNoMatchOption nomatch_option,
84 int nomatch_varno,
85 bool *outer_hasSubLinks);
87 #endif /* REWRITEMANIP_H */