PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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-2025, 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#include "nodes/pathnodes.h"
19
20struct AttrMap; /* avoid including attmap.h here */
21
22
24
25typedef Node *(*replace_rte_variables_callback) (Var *var,
27
29{
31 void *callback_arg; /* context data for callback function */
32 int target_varno; /* RTE index to search for */
33 int sublevels_up; /* (current) nesting depth */
34 bool inserted_sublink; /* have we inserted a SubLink? */
35};
36
38{
39 REPLACEVARS_REPORT_ERROR, /* throw error if no match */
40 REPLACEVARS_CHANGE_VARNO, /* change the Var's varno, nothing else */
41 REPLACEVARS_SUBSTITUTE_NULL, /* replace with a NULL Const */
43
44
45extern Relids adjust_relid_set(Relids relids, int oldrelid, int newrelid);
46extern void CombineRangeTables(List **dst_rtable, List **dst_perminfos,
47 List *src_rtable, List *src_perminfos);
48extern void OffsetVarNodes(Node *node, int offset, int sublevels_up);
49extern void ChangeVarNodes(Node *node, int rt_index, int new_index,
50 int sublevels_up);
51extern void ChangeVarNodesExtended(Node *node, int rt_index, int new_index,
52 int sublevels_up, bool change_RangeTblRef);
53extern void IncrementVarSublevelsUp(Node *node, int delta_sublevels_up,
54 int min_sublevels_up);
55extern void IncrementVarSublevelsUp_rtable(List *rtable,
56 int delta_sublevels_up, int min_sublevels_up);
57
58extern bool rangeTableEntry_used(Node *node, int rt_index,
59 int sublevels_up);
60
61extern Query *getInsertSelectQuery(Query *parsetree, Query ***subquery_ptr);
62
63extern void AddQual(Query *parsetree, Node *qual);
64extern void AddInvertedQual(Query *parsetree, Node *qual);
65
66extern bool contain_aggs_of_level(Node *node, int levelsup);
67extern int locate_agg_of_level(Node *node, int levelsup);
68extern bool contain_windowfuncs(Node *node);
69extern int locate_windowfunc(Node *node);
70extern bool checkExprHasSubLink(Node *node);
71
72extern Node *add_nulling_relids(Node *node,
73 const Bitmapset *target_relids,
74 const Bitmapset *added_relids);
75extern Node *remove_nulling_relids(Node *node,
76 const Bitmapset *removable_relids,
77 const Bitmapset *except_relids);
78
79extern Node *replace_rte_variables(Node *node,
80 int target_varno, int sublevels_up,
82 void *callback_arg,
83 bool *outer_hasSubLinks);
86
88 int target_varno, int sublevels_up,
89 const struct AttrMap *attno_map,
90 Oid to_rowtype, bool *found_whole_row);
91
93 RangeTblEntry *target_rte,
94 List *targetlist,
95 int result_relation,
96 ReplaceVarsNoMatchOption nomatch_option,
97 int nomatch_varno);
99 int target_varno, int sublevels_up,
100 RangeTblEntry *target_rte,
101 List *targetlist,
102 int result_relation,
103 ReplaceVarsNoMatchOption nomatch_option,
104 int nomatch_varno,
105 bool *outer_hasSubLinks);
106
107#endif /* REWRITEMANIP_H */
unsigned int Oid
Definition: postgres_ext.h:30
bool contain_windowfuncs(Node *node)
Definition: rewriteManip.c:214
void ChangeVarNodesExtended(Node *node, int rt_index, int new_index, int sublevels_up, bool change_RangeTblRef)
Definition: rewriteManip.c:751
void IncrementVarSublevelsUp_rtable(List *rtable, int delta_sublevels_up, int min_sublevels_up)
Definition: rewriteManip.c:951
void ChangeVarNodes(Node *node, int rt_index, int new_index, int sublevels_up)
Definition: rewriteManip.c:793
Node * replace_rte_variables_mutator(Node *node, replace_rte_variables_context *context)
Relids adjust_relid_set(Relids relids, int oldrelid, int newrelid)
Definition: rewriteManip.c:808
void OffsetVarNodes(Node *node, int offset, int sublevels_up)
Definition: rewriteManip.c:476
bool checkExprHasSubLink(Node *node)
Definition: rewriteManip.c:292
void CombineRangeTables(List **dst_rtable, List **dst_perminfos, List *src_rtable, List *src_perminfos)
Definition: rewriteManip.c:347
void AddQual(Query *parsetree, Node *qual)
int locate_agg_of_level(Node *node, int levelsup)
Definition: rewriteManip.c:149
Node *(* replace_rte_variables_callback)(Var *var, replace_rte_variables_context *context)
Definition: rewriteManip.h:25
Node * add_nulling_relids(Node *node, const Bitmapset *target_relids, const Bitmapset *added_relids)
bool rangeTableEntry_used(Node *node, int rt_index, int sublevels_up)
bool contain_aggs_of_level(Node *node, int levelsup)
Definition: rewriteManip.c:85
Query * getInsertSelectQuery(Query *parsetree, Query ***subquery_ptr)
int locate_windowfunc(Node *node)
Definition: rewriteManip.c:251
Node * remove_nulling_relids(Node *node, const Bitmapset *removable_relids, const Bitmapset *except_relids)
void AddInvertedQual(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)
ReplaceVarsNoMatchOption
Definition: rewriteManip.h:38
@ REPLACEVARS_SUBSTITUTE_NULL
Definition: rewriteManip.h:41
@ REPLACEVARS_CHANGE_VARNO
Definition: rewriteManip.h:40
@ REPLACEVARS_REPORT_ERROR
Definition: rewriteManip.h:39
Node * ReplaceVarFromTargetList(Var *var, RangeTblEntry *target_rte, List *targetlist, int result_relation, ReplaceVarsNoMatchOption nomatch_option, int nomatch_varno)
void IncrementVarSublevelsUp(Node *node, int delta_sublevels_up, int min_sublevels_up)
Definition: rewriteManip.c:928
Node * ReplaceVarsFromTargetList(Node *node, int target_varno, int sublevels_up, RangeTblEntry *target_rte, List *targetlist, int result_relation, ReplaceVarsNoMatchOption nomatch_option, int nomatch_varno, bool *outer_hasSubLinks)
Node * map_variable_attnos(Node *node, int target_varno, int sublevels_up, const struct AttrMap *attno_map, Oid to_rowtype, bool *found_whole_row)
Definition: attmap.h:35
Definition: pg_list.h:54
Definition: nodes.h:135
Definition: primnodes.h:262
replace_rte_variables_callback callback
Definition: rewriteManip.h:30
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:46