2
0

rewriteManip.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. #include "nodes/parsenodes.h"
  17. struct AttrMap; /* avoid including attmap.h here */
  18. typedef struct replace_rte_variables_context replace_rte_variables_context;
  19. typedef Node *(*replace_rte_variables_callback) (Var *var,
  20. replace_rte_variables_context *context);
  21. struct replace_rte_variables_context
  22. {
  23. replace_rte_variables_callback callback; /* callback function */
  24. void *callback_arg; /* context data for callback function */
  25. int target_varno; /* RTE index to search for */
  26. int sublevels_up; /* (current) nesting depth */
  27. bool inserted_sublink; /* have we inserted a SubLink? */
  28. };
  29. typedef enum ReplaceVarsNoMatchOption
  30. {
  31. REPLACEVARS_REPORT_ERROR, /* throw error if no match */
  32. REPLACEVARS_CHANGE_VARNO, /* change the Var's varno, nothing else */
  33. REPLACEVARS_SUBSTITUTE_NULL /* replace with a NULL Const */
  34. } ReplaceVarsNoMatchOption;
  35. extern void OffsetVarNodes(Node *node, int offset, int sublevels_up);
  36. extern void ChangeVarNodes(Node *node, int old_varno, int new_varno,
  37. int sublevels_up);
  38. extern void IncrementVarSublevelsUp(Node *node, int delta_sublevels_up,
  39. int min_sublevels_up);
  40. extern void IncrementVarSublevelsUp_rtable(List *rtable,
  41. int delta_sublevels_up, int min_sublevels_up);
  42. extern bool rangeTableEntry_used(Node *node, int rt_index,
  43. int sublevels_up);
  44. extern Query *getInsertSelectQuery(Query *parsetree, Query ***subquery_ptr);
  45. extern void AddQual(Query *parsetree, Node *qual);
  46. extern void AddInvertedQual(Query *parsetree, Node *qual);
  47. extern bool contain_aggs_of_level(Node *node, int levelsup);
  48. extern int locate_agg_of_level(Node *node, int levelsup);
  49. extern bool contain_windowfuncs(Node *node);
  50. extern int locate_windowfunc(Node *node);
  51. extern bool checkExprHasSubLink(Node *node);
  52. extern Node *replace_rte_variables(Node *node,
  53. int target_varno, int sublevels_up,
  54. replace_rte_variables_callback callback,
  55. void *callback_arg,
  56. bool *outer_hasSubLinks);
  57. extern Node *replace_rte_variables_mutator(Node *node,
  58. replace_rte_variables_context *context);
  59. extern Node *map_variable_attnos(Node *node,
  60. int target_varno, int sublevels_up,
  61. const struct AttrMap *attno_map,
  62. Oid to_rowtype, bool *found_whole_row);
  63. extern Node *ReplaceVarsFromTargetList(Node *node,
  64. int target_varno, int sublevels_up,
  65. RangeTblEntry *target_rte,
  66. List *targetlist,
  67. ReplaceVarsNoMatchOption nomatch_option,
  68. int nomatch_varno,
  69. bool *outer_hasSubLinks);
  70. #endif /* REWRITEMANIP_H */