Header And Logo

PostgreSQL
| The world's most advanced open source database.

rewriteManip.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * rewriteManip.h
00004  *      Querytree manipulation subroutines for query rewriter.
00005  *
00006  *
00007  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00008  * Portions Copyright (c) 1994, Regents of the University of California
00009  *
00010  * src/include/rewrite/rewriteManip.h
00011  *
00012  *-------------------------------------------------------------------------
00013  */
00014 #ifndef REWRITEMANIP_H
00015 #define REWRITEMANIP_H
00016 
00017 #include "nodes/parsenodes.h"
00018 
00019 
00020 typedef struct replace_rte_variables_context replace_rte_variables_context;
00021 
00022 typedef Node *(*replace_rte_variables_callback) (Var *var,
00023                                      replace_rte_variables_context *context);
00024 
00025 struct replace_rte_variables_context
00026 {
00027     replace_rte_variables_callback callback;    /* callback function */
00028     void       *callback_arg;   /* context data for callback function */
00029     int         target_varno;   /* RTE index to search for */
00030     int         sublevels_up;   /* (current) nesting depth */
00031     bool        inserted_sublink;       /* have we inserted a SubLink? */
00032 };
00033 
00034 typedef enum ReplaceVarsNoMatchOption
00035 {
00036     REPLACEVARS_REPORT_ERROR,   /* throw error if no match */
00037     REPLACEVARS_CHANGE_VARNO,   /* change the Var's varno, nothing else */
00038     REPLACEVARS_SUBSTITUTE_NULL /* replace with a NULL Const */
00039 } ReplaceVarsNoMatchOption;
00040 
00041 
00042 extern void OffsetVarNodes(Node *node, int offset, int sublevels_up);
00043 extern void ChangeVarNodes(Node *node, int old_varno, int new_varno,
00044                int sublevels_up);
00045 extern void IncrementVarSublevelsUp(Node *node, int delta_sublevels_up,
00046                         int min_sublevels_up);
00047 extern void IncrementVarSublevelsUp_rtable(List *rtable,
00048                                int delta_sublevels_up, int min_sublevels_up);
00049 
00050 extern bool rangeTableEntry_used(Node *node, int rt_index,
00051                      int sublevels_up);
00052 extern bool attribute_used(Node *node, int rt_index, int attno,
00053                int sublevels_up);
00054 
00055 extern Query *getInsertSelectQuery(Query *parsetree, Query ***subquery_ptr);
00056 
00057 extern void AddQual(Query *parsetree, Node *qual);
00058 extern void AddInvertedQual(Query *parsetree, Node *qual);
00059 
00060 extern bool contain_aggs_of_level(Node *node, int levelsup);
00061 extern int  locate_agg_of_level(Node *node, int levelsup);
00062 extern bool contain_windowfuncs(Node *node);
00063 extern int  locate_windowfunc(Node *node);
00064 extern bool checkExprHasSubLink(Node *node);
00065 
00066 extern Node *replace_rte_variables(Node *node,
00067                       int target_varno, int sublevels_up,
00068                       replace_rte_variables_callback callback,
00069                       void *callback_arg,
00070                       bool *outer_hasSubLinks);
00071 extern Node *replace_rte_variables_mutator(Node *node,
00072                               replace_rte_variables_context *context);
00073 
00074 extern Node *map_variable_attnos(Node *node,
00075                     int target_varno, int sublevels_up,
00076                     const AttrNumber *attno_map, int map_length,
00077                     bool *found_whole_row);
00078 
00079 extern Node *ReplaceVarsFromTargetList(Node *node,
00080                           int target_varno, int sublevels_up,
00081                           RangeTblEntry *target_rte,
00082                           List *targetlist,
00083                           ReplaceVarsNoMatchOption nomatch_option,
00084                           int nomatch_varno,
00085                           bool *outer_hasSubLinks);
00086 
00087 #endif   /* REWRITEMANIP_H */