| 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 |
|
| 20 |
struct AttrMap; /* avoid including attmap.h here */ |
| 21 |
|
| 22 |
|
| 23 |
typedef struct replace_rte_variables_context replace_rte_variables_context; |
| 24 |
|
| 25 |
typedef Node *(*replace_rte_variables_callback) (Var *var, |
| 26 |
replace_rte_variables_context *context); |
| 27 |
|
| 28 |
struct replace_rte_variables_context |
| 29 |
{ |
| 30 |
replace_rte_variables_callback callback; /* callback function */ |
| 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 |
|
| 37 |
typedef enum ReplaceVarsNoMatchOption |
| 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 */ |
| 42 |
} ReplaceVarsNoMatchOption; |
| 43 |
|
| 44 |
typedef struct ChangeVarNodes_context ChangeVarNodes_context; |
| 45 |
|
| 46 |
typedef bool (*ChangeVarNodes_callback) (Node *node, |
| 47 |
ChangeVarNodes_context *arg); |
| 48 |
|
| 49 |
struct ChangeVarNodes_context |
| 50 |
{ |
| 51 |
int rt_index; |
| 52 |
int new_index; |
| 53 |
int sublevels_up; |
| 54 |
ChangeVarNodes_callback callback; |
| 55 |
}; |
| 56 |
|
| 57 |
extern Relids adjust_relid_set(Relids relids, int oldrelid, int newrelid); |
| 58 |
extern void CombineRangeTables(List **dst_rtable, List **dst_perminfos, |
| 59 |
List *src_rtable, List *src_perminfos); |
| 60 |
extern void OffsetVarNodes(Node *node, int offset, int sublevels_up); |
| 61 |
extern void ChangeVarNodes(Node *node, int rt_index, int new_index, |
| 62 |
int sublevels_up); |
| 63 |
extern void ChangeVarNodesExtended(Node *node, int rt_index, int new_index, |
| 64 |
int sublevels_up, |
| 65 |
ChangeVarNodes_callback callback); |
| 66 |
extern bool ChangeVarNodesWalkExpression(Node *node, |
| 67 |
ChangeVarNodes_context *context); |
| 68 |
extern void IncrementVarSublevelsUp(Node *node, int delta_sublevels_up, |
| 69 |
int min_sublevels_up); |
| 70 |
extern void IncrementVarSublevelsUp_rtable(List *rtable, |
| 71 |
int delta_sublevels_up, int min_sublevels_up); |
| 72 |
|
| 73 |
extern bool rangeTableEntry_used(Node *node, int rt_index, |
| 74 |
int sublevels_up); |
| 75 |
|
| 76 |
extern Query *getInsertSelectQuery(Query *parsetree, Query ***subquery_ptr); |
| 77 |
|
| 78 |
extern void AddQual(Query *parsetree, Node *qual); |
| 79 |
extern void AddInvertedQual(Query *parsetree, Node *qual); |
| 80 |
|
| 81 |
extern bool contain_aggs_of_level(Node *node, int levelsup); |
| 82 |
extern int locate_agg_of_level(Node *node, int levelsup); |
| 83 |
extern bool contain_windowfuncs(Node *node); |
| 84 |
extern int locate_windowfunc(Node *node); |
| 85 |
extern bool checkExprHasSubLink(Node *node); |
| 86 |
|
| 87 |
extern Node *add_nulling_relids(Node *node, |
| 88 |
const Bitmapset *target_relids, |
| 89 |
const Bitmapset *added_relids); |
| 90 |
extern Node *remove_nulling_relids(Node *node, |
| 91 |
const Bitmapset *removable_relids, |
| 92 |
const Bitmapset *except_relids); |
| 93 |
|
| 94 |
extern Node *replace_rte_variables(Node *node, |
| 95 |
int target_varno, int sublevels_up, |
| 96 |
replace_rte_variables_callback callback, |
| 97 |
void *callback_arg, |
| 98 |
bool *outer_hasSubLinks); |
| 99 |
extern Node *replace_rte_variables_mutator(Node *node, |
| 100 |
replace_rte_variables_context *context); |
| 101 |
|
| 102 |
extern Node *map_variable_attnos(Node *node, |
| 103 |
int target_varno, int sublevels_up, |
| 104 |
const struct AttrMap *attno_map, |
| 105 |
Oid to_rowtype, bool *found_whole_row); |
| 106 |
|
| 107 |
extern Node *ReplaceVarFromTargetList(Var *var, |
| 108 |
RangeTblEntry *target_rte, |
| 109 |
List *targetlist, |
| 110 |
int result_relation, |
| 111 |
ReplaceVarsNoMatchOption nomatch_option, |
| 112 |
int nomatch_varno); |
| 113 |
extern Node *ReplaceVarsFromTargetList(Node *node, |
| 114 |
int target_varno, int sublevels_up, |
| 115 |
RangeTblEntry *target_rte, |
| 116 |
List *targetlist, |
| 117 |
int result_relation, |
| 118 |
ReplaceVarsNoMatchOption nomatch_option, |
| 119 |
int nomatch_varno, |
| 120 |
bool *outer_hasSubLinks); |
| 121 |
|
| 122 |
#endif /* REWRITEMANIP_H */ |