nodeFuncs.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*-------------------------------------------------------------------------
  2. *
  3. * nodeFuncs.h
  4. * Various general-purpose manipulations of Node trees
  5. *
  6. * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
  7. * Portions Copyright (c) 1994, Regents of the University of California
  8. *
  9. * src/include/nodes/nodeFuncs.h
  10. *
  11. *-------------------------------------------------------------------------
  12. */
  13. #ifndef NODEFUNCS_H
  14. #define NODEFUNCS_H
  15. #include "nodes/parsenodes.h"
  16. /* flags bits for query_tree_walker and query_tree_mutator */
  17. #define QTW_IGNORE_RT_SUBQUERIES 0x01 /* subqueries in rtable */
  18. #define QTW_IGNORE_CTE_SUBQUERIES 0x02 /* subqueries in cteList */
  19. #define QTW_IGNORE_RC_SUBQUERIES 0x03 /* both of above */
  20. #define QTW_IGNORE_JOINALIASES 0x04 /* JOIN alias var lists */
  21. #define QTW_IGNORE_RANGE_TABLE 0x08 /* skip rangetable entirely */
  22. #define QTW_EXAMINE_RTES_BEFORE 0x10 /* examine RTE nodes before their
  23. * contents */
  24. #define QTW_EXAMINE_RTES_AFTER 0x20 /* examine RTE nodes after their
  25. * contents */
  26. #define QTW_DONT_COPY_QUERY 0x40 /* do not copy top Query */
  27. #define QTW_EXAMINE_SORTGROUP 0x80 /* include SortGroupNode lists */
  28. /* callback function for check_functions_in_node */
  29. typedef bool (*check_function_callback) (Oid func_id, void *context);
  30. extern Oid exprType(const Node *expr);
  31. extern int32 exprTypmod(const Node *expr);
  32. extern bool exprIsLengthCoercion(const Node *expr, int32 *coercedTypmod);
  33. extern Node *applyRelabelType(Node *arg, Oid rtype, int32 rtypmod, Oid rcollid,
  34. CoercionForm rformat, int rlocation,
  35. bool overwrite_ok);
  36. extern Node *relabel_to_typmod(Node *expr, int32 typmod);
  37. extern Node *strip_implicit_coercions(Node *node);
  38. extern bool expression_returns_set(Node *clause);
  39. extern Oid exprCollation(const Node *expr);
  40. extern Oid exprInputCollation(const Node *expr);
  41. extern void exprSetCollation(Node *expr, Oid collation);
  42. extern void exprSetInputCollation(Node *expr, Oid inputcollation);
  43. extern int exprLocation(const Node *expr);
  44. extern void fix_opfuncids(Node *node);
  45. extern void set_opfuncid(OpExpr *opexpr);
  46. extern void set_sa_opfuncid(ScalarArrayOpExpr *opexpr);
  47. /* Is clause a FuncExpr clause? */
  48. static inline bool
  49. is_funcclause(const void *clause)
  50. {
  51. return clause != NULL && IsA(clause, FuncExpr);
  52. }
  53. /* Is clause an OpExpr clause? */
  54. static inline bool
  55. is_opclause(const void *clause)
  56. {
  57. return clause != NULL && IsA(clause, OpExpr);
  58. }
  59. /* Extract left arg of a binary opclause, or only arg of a unary opclause */
  60. static inline Node *
  61. get_leftop(const void *clause)
  62. {
  63. const OpExpr *expr = (const OpExpr *) clause;
  64. if (expr->args != NIL)
  65. return (Node *) linitial(expr->args);
  66. else
  67. return NULL;
  68. }
  69. /* Extract right arg of a binary opclause (NULL if it's a unary opclause) */
  70. static inline Node *
  71. get_rightop(const void *clause)
  72. {
  73. const OpExpr *expr = (const OpExpr *) clause;
  74. if (list_length(expr->args) >= 2)
  75. return (Node *) lsecond(expr->args);
  76. else
  77. return NULL;
  78. }
  79. /* Is clause an AND clause? */
  80. static inline bool
  81. is_andclause(const void *clause)
  82. {
  83. return (clause != NULL &&
  84. IsA(clause, BoolExpr) &&
  85. ((const BoolExpr *) clause)->boolop == AND_EXPR);
  86. }
  87. /* Is clause an OR clause? */
  88. static inline bool
  89. is_orclause(const void *clause)
  90. {
  91. return (clause != NULL &&
  92. IsA(clause, BoolExpr) &&
  93. ((const BoolExpr *) clause)->boolop == OR_EXPR);
  94. }
  95. /* Is clause a NOT clause? */
  96. static inline bool
  97. is_notclause(const void *clause)
  98. {
  99. return (clause != NULL &&
  100. IsA(clause, BoolExpr) &&
  101. ((const BoolExpr *) clause)->boolop == NOT_EXPR);
  102. }
  103. /* Extract argument from a clause known to be a NOT clause */
  104. static inline Expr *
  105. get_notclausearg(const void *notclause)
  106. {
  107. return (Expr *) linitial(((const BoolExpr *) notclause)->args);
  108. }
  109. extern bool check_functions_in_node(Node *node, check_function_callback checker,
  110. void *context);
  111. extern bool expression_tree_walker(Node *node, bool (*walker) (),
  112. void *context);
  113. extern Node *expression_tree_mutator(Node *node, Node *(*mutator) (),
  114. void *context);
  115. extern bool query_tree_walker(Query *query, bool (*walker) (),
  116. void *context, int flags);
  117. extern Query *query_tree_mutator(Query *query, Node *(*mutator) (),
  118. void *context, int flags);
  119. extern bool range_table_walker(List *rtable, bool (*walker) (),
  120. void *context, int flags);
  121. extern List *range_table_mutator(List *rtable, Node *(*mutator) (),
  122. void *context, int flags);
  123. extern bool range_table_entry_walker(RangeTblEntry *rte, bool (*walker) (),
  124. void *context, int flags);
  125. extern bool query_or_expression_tree_walker(Node *node, bool (*walker) (),
  126. void *context, int flags);
  127. extern Node *query_or_expression_tree_mutator(Node *node, Node *(*mutator) (),
  128. void *context, int flags);
  129. extern bool raw_expression_tree_walker(Node *node, bool (*walker) (),
  130. void *context);
  131. struct PlanState;
  132. extern bool planstate_tree_walker(struct PlanState *planstate, bool (*walker) (),
  133. void *context);
  134. #endif /* NODEFUNCS_H */