PostgreSQL Source Code  git master
rewriteManip.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * rewriteManip.h
4  * Querytree manipulation subroutines for query rewriter.
5  *
6  *
7  * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * src/include/rewrite/rewriteManip.h
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef REWRITEMANIP_H
15 #define REWRITEMANIP_H
16 
17 #include "nodes/parsenodes.h"
18 
19 struct AttrMap; /* avoid including attmap.h here */
20 
21 
23 
24 typedef Node *(*replace_rte_variables_callback) (Var *var,
26 
28 {
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? */
34 };
35 
37 {
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 */
42 
43 
44 extern void CombineRangeTables(List **dst_rtable, List **dst_perminfos,
45  List *src_rtable, List *src_perminfos);
46 extern void OffsetVarNodes(Node *node, int offset, int sublevels_up);
47 extern void ChangeVarNodes(Node *node, int rt_index, int new_index,
48  int sublevels_up);
49 extern void IncrementVarSublevelsUp(Node *node, int delta_sublevels_up,
50  int min_sublevels_up);
51 extern void IncrementVarSublevelsUp_rtable(List *rtable,
52  int delta_sublevels_up, int min_sublevels_up);
53 
54 extern bool rangeTableEntry_used(Node *node, int rt_index,
55  int sublevels_up);
56 
57 extern Query *getInsertSelectQuery(Query *parsetree, Query ***subquery_ptr);
58 
59 extern void AddQual(Query *parsetree, Node *qual);
60 extern void AddInvertedQual(Query *parsetree, Node *qual);
61 
62 extern bool contain_aggs_of_level(Node *node, int levelsup);
63 extern int locate_agg_of_level(Node *node, int levelsup);
64 extern bool contain_windowfuncs(Node *node);
65 extern int locate_windowfunc(Node *node);
66 extern bool checkExprHasSubLink(Node *node);
67 
68 extern Node *replace_rte_variables(Node *node,
69  int target_varno, int sublevels_up,
71  void *callback_arg,
72  bool *outer_hasSubLinks);
75 
77  int target_varno, int sublevels_up,
78  const struct AttrMap *attno_map,
79  Oid to_rowtype, bool *found_whole_row);
80 
81 extern Node *ReplaceVarsFromTargetList(Node *node,
82  int target_varno, int sublevels_up,
83  RangeTblEntry *target_rte,
84  List *targetlist,
85  ReplaceVarsNoMatchOption nomatch_option,
86  int nomatch_varno,
87  bool *outer_hasSubLinks);
88 
89 #endif /* REWRITEMANIP_H */
unsigned int Oid
Definition: postgres_ext.h:31
bool contain_windowfuncs(Node *node)
Definition: rewriteManip.c:197
Node * ReplaceVarsFromTargetList(Node *node, int target_varno, int sublevels_up, RangeTblEntry *target_rte, List *targetlist, ReplaceVarsNoMatchOption nomatch_option, int nomatch_varno, bool *outer_hasSubLinks)
void IncrementVarSublevelsUp_rtable(List *rtable, int delta_sublevels_up, int min_sublevels_up)
Definition: rewriteManip.c:832
void ChangeVarNodes(Node *node, int rt_index, int new_index, int sublevels_up)
Definition: rewriteManip.c:643
Node * replace_rte_variables_mutator(Node *node, replace_rte_variables_context *context)
void OffsetVarNodes(Node *node, int offset, int sublevels_up)
Definition: rewriteManip.c:458
bool checkExprHasSubLink(Node *node)
Definition: rewriteManip.c:277
Query * getInsertSelectQuery(Query *parsetree, Query ***subquery_ptr)
Definition: rewriteManip.c:957
void CombineRangeTables(List **dst_rtable, List **dst_perminfos, List *src_rtable, List *src_perminfos)
Definition: rewriteManip.c:332
void AddQual(Query *parsetree, Node *qual)
Node * replace_rte_variables(Node *node, int target_varno, int sublevels_up, replace_rte_variables_callback callback, void *callback_arg, bool *outer_hasSubLinks)
int locate_agg_of_level(Node *node, int levelsup)
Definition: rewriteManip.c:131
Node *(* replace_rte_variables_callback)(Var *var, replace_rte_variables_context *context)
Definition: rewriteManip.h:24
bool rangeTableEntry_used(Node *node, int rt_index, int sublevels_up)
Definition: rewriteManip.c:925
Node * map_variable_attnos(Node *node, int target_varno, int sublevels_up, const struct AttrMap *attno_map, Oid to_rowtype, bool *found_whole_row)
bool contain_aggs_of_level(Node *node, int levelsup)
Definition: rewriteManip.c:67
int locate_windowfunc(Node *node)
Definition: rewriteManip.c:235
void AddInvertedQual(Query *parsetree, Node *qual)
ReplaceVarsNoMatchOption
Definition: rewriteManip.h:37
@ REPLACEVARS_SUBSTITUTE_NULL
Definition: rewriteManip.h:40
@ REPLACEVARS_CHANGE_VARNO
Definition: rewriteManip.h:39
@ REPLACEVARS_REPORT_ERROR
Definition: rewriteManip.h:38
void IncrementVarSublevelsUp(Node *node, int delta_sublevels_up, int min_sublevels_up)
Definition: rewriteManip.c:809
Definition: attmap.h:35
Definition: pg_list.h:52
Definition: nodes.h:118
Definition: primnodes.h:205
replace_rte_variables_callback callback
Definition: rewriteManip.h:29
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:46