rewriteManip.h 2.9 KB

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