PostgreSQL Source Code  git master
nodeFuncs.h File Reference
#include "nodes/parsenodes.h"
Include dependency graph for nodeFuncs.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define QTW_IGNORE_RT_SUBQUERIES   0x01 /* subqueries in rtable */
 
#define QTW_IGNORE_CTE_SUBQUERIES   0x02 /* subqueries in cteList */
 
#define QTW_IGNORE_RC_SUBQUERIES   0x03 /* both of above */
 
#define QTW_IGNORE_JOINALIASES   0x04 /* JOIN alias var lists */
 
#define QTW_IGNORE_RANGE_TABLE   0x08 /* skip rangetable entirely */
 
#define QTW_EXAMINE_RTES_BEFORE
 
#define QTW_EXAMINE_RTES_AFTER
 
#define QTW_DONT_COPY_QUERY   0x40 /* do not copy top Query */
 
#define QTW_EXAMINE_SORTGROUP   0x80 /* include SortGroupClause lists */
 
#define expression_tree_walker(n, w, c)    expression_tree_walker_impl(n, (tree_walker_callback) (w), c)
 
#define expression_tree_mutator(n, m, c)    expression_tree_mutator_impl(n, (tree_mutator_callback) (m), c)
 
#define query_tree_walker(q, w, c, f)    query_tree_walker_impl(q, (tree_walker_callback) (w), c, f)
 
#define query_tree_mutator(q, m, c, f)    query_tree_mutator_impl(q, (tree_mutator_callback) (m), c, f)
 
#define range_table_walker(rt, w, c, f)    range_table_walker_impl(rt, (tree_walker_callback) (w), c, f)
 
#define range_table_mutator(rt, m, c, f)    range_table_mutator_impl(rt, (tree_mutator_callback) (m), c, f)
 
#define range_table_entry_walker(r, w, c, f)    range_table_entry_walker_impl(r, (tree_walker_callback) (w), c, f)
 
#define query_or_expression_tree_walker(n, w, c, f)    query_or_expression_tree_walker_impl(n, (tree_walker_callback) (w), c, f)
 
#define query_or_expression_tree_mutator(n, m, c, f)    query_or_expression_tree_mutator_impl(n, (tree_mutator_callback) (m), c, f)
 
#define raw_expression_tree_walker(n, w, c)    raw_expression_tree_walker_impl(n, (tree_walker_callback) (w), c)
 
#define planstate_tree_walker(ps, w, c)    planstate_tree_walker_impl(ps, (planstate_tree_walker_callback) (w), c)
 

Typedefs

typedef bool(* check_function_callback) (Oid func_id, void *context)
 
typedef bool(* tree_walker_callback) (Node *node, void *context)
 
typedef bool(* planstate_tree_walker_callback) (struct PlanState *planstate, void *context)
 
typedef Node *(* tree_mutator_callback) (Node *node, void *context)
 

Functions

Oid exprType (const Node *expr)
 
int32 exprTypmod (const Node *expr)
 
bool exprIsLengthCoercion (const Node *expr, int32 *coercedTypmod)
 
NodeapplyRelabelType (Node *arg, Oid rtype, int32 rtypmod, Oid rcollid, CoercionForm rformat, int rlocation, bool overwrite_ok)
 
Noderelabel_to_typmod (Node *expr, int32 typmod)
 
Nodestrip_implicit_coercions (Node *node)
 
bool expression_returns_set (Node *clause)
 
Oid exprCollation (const Node *expr)
 
Oid exprInputCollation (const Node *expr)
 
void exprSetCollation (Node *expr, Oid collation)
 
void exprSetInputCollation (Node *expr, Oid inputcollation)
 
int exprLocation (const Node *expr)
 
void fix_opfuncids (Node *node)
 
void set_opfuncid (OpExpr *opexpr)
 
void set_sa_opfuncid (ScalarArrayOpExpr *opexpr)
 
static bool is_funcclause (const void *clause)
 
static bool is_opclause (const void *clause)
 
static Nodeget_leftop (const void *clause)
 
static Nodeget_rightop (const void *clause)
 
static bool is_andclause (const void *clause)
 
static bool is_orclause (const void *clause)
 
static bool is_notclause (const void *clause)
 
static Exprget_notclausearg (const void *notclause)
 
bool check_functions_in_node (Node *node, check_function_callback checker, void *context)
 
bool expression_tree_walker_impl (Node *node, tree_walker_callback walker, void *context)
 
Nodeexpression_tree_mutator_impl (Node *node, tree_mutator_callback mutator, void *context)
 
bool query_tree_walker_impl (Query *query, tree_walker_callback walker, void *context, int flags)
 
Queryquery_tree_mutator_impl (Query *query, tree_mutator_callback mutator, void *context, int flags)
 
bool range_table_walker_impl (List *rtable, tree_walker_callback walker, void *context, int flags)
 
Listrange_table_mutator_impl (List *rtable, tree_mutator_callback mutator, void *context, int flags)
 
bool range_table_entry_walker_impl (RangeTblEntry *rte, tree_walker_callback walker, void *context, int flags)
 
bool query_or_expression_tree_walker_impl (Node *node, tree_walker_callback walker, void *context, int flags)
 
Nodequery_or_expression_tree_mutator_impl (Node *node, tree_mutator_callback mutator, void *context, int flags)
 
bool raw_expression_tree_walker_impl (Node *node, tree_walker_callback walker, void *context)
 
bool planstate_tree_walker_impl (struct PlanState *planstate, planstate_tree_walker_callback walker, void *context)
 

Macro Definition Documentation

◆ expression_tree_mutator

#define expression_tree_mutator (   n,
  m,
  c 
)     expression_tree_mutator_impl(n, (tree_mutator_callback) (m), c)

Definition at line 153 of file nodeFuncs.h.

◆ expression_tree_walker

#define expression_tree_walker (   n,
  w,
  c 
)     expression_tree_walker_impl(n, (tree_walker_callback) (w), c)

Definition at line 151 of file nodeFuncs.h.

◆ planstate_tree_walker

#define planstate_tree_walker (   ps,
  w,
  c 
)     planstate_tree_walker_impl(ps, (planstate_tree_walker_callback) (w), c)

Definition at line 177 of file nodeFuncs.h.

◆ QTW_DONT_COPY_QUERY

#define QTW_DONT_COPY_QUERY   0x40 /* do not copy top Query */

Definition at line 29 of file nodeFuncs.h.

◆ QTW_EXAMINE_RTES_AFTER

#define QTW_EXAMINE_RTES_AFTER
Value:
0x20 /* examine RTE nodes after their
* contents */

Definition at line 28 of file nodeFuncs.h.

◆ QTW_EXAMINE_RTES_BEFORE

#define QTW_EXAMINE_RTES_BEFORE
Value:
0x10 /* examine RTE nodes before their
* contents */

Definition at line 27 of file nodeFuncs.h.

◆ QTW_EXAMINE_SORTGROUP

#define QTW_EXAMINE_SORTGROUP   0x80 /* include SortGroupClause lists */

Definition at line 30 of file nodeFuncs.h.

◆ QTW_IGNORE_CTE_SUBQUERIES

#define QTW_IGNORE_CTE_SUBQUERIES   0x02 /* subqueries in cteList */

Definition at line 23 of file nodeFuncs.h.

◆ QTW_IGNORE_JOINALIASES

#define QTW_IGNORE_JOINALIASES   0x04 /* JOIN alias var lists */

Definition at line 25 of file nodeFuncs.h.

◆ QTW_IGNORE_RANGE_TABLE

#define QTW_IGNORE_RANGE_TABLE   0x08 /* skip rangetable entirely */

Definition at line 26 of file nodeFuncs.h.

◆ QTW_IGNORE_RC_SUBQUERIES

#define QTW_IGNORE_RC_SUBQUERIES   0x03 /* both of above */

Definition at line 24 of file nodeFuncs.h.

◆ QTW_IGNORE_RT_SUBQUERIES

#define QTW_IGNORE_RT_SUBQUERIES   0x01 /* subqueries in rtable */

Definition at line 22 of file nodeFuncs.h.

◆ query_or_expression_tree_mutator

#define query_or_expression_tree_mutator (   n,
  m,
  c,
 
)     query_or_expression_tree_mutator_impl(n, (tree_mutator_callback) (m), c, f)

Definition at line 171 of file nodeFuncs.h.

◆ query_or_expression_tree_walker

#define query_or_expression_tree_walker (   n,
  w,
  c,
 
)     query_or_expression_tree_walker_impl(n, (tree_walker_callback) (w), c, f)

Definition at line 169 of file nodeFuncs.h.

◆ query_tree_mutator

#define query_tree_mutator (   q,
  m,
  c,
 
)     query_tree_mutator_impl(q, (tree_mutator_callback) (m), c, f)

Definition at line 158 of file nodeFuncs.h.

◆ query_tree_walker

#define query_tree_walker (   q,
  w,
  c,
 
)     query_tree_walker_impl(q, (tree_walker_callback) (w), c, f)

Definition at line 156 of file nodeFuncs.h.

◆ range_table_entry_walker

#define range_table_entry_walker (   r,
  w,
  c,
 
)     range_table_entry_walker_impl(r, (tree_walker_callback) (w), c, f)

Definition at line 166 of file nodeFuncs.h.

◆ range_table_mutator

#define range_table_mutator (   rt,
  m,
  c,
 
)     range_table_mutator_impl(rt, (tree_mutator_callback) (m), c, f)

Definition at line 163 of file nodeFuncs.h.

◆ range_table_walker

#define range_table_walker (   rt,
  w,
  c,
 
)     range_table_walker_impl(rt, (tree_walker_callback) (w), c, f)

Definition at line 161 of file nodeFuncs.h.

◆ raw_expression_tree_walker

#define raw_expression_tree_walker (   n,
  w,
  c 
)     raw_expression_tree_walker_impl(n, (tree_walker_callback) (w), c)

Definition at line 174 of file nodeFuncs.h.

Typedef Documentation

◆ check_function_callback

typedef bool(* check_function_callback) (Oid func_id, void *context)

Definition at line 33 of file nodeFuncs.h.

◆ planstate_tree_walker_callback

typedef bool(* planstate_tree_walker_callback) (struct PlanState *planstate, void *context)

Definition at line 37 of file nodeFuncs.h.

◆ tree_mutator_callback

typedef Node*(* tree_mutator_callback) (Node *node, void *context)

Definition at line 41 of file nodeFuncs.h.

◆ tree_walker_callback

typedef bool(* tree_walker_callback) (Node *node, void *context)

Definition at line 36 of file nodeFuncs.h.

Function Documentation

◆ applyRelabelType()

Node* applyRelabelType ( Node arg,
Oid  rtype,
int32  rtypmod,
Oid  rcollid,
CoercionForm  rformat,
int  rlocation,
bool  overwrite_ok 
)

Definition at line 631 of file nodeFuncs.c.

633 {
634  /*
635  * If we find stacked RelabelTypes (eg, from foo::int::oid) we can discard
636  * all but the top one, and must do so to ensure that semantically
637  * equivalent expressions are equal().
638  */
639  while (arg && IsA(arg, RelabelType))
640  arg = (Node *) ((RelabelType *) arg)->arg;
641 
642  if (arg && IsA(arg, Const))
643  {
644  /* Modify the Const directly to preserve const-flatness. */
645  Const *con = (Const *) arg;
646 
647  if (!overwrite_ok)
648  con = copyObject(con);
649  con->consttype = rtype;
650  con->consttypmod = rtypmod;
651  con->constcollid = rcollid;
652  /* We keep the Const's original location. */
653  return (Node *) con;
654  }
655  else if (exprType(arg) == rtype &&
656  exprTypmod(arg) == rtypmod &&
657  exprCollation(arg) == rcollid)
658  {
659  /* Sometimes we find a nest of relabels that net out to nothing. */
660  return arg;
661  }
662  else
663  {
664  /* Nope, gotta have a RelabelType. */
665  RelabelType *newrelabel = makeNode(RelabelType);
666 
667  newrelabel->arg = (Expr *) arg;
668  newrelabel->resulttype = rtype;
669  newrelabel->resulttypmod = rtypmod;
670  newrelabel->resultcollid = rcollid;
671  newrelabel->relabelformat = rformat;
672  newrelabel->location = rlocation;
673  return (Node *) newrelabel;
674  }
675 }
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:42
int32 exprTypmod(const Node *expr)
Definition: nodeFuncs.c:298
Oid exprCollation(const Node *expr)
Definition: nodeFuncs.c:816
#define IsA(nodeptr, _type_)
Definition: nodes.h:158
#define copyObject(obj)
Definition: nodes.h:224
#define makeNode(_type_)
Definition: nodes.h:155
void * arg
Oid consttype
Definition: primnodes.h:312
Definition: nodes.h:129
Oid resulttype
Definition: primnodes.h:1155
ParseLoc location
Definition: primnodes.h:1162
Expr * arg
Definition: primnodes.h:1154

References arg, RelabelType::arg, Const::consttype, copyObject, exprCollation(), exprType(), exprTypmod(), IsA, RelabelType::location, makeNode, and RelabelType::resulttype.

Referenced by canonicalize_ec_expression(), coerce_type_typmod(), eval_const_expressions_mutator(), generate_setop_tlist(), and relabel_to_typmod().

◆ check_functions_in_node()

bool check_functions_in_node ( Node node,
check_function_callback  checker,
void *  context 
)

Definition at line 1906 of file nodeFuncs.c.

1908 {
1909  switch (nodeTag(node))
1910  {
1911  case T_Aggref:
1912  {
1913  Aggref *expr = (Aggref *) node;
1914 
1915  if (checker(expr->aggfnoid, context))
1916  return true;
1917  }
1918  break;
1919  case T_WindowFunc:
1920  {
1921  WindowFunc *expr = (WindowFunc *) node;
1922 
1923  if (checker(expr->winfnoid, context))
1924  return true;
1925  }
1926  break;
1927  case T_FuncExpr:
1928  {
1929  FuncExpr *expr = (FuncExpr *) node;
1930 
1931  if (checker(expr->funcid, context))
1932  return true;
1933  }
1934  break;
1935  case T_OpExpr:
1936  case T_DistinctExpr: /* struct-equivalent to OpExpr */
1937  case T_NullIfExpr: /* struct-equivalent to OpExpr */
1938  {
1939  OpExpr *expr = (OpExpr *) node;
1940 
1941  /* Set opfuncid if it wasn't set already */
1942  set_opfuncid(expr);
1943  if (checker(expr->opfuncid, context))
1944  return true;
1945  }
1946  break;
1947  case T_ScalarArrayOpExpr:
1948  {
1949  ScalarArrayOpExpr *expr = (ScalarArrayOpExpr *) node;
1950 
1951  set_sa_opfuncid(expr);
1952  if (checker(expr->opfuncid, context))
1953  return true;
1954  }
1955  break;
1956  case T_CoerceViaIO:
1957  {
1958  CoerceViaIO *expr = (CoerceViaIO *) node;
1959  Oid iofunc;
1960  Oid typioparam;
1961  bool typisvarlena;
1962 
1963  /* check the result type's input function */
1965  &iofunc, &typioparam);
1966  if (checker(iofunc, context))
1967  return true;
1968  /* check the input type's output function */
1969  getTypeOutputInfo(exprType((Node *) expr->arg),
1970  &iofunc, &typisvarlena);
1971  if (checker(iofunc, context))
1972  return true;
1973  }
1974  break;
1975  case T_RowCompareExpr:
1976  {
1977  RowCompareExpr *rcexpr = (RowCompareExpr *) node;
1978  ListCell *opid;
1979 
1980  foreach(opid, rcexpr->opnos)
1981  {
1982  Oid opfuncid = get_opcode(lfirst_oid(opid));
1983 
1984  if (checker(opfuncid, context))
1985  return true;
1986  }
1987  }
1988  break;
1989  default:
1990  break;
1991  }
1992  return false;
1993 }
void getTypeOutputInfo(Oid type, Oid *typOutput, bool *typIsVarlena)
Definition: lsyscache.c:2907
RegProcedure get_opcode(Oid opno)
Definition: lsyscache.c:1285
void getTypeInputInfo(Oid type, Oid *typInput, Oid *typIOParam)
Definition: lsyscache.c:2874
void set_sa_opfuncid(ScalarArrayOpExpr *opexpr)
Definition: nodeFuncs.c:1879
void set_opfuncid(OpExpr *opexpr)
Definition: nodeFuncs.c:1868
#define nodeTag(nodeptr)
Definition: nodes.h:133
#define lfirst_oid(lc)
Definition: pg_list.h:174
unsigned int Oid
Definition: postgres_ext.h:31
tree context
Definition: radixtree.h:1829
Oid aggfnoid
Definition: primnodes.h:444
Expr * arg
Definition: primnodes.h:1177
Oid resulttype
Definition: primnodes.h:1178
Oid funcid
Definition: primnodes.h:720
Oid winfnoid
Definition: primnodes.h:567

References Aggref::aggfnoid, CoerceViaIO::arg, context, exprType(), FuncExpr::funcid, get_opcode(), getTypeInputInfo(), getTypeOutputInfo(), lfirst_oid, nodeTag, CoerceViaIO::resulttype, set_opfuncid(), set_sa_opfuncid(), and WindowFunc::winfnoid.

Referenced by check_simple_rowfilter_expr_walker(), contain_leaked_vars_walker(), contain_mutable_functions_walker(), contain_nonstrict_functions_walker(), contain_volatile_functions_not_nextval_walker(), contain_volatile_functions_walker(), and max_parallel_hazard_walker().

◆ exprCollation()

Oid exprCollation ( const Node expr)

Definition at line 816 of file nodeFuncs.c.

817 {
818  Oid coll;
819 
820  if (!expr)
821  return InvalidOid;
822 
823  switch (nodeTag(expr))
824  {
825  case T_Var:
826  coll = ((const Var *) expr)->varcollid;
827  break;
828  case T_Const:
829  coll = ((const Const *) expr)->constcollid;
830  break;
831  case T_Param:
832  coll = ((const Param *) expr)->paramcollid;
833  break;
834  case T_Aggref:
835  coll = ((const Aggref *) expr)->aggcollid;
836  break;
837  case T_GroupingFunc:
838  coll = InvalidOid;
839  break;
840  case T_WindowFunc:
841  coll = ((const WindowFunc *) expr)->wincollid;
842  break;
843  case T_MergeSupportFunc:
844  coll = ((const MergeSupportFunc *) expr)->msfcollid;
845  break;
846  case T_SubscriptingRef:
847  coll = ((const SubscriptingRef *) expr)->refcollid;
848  break;
849  case T_FuncExpr:
850  coll = ((const FuncExpr *) expr)->funccollid;
851  break;
852  case T_NamedArgExpr:
853  coll = exprCollation((Node *) ((const NamedArgExpr *) expr)->arg);
854  break;
855  case T_OpExpr:
856  coll = ((const OpExpr *) expr)->opcollid;
857  break;
858  case T_DistinctExpr:
859  coll = ((const DistinctExpr *) expr)->opcollid;
860  break;
861  case T_NullIfExpr:
862  coll = ((const NullIfExpr *) expr)->opcollid;
863  break;
864  case T_ScalarArrayOpExpr:
865  /* ScalarArrayOpExpr's result is boolean ... */
866  coll = InvalidOid; /* ... so it has no collation */
867  break;
868  case T_BoolExpr:
869  /* BoolExpr's result is boolean ... */
870  coll = InvalidOid; /* ... so it has no collation */
871  break;
872  case T_SubLink:
873  {
874  const SubLink *sublink = (const SubLink *) expr;
875 
876  if (sublink->subLinkType == EXPR_SUBLINK ||
877  sublink->subLinkType == ARRAY_SUBLINK)
878  {
879  /* get the collation of subselect's first target column */
880  Query *qtree = (Query *) sublink->subselect;
881  TargetEntry *tent;
882 
883  if (!qtree || !IsA(qtree, Query))
884  elog(ERROR, "cannot get collation for untransformed sublink");
885  tent = linitial_node(TargetEntry, qtree->targetList);
886  Assert(!tent->resjunk);
887  coll = exprCollation((Node *) tent->expr);
888  /* collation doesn't change if it's converted to array */
889  }
890  else
891  {
892  /* otherwise, SubLink's result is RECORD or BOOLEAN */
893  coll = InvalidOid; /* ... so it has no collation */
894  }
895  }
896  break;
897  case T_SubPlan:
898  {
899  const SubPlan *subplan = (const SubPlan *) expr;
900 
901  if (subplan->subLinkType == EXPR_SUBLINK ||
902  subplan->subLinkType == ARRAY_SUBLINK)
903  {
904  /* get the collation of subselect's first target column */
905  coll = subplan->firstColCollation;
906  /* collation doesn't change if it's converted to array */
907  }
908  else
909  {
910  /* otherwise, SubPlan's result is RECORD or BOOLEAN */
911  coll = InvalidOid; /* ... so it has no collation */
912  }
913  }
914  break;
915  case T_AlternativeSubPlan:
916  {
917  const AlternativeSubPlan *asplan = (const AlternativeSubPlan *) expr;
918 
919  /* subplans should all return the same thing */
920  coll = exprCollation((Node *) linitial(asplan->subplans));
921  }
922  break;
923  case T_FieldSelect:
924  coll = ((const FieldSelect *) expr)->resultcollid;
925  break;
926  case T_FieldStore:
927  /* FieldStore's result is composite ... */
928  coll = InvalidOid; /* ... so it has no collation */
929  break;
930  case T_RelabelType:
931  coll = ((const RelabelType *) expr)->resultcollid;
932  break;
933  case T_CoerceViaIO:
934  coll = ((const CoerceViaIO *) expr)->resultcollid;
935  break;
936  case T_ArrayCoerceExpr:
937  coll = ((const ArrayCoerceExpr *) expr)->resultcollid;
938  break;
939  case T_ConvertRowtypeExpr:
940  /* ConvertRowtypeExpr's result is composite ... */
941  coll = InvalidOid; /* ... so it has no collation */
942  break;
943  case T_CollateExpr:
944  coll = ((const CollateExpr *) expr)->collOid;
945  break;
946  case T_CaseExpr:
947  coll = ((const CaseExpr *) expr)->casecollid;
948  break;
949  case T_CaseTestExpr:
950  coll = ((const CaseTestExpr *) expr)->collation;
951  break;
952  case T_ArrayExpr:
953  coll = ((const ArrayExpr *) expr)->array_collid;
954  break;
955  case T_RowExpr:
956  /* RowExpr's result is composite ... */
957  coll = InvalidOid; /* ... so it has no collation */
958  break;
959  case T_RowCompareExpr:
960  /* RowCompareExpr's result is boolean ... */
961  coll = InvalidOid; /* ... so it has no collation */
962  break;
963  case T_CoalesceExpr:
964  coll = ((const CoalesceExpr *) expr)->coalescecollid;
965  break;
966  case T_MinMaxExpr:
967  coll = ((const MinMaxExpr *) expr)->minmaxcollid;
968  break;
969  case T_SQLValueFunction:
970  /* Returns either NAME or a non-collatable type */
971  if (((const SQLValueFunction *) expr)->type == NAMEOID)
972  coll = C_COLLATION_OID;
973  else
974  coll = InvalidOid;
975  break;
976  case T_XmlExpr:
977 
978  /*
979  * XMLSERIALIZE returns text from non-collatable inputs, so its
980  * collation is always default. The other cases return boolean or
981  * XML, which are non-collatable.
982  */
983  if (((const XmlExpr *) expr)->op == IS_XMLSERIALIZE)
984  coll = DEFAULT_COLLATION_OID;
985  else
986  coll = InvalidOid;
987  break;
988  case T_JsonValueExpr:
989  coll = exprCollation((Node *) ((const JsonValueExpr *) expr)->formatted_expr);
990  break;
991  case T_JsonConstructorExpr:
992  {
993  const JsonConstructorExpr *ctor = (const JsonConstructorExpr *) expr;
994 
995  if (ctor->coercion)
996  coll = exprCollation((Node *) ctor->coercion);
997  else
998  coll = InvalidOid;
999  }
1000  break;
1001  case T_JsonIsPredicate:
1002  /* IS JSON's result is boolean ... */
1003  coll = InvalidOid; /* ... so it has no collation */
1004  break;
1005  case T_JsonExpr:
1006  {
1007  const JsonExpr *jsexpr = (JsonExpr *) expr;
1008 
1009  if (jsexpr->coercion_expr)
1010  coll = exprCollation(jsexpr->coercion_expr);
1011  else
1012  coll = jsexpr->collation;
1013  }
1014  break;
1015  case T_JsonBehavior:
1016  {
1017  const JsonBehavior *behavior = (JsonBehavior *) expr;
1018 
1019  if (behavior->expr)
1020  coll = exprCollation(behavior->expr);
1021  else
1022  coll = InvalidOid;
1023  }
1024  break;
1025  case T_NullTest:
1026  /* NullTest's result is boolean ... */
1027  coll = InvalidOid; /* ... so it has no collation */
1028  break;
1029  case T_BooleanTest:
1030  /* BooleanTest's result is boolean ... */
1031  coll = InvalidOid; /* ... so it has no collation */
1032  break;
1033  case T_CoerceToDomain:
1034  coll = ((const CoerceToDomain *) expr)->resultcollid;
1035  break;
1036  case T_CoerceToDomainValue:
1037  coll = ((const CoerceToDomainValue *) expr)->collation;
1038  break;
1039  case T_SetToDefault:
1040  coll = ((const SetToDefault *) expr)->collation;
1041  break;
1042  case T_CurrentOfExpr:
1043  /* CurrentOfExpr's result is boolean ... */
1044  coll = InvalidOid; /* ... so it has no collation */
1045  break;
1046  case T_NextValueExpr:
1047  /* NextValueExpr's result is an integer type ... */
1048  coll = InvalidOid; /* ... so it has no collation */
1049  break;
1050  case T_InferenceElem:
1051  coll = exprCollation((Node *) ((const InferenceElem *) expr)->expr);
1052  break;
1053  case T_PlaceHolderVar:
1054  coll = exprCollation((Node *) ((const PlaceHolderVar *) expr)->phexpr);
1055  break;
1056  default:
1057  elog(ERROR, "unrecognized node type: %d", (int) nodeTag(expr));
1058  coll = InvalidOid; /* keep compiler quiet */
1059  break;
1060  }
1061  return coll;
1062 }
#define Assert(condition)
Definition: c.h:858
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:224
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:77
#define linitial_node(type, l)
Definition: pg_list.h:181
#define linitial(l)
Definition: pg_list.h:178
#define InvalidOid
Definition: postgres_ext.h:36
@ ARRAY_SUBLINK
Definition: primnodes.h:973
@ EXPR_SUBLINK
Definition: primnodes.h:971
@ IS_XMLSERIALIZE
Definition: primnodes.h:1556
Node * expr
Definition: primnodes.h:1757
Oid collation
Definition: primnodes.h:1828
Node * coercion_expr
Definition: primnodes.h:1817
List * targetList
Definition: parsenodes.h:191
Oid firstColCollation
Definition: primnodes.h:1046
SubLinkType subLinkType
Definition: primnodes.h:1035
Definition: primnodes.h:248
const char * type

References arg, ARRAY_SUBLINK, Assert, JsonConstructorExpr::coercion, JsonExpr::coercion_expr, JsonExpr::collation, elog, ERROR, JsonBehavior::expr, EXPR_SUBLINK, SubPlan::firstColCollation, if(), InvalidOid, IS_XMLSERIALIZE, IsA, linitial, linitial_node, nodeTag, SubLink::subLinkType, SubPlan::subLinkType, AlternativeSubPlan::subplans, SubLink::subselect, Query::targetList, and type.

Referenced by addRangeTableEntryForFunction(), addRangeTableEntryForSubquery(), analyzeCTE(), analyzeCTETargetList(), applyRelabelType(), assign_collations_walker(), assign_hypothetical_collations(), build_expression_pathkey(), build_pertrans_for_aggref(), build_subplan(), canonicalize_ec_expression(), check_simple_rowfilter_expr_walker(), coerce_type_typmod(), ComputeIndexAttrs(), ComputePartitionAttrs(), convert_EXISTS_to_ANY(), create_ctas_nodata(), create_limit_plan(), create_memoize_plan(), create_unique_plan(), create_windowagg_plan(), DefineVirtualRelation(), eval_const_expressions_mutator(), examine_attribute(), examine_expression(), ExecInitFunctionScan(), ExecInitIndexScan(), ExecTypeFromExprList(), ExecTypeFromTLInternal(), expandRecordVariable(), expandRTE(), exprSetCollation(), extract_grouping_collations(), fix_indexqual_operand(), generate_setop_tlist(), generate_subquery_params(), get_expr_result_type(), get_first_col_type(), inline_function(), make_pathkey_from_sortop(), make_recursive_union(), make_setop(), make_sort_from_groupcols(), make_sort_from_sortclauses(), make_unique_from_sortclauses(), makeJsonConstructorExpr(), makeVarFromTargetEntry(), makeWholeRowVar(), mcv_match_expression(), ordered_set_startup(), pg_get_indexdef_worker(), pg_get_partkeydef_worker(), preprocess_minmax_aggregates(), relabel_to_typmod(), RelationBuildPartitionKey(), RelationGetDummyIndexExpressions(), remove_unused_subquery_outputs(), replace_nestloop_param_placeholdervar(), replace_outer_placeholdervar(), scalararraysel(), set_dummy_tlist_references(), set_joinrel_partition_key_exprs(), tlist_same_collations(), transformCaseExpr(), transformFromClauseItem(), transformJsonTableColumns(), transformMultiAssignRef(), transformPLAssignStmt(), transformSubLink(), and transformWindowDefinitions().

◆ expression_returns_set()

◆ expression_tree_mutator_impl()

Node* expression_tree_mutator_impl ( Node node,
tree_mutator_callback  mutator,
void *  context 
)

Definition at line 2935 of file nodeFuncs.c.

2938 {
2939  /*
2940  * The mutator has already decided not to modify the current node, but we
2941  * must call the mutator for any sub-nodes.
2942  */
2943 
2944 #define FLATCOPY(newnode, node, nodetype) \
2945  ( (newnode) = (nodetype *) palloc(sizeof(nodetype)), \
2946  memcpy((newnode), (node), sizeof(nodetype)) )
2947 
2948 #define MUTATE(newfield, oldfield, fieldtype) \
2949  ( (newfield) = (fieldtype) mutator((Node *) (oldfield), context) )
2950 
2951  if (node == NULL)
2952  return NULL;
2953 
2954  /* Guard against stack overflow due to overly complex expressions */
2956 
2957  switch (nodeTag(node))
2958  {
2959  /*
2960  * Primitive node types with no expression subnodes. Var and
2961  * Const are frequent enough to deserve special cases, the others
2962  * we just use copyObject for.
2963  */
2964  case T_Var:
2965  {
2966  Var *var = (Var *) node;
2967  Var *newnode;
2968 
2969  FLATCOPY(newnode, var, Var);
2970  /* Assume we need not copy the varnullingrels bitmapset */
2971  return (Node *) newnode;
2972  }
2973  break;
2974  case T_Const:
2975  {
2976  Const *oldnode = (Const *) node;
2977  Const *newnode;
2978 
2979  FLATCOPY(newnode, oldnode, Const);
2980  /* XXX we don't bother with datumCopy; should we? */
2981  return (Node *) newnode;
2982  }
2983  break;
2984  case T_Param:
2985  case T_CaseTestExpr:
2986  case T_SQLValueFunction:
2987  case T_JsonFormat:
2988  case T_CoerceToDomainValue:
2989  case T_SetToDefault:
2990  case T_CurrentOfExpr:
2991  case T_NextValueExpr:
2992  case T_RangeTblRef:
2993  case T_SortGroupClause:
2994  case T_CTESearchClause:
2995  case T_MergeSupportFunc:
2996  return (Node *) copyObject(node);
2997  case T_WithCheckOption:
2998  {
2999  WithCheckOption *wco = (WithCheckOption *) node;
3000  WithCheckOption *newnode;
3001 
3002  FLATCOPY(newnode, wco, WithCheckOption);
3003  MUTATE(newnode->qual, wco->qual, Node *);
3004  return (Node *) newnode;
3005  }
3006  case T_Aggref:
3007  {
3008  Aggref *aggref = (Aggref *) node;
3009  Aggref *newnode;
3010 
3011  FLATCOPY(newnode, aggref, Aggref);
3012  /* assume mutation doesn't change types of arguments */
3013  newnode->aggargtypes = list_copy(aggref->aggargtypes);
3014  MUTATE(newnode->aggdirectargs, aggref->aggdirectargs, List *);
3015  MUTATE(newnode->args, aggref->args, List *);
3016  MUTATE(newnode->aggorder, aggref->aggorder, List *);
3017  MUTATE(newnode->aggdistinct, aggref->aggdistinct, List *);
3018  MUTATE(newnode->aggfilter, aggref->aggfilter, Expr *);
3019  return (Node *) newnode;
3020  }
3021  break;
3022  case T_GroupingFunc:
3023  {
3024  GroupingFunc *grouping = (GroupingFunc *) node;
3025  GroupingFunc *newnode;
3026 
3027  FLATCOPY(newnode, grouping, GroupingFunc);
3028  MUTATE(newnode->args, grouping->args, List *);
3029 
3030  /*
3031  * We assume here that mutating the arguments does not change
3032  * the semantics, i.e. that the arguments are not mutated in a
3033  * way that makes them semantically different from their
3034  * previously matching expressions in the GROUP BY clause.
3035  *
3036  * If a mutator somehow wanted to do this, it would have to
3037  * handle the refs and cols lists itself as appropriate.
3038  */
3039  newnode->refs = list_copy(grouping->refs);
3040  newnode->cols = list_copy(grouping->cols);
3041 
3042  return (Node *) newnode;
3043  }
3044  break;
3045  case T_WindowFunc:
3046  {
3047  WindowFunc *wfunc = (WindowFunc *) node;
3048  WindowFunc *newnode;
3049 
3050  FLATCOPY(newnode, wfunc, WindowFunc);
3051  MUTATE(newnode->args, wfunc->args, List *);
3052  MUTATE(newnode->aggfilter, wfunc->aggfilter, Expr *);
3053  return (Node *) newnode;
3054  }
3055  break;
3056  case T_SubscriptingRef:
3057  {
3058  SubscriptingRef *sbsref = (SubscriptingRef *) node;
3059  SubscriptingRef *newnode;
3060 
3061  FLATCOPY(newnode, sbsref, SubscriptingRef);
3062  MUTATE(newnode->refupperindexpr, sbsref->refupperindexpr,
3063  List *);
3064  MUTATE(newnode->reflowerindexpr, sbsref->reflowerindexpr,
3065  List *);
3066  MUTATE(newnode->refexpr, sbsref->refexpr,
3067  Expr *);
3068  MUTATE(newnode->refassgnexpr, sbsref->refassgnexpr,
3069  Expr *);
3070 
3071  return (Node *) newnode;
3072  }
3073  break;
3074  case T_FuncExpr:
3075  {
3076  FuncExpr *expr = (FuncExpr *) node;
3077  FuncExpr *newnode;
3078 
3079  FLATCOPY(newnode, expr, FuncExpr);
3080  MUTATE(newnode->args, expr->args, List *);
3081  return (Node *) newnode;
3082  }
3083  break;
3084  case T_NamedArgExpr:
3085  {
3086  NamedArgExpr *nexpr = (NamedArgExpr *) node;
3087  NamedArgExpr *newnode;
3088 
3089  FLATCOPY(newnode, nexpr, NamedArgExpr);
3090  MUTATE(newnode->arg, nexpr->arg, Expr *);
3091  return (Node *) newnode;
3092  }
3093  break;
3094  case T_OpExpr:
3095  {
3096  OpExpr *expr = (OpExpr *) node;
3097  OpExpr *newnode;
3098 
3099  FLATCOPY(newnode, expr, OpExpr);
3100  MUTATE(newnode->args, expr->args, List *);
3101  return (Node *) newnode;
3102  }
3103  break;
3104  case T_DistinctExpr:
3105  {
3106  DistinctExpr *expr = (DistinctExpr *) node;
3107  DistinctExpr *newnode;
3108 
3109  FLATCOPY(newnode, expr, DistinctExpr);
3110  MUTATE(newnode->args, expr->args, List *);
3111  return (Node *) newnode;
3112  }
3113  break;
3114  case T_NullIfExpr:
3115  {
3116  NullIfExpr *expr = (NullIfExpr *) node;
3117  NullIfExpr *newnode;
3118 
3119  FLATCOPY(newnode, expr, NullIfExpr);
3120  MUTATE(newnode->args, expr->args, List *);
3121  return (Node *) newnode;
3122  }
3123  break;
3124  case T_ScalarArrayOpExpr:
3125  {
3126  ScalarArrayOpExpr *expr = (ScalarArrayOpExpr *) node;
3127  ScalarArrayOpExpr *newnode;
3128 
3129  FLATCOPY(newnode, expr, ScalarArrayOpExpr);
3130  MUTATE(newnode->args, expr->args, List *);
3131  return (Node *) newnode;
3132  }
3133  break;
3134  case T_BoolExpr:
3135  {
3136  BoolExpr *expr = (BoolExpr *) node;
3137  BoolExpr *newnode;
3138 
3139  FLATCOPY(newnode, expr, BoolExpr);
3140  MUTATE(newnode->args, expr->args, List *);
3141  return (Node *) newnode;
3142  }
3143  break;
3144  case T_SubLink:
3145  {
3146  SubLink *sublink = (SubLink *) node;
3147  SubLink *newnode;
3148 
3149  FLATCOPY(newnode, sublink, SubLink);
3150  MUTATE(newnode->testexpr, sublink->testexpr, Node *);
3151 
3152  /*
3153  * Also invoke the mutator on the sublink's Query node, so it
3154  * can recurse into the sub-query if it wants to.
3155  */
3156  MUTATE(newnode->subselect, sublink->subselect, Node *);
3157  return (Node *) newnode;
3158  }
3159  break;
3160  case T_SubPlan:
3161  {
3162  SubPlan *subplan = (SubPlan *) node;
3163  SubPlan *newnode;
3164 
3165  FLATCOPY(newnode, subplan, SubPlan);
3166  /* transform testexpr */
3167  MUTATE(newnode->testexpr, subplan->testexpr, Node *);
3168  /* transform args list (params to be passed to subplan) */
3169  MUTATE(newnode->args, subplan->args, List *);
3170  /* but not the sub-Plan itself, which is referenced as-is */
3171  return (Node *) newnode;
3172  }
3173  break;
3174  case T_AlternativeSubPlan:
3175  {
3176  AlternativeSubPlan *asplan = (AlternativeSubPlan *) node;
3177  AlternativeSubPlan *newnode;
3178 
3179  FLATCOPY(newnode, asplan, AlternativeSubPlan);
3180  MUTATE(newnode->subplans, asplan->subplans, List *);
3181  return (Node *) newnode;
3182  }
3183  break;
3184  case T_FieldSelect:
3185  {
3186  FieldSelect *fselect = (FieldSelect *) node;
3187  FieldSelect *newnode;
3188 
3189  FLATCOPY(newnode, fselect, FieldSelect);
3190  MUTATE(newnode->arg, fselect->arg, Expr *);
3191  return (Node *) newnode;
3192  }
3193  break;
3194  case T_FieldStore:
3195  {
3196  FieldStore *fstore = (FieldStore *) node;
3197  FieldStore *newnode;
3198 
3199  FLATCOPY(newnode, fstore, FieldStore);
3200  MUTATE(newnode->arg, fstore->arg, Expr *);
3201  MUTATE(newnode->newvals, fstore->newvals, List *);
3202  newnode->fieldnums = list_copy(fstore->fieldnums);
3203  return (Node *) newnode;
3204  }
3205  break;
3206  case T_RelabelType:
3207  {
3208  RelabelType *relabel = (RelabelType *) node;
3209  RelabelType *newnode;
3210 
3211  FLATCOPY(newnode, relabel, RelabelType);
3212  MUTATE(newnode->arg, relabel->arg, Expr *);
3213  return (Node *) newnode;
3214  }
3215  break;
3216  case T_CoerceViaIO:
3217  {
3218  CoerceViaIO *iocoerce = (CoerceViaIO *) node;
3219  CoerceViaIO *newnode;
3220 
3221  FLATCOPY(newnode, iocoerce, CoerceViaIO);
3222  MUTATE(newnode->arg, iocoerce->arg, Expr *);
3223  return (Node *) newnode;
3224  }
3225  break;
3226  case T_ArrayCoerceExpr:
3227  {
3228  ArrayCoerceExpr *acoerce = (ArrayCoerceExpr *) node;
3229  ArrayCoerceExpr *newnode;
3230 
3231  FLATCOPY(newnode, acoerce, ArrayCoerceExpr);
3232  MUTATE(newnode->arg, acoerce->arg, Expr *);
3233  MUTATE(newnode->elemexpr, acoerce->elemexpr, Expr *);
3234  return (Node *) newnode;
3235  }
3236  break;
3237  case T_ConvertRowtypeExpr:
3238  {
3239  ConvertRowtypeExpr *convexpr = (ConvertRowtypeExpr *) node;
3240  ConvertRowtypeExpr *newnode;
3241 
3242  FLATCOPY(newnode, convexpr, ConvertRowtypeExpr);
3243  MUTATE(newnode->arg, convexpr->arg, Expr *);
3244  return (Node *) newnode;
3245  }
3246  break;
3247  case T_CollateExpr:
3248  {
3249  CollateExpr *collate = (CollateExpr *) node;
3250  CollateExpr *newnode;
3251 
3252  FLATCOPY(newnode, collate, CollateExpr);
3253  MUTATE(newnode->arg, collate->arg, Expr *);
3254  return (Node *) newnode;
3255  }
3256  break;
3257  case T_CaseExpr:
3258  {
3259  CaseExpr *caseexpr = (CaseExpr *) node;
3260  CaseExpr *newnode;
3261 
3262  FLATCOPY(newnode, caseexpr, CaseExpr);
3263  MUTATE(newnode->arg, caseexpr->arg, Expr *);
3264  MUTATE(newnode->args, caseexpr->args, List *);
3265  MUTATE(newnode->defresult, caseexpr->defresult, Expr *);
3266  return (Node *) newnode;
3267  }
3268  break;
3269  case T_CaseWhen:
3270  {
3271  CaseWhen *casewhen = (CaseWhen *) node;
3272  CaseWhen *newnode;
3273 
3274  FLATCOPY(newnode, casewhen, CaseWhen);
3275  MUTATE(newnode->expr, casewhen->expr, Expr *);
3276  MUTATE(newnode->result, casewhen->result, Expr *);
3277  return (Node *) newnode;
3278  }
3279  break;
3280  case T_ArrayExpr:
3281  {
3282  ArrayExpr *arrayexpr = (ArrayExpr *) node;
3283  ArrayExpr *newnode;
3284 
3285  FLATCOPY(newnode, arrayexpr, ArrayExpr);
3286  MUTATE(newnode->elements, arrayexpr->elements, List *);
3287  return (Node *) newnode;
3288  }
3289  break;
3290  case T_RowExpr:
3291  {
3292  RowExpr *rowexpr = (RowExpr *) node;
3293  RowExpr *newnode;
3294 
3295  FLATCOPY(newnode, rowexpr, RowExpr);
3296  MUTATE(newnode->args, rowexpr->args, List *);
3297  /* Assume colnames needn't be duplicated */
3298  return (Node *) newnode;
3299  }
3300  break;
3301  case T_RowCompareExpr:
3302  {
3303  RowCompareExpr *rcexpr = (RowCompareExpr *) node;
3304  RowCompareExpr *newnode;
3305 
3306  FLATCOPY(newnode, rcexpr, RowCompareExpr);
3307  MUTATE(newnode->largs, rcexpr->largs, List *);
3308  MUTATE(newnode->rargs, rcexpr->rargs, List *);
3309  return (Node *) newnode;
3310  }
3311  break;
3312  case T_CoalesceExpr:
3313  {
3314  CoalesceExpr *coalesceexpr = (CoalesceExpr *) node;
3315  CoalesceExpr *newnode;
3316 
3317  FLATCOPY(newnode, coalesceexpr, CoalesceExpr);
3318  MUTATE(newnode->args, coalesceexpr->args, List *);
3319  return (Node *) newnode;
3320  }
3321  break;
3322  case T_MinMaxExpr:
3323  {
3324  MinMaxExpr *minmaxexpr = (MinMaxExpr *) node;
3325  MinMaxExpr *newnode;
3326 
3327  FLATCOPY(newnode, minmaxexpr, MinMaxExpr);
3328  MUTATE(newnode->args, minmaxexpr->args, List *);
3329  return (Node *) newnode;
3330  }
3331  break;
3332  case T_XmlExpr:
3333  {
3334  XmlExpr *xexpr = (XmlExpr *) node;
3335  XmlExpr *newnode;
3336 
3337  FLATCOPY(newnode, xexpr, XmlExpr);
3338  MUTATE(newnode->named_args, xexpr->named_args, List *);
3339  /* assume mutator does not care about arg_names */
3340  MUTATE(newnode->args, xexpr->args, List *);
3341  return (Node *) newnode;
3342  }
3343  break;
3344  case T_JsonReturning:
3345  {
3346  JsonReturning *jr = (JsonReturning *) node;
3347  JsonReturning *newnode;
3348 
3349  FLATCOPY(newnode, jr, JsonReturning);
3350  MUTATE(newnode->format, jr->format, JsonFormat *);
3351 
3352  return (Node *) newnode;
3353  }
3354  case T_JsonValueExpr:
3355  {
3356  JsonValueExpr *jve = (JsonValueExpr *) node;
3357  JsonValueExpr *newnode;
3358 
3359  FLATCOPY(newnode, jve, JsonValueExpr);
3360  MUTATE(newnode->raw_expr, jve->raw_expr, Expr *);
3361  MUTATE(newnode->formatted_expr, jve->formatted_expr, Expr *);
3362  MUTATE(newnode->format, jve->format, JsonFormat *);
3363 
3364  return (Node *) newnode;
3365  }
3366  case T_JsonConstructorExpr:
3367  {
3368  JsonConstructorExpr *jce = (JsonConstructorExpr *) node;
3369  JsonConstructorExpr *newnode;
3370 
3371  FLATCOPY(newnode, jce, JsonConstructorExpr);
3372  MUTATE(newnode->args, jce->args, List *);
3373  MUTATE(newnode->func, jce->func, Expr *);
3374  MUTATE(newnode->coercion, jce->coercion, Expr *);
3375  MUTATE(newnode->returning, jce->returning, JsonReturning *);
3376 
3377  return (Node *) newnode;
3378  }
3379  case T_JsonIsPredicate:
3380  {
3381  JsonIsPredicate *pred = (JsonIsPredicate *) node;
3382  JsonIsPredicate *newnode;
3383 
3384  FLATCOPY(newnode, pred, JsonIsPredicate);
3385  MUTATE(newnode->expr, pred->expr, Node *);
3386  MUTATE(newnode->format, pred->format, JsonFormat *);
3387 
3388  return (Node *) newnode;
3389  }
3390  case T_JsonExpr:
3391  {
3392  JsonExpr *jexpr = (JsonExpr *) node;
3393  JsonExpr *newnode;
3394 
3395  FLATCOPY(newnode, jexpr, JsonExpr);
3396  MUTATE(newnode->formatted_expr, jexpr->formatted_expr, Node *);
3397  MUTATE(newnode->path_spec, jexpr->path_spec, Node *);
3398  MUTATE(newnode->coercion_expr, jexpr->coercion_expr, Node *);
3399  MUTATE(newnode->passing_values, jexpr->passing_values, List *);
3400  /* assume mutator does not care about passing_names */
3401  MUTATE(newnode->on_empty, jexpr->on_empty, JsonBehavior *);
3402  MUTATE(newnode->on_error, jexpr->on_error, JsonBehavior *);
3403  return (Node *) newnode;
3404  }
3405  break;
3406  case T_JsonBehavior:
3407  {
3408  JsonBehavior *behavior = (JsonBehavior *) node;
3409  JsonBehavior *newnode;
3410 
3411  FLATCOPY(newnode, behavior, JsonBehavior);
3412  MUTATE(newnode->expr, behavior->expr, Node *);
3413  return (Node *) newnode;
3414  }
3415  break;
3416  case T_NullTest:
3417  {
3418  NullTest *ntest = (NullTest *) node;
3419  NullTest *newnode;
3420 
3421  FLATCOPY(newnode, ntest, NullTest);
3422  MUTATE(newnode->arg, ntest->arg, Expr *);
3423  return (Node *) newnode;
3424  }
3425  break;
3426  case T_BooleanTest:
3427  {
3428  BooleanTest *btest = (BooleanTest *) node;
3429  BooleanTest *newnode;
3430 
3431  FLATCOPY(newnode, btest, BooleanTest);
3432  MUTATE(newnode->arg, btest->arg, Expr *);
3433  return (Node *) newnode;
3434  }
3435  break;
3436  case T_CoerceToDomain:
3437  {
3438  CoerceToDomain *ctest = (CoerceToDomain *) node;
3439  CoerceToDomain *newnode;
3440 
3441  FLATCOPY(newnode, ctest, CoerceToDomain);
3442  MUTATE(newnode->arg, ctest->arg, Expr *);
3443  return (Node *) newnode;
3444  }
3445  break;
3446  case T_TargetEntry:
3447  {
3448  TargetEntry *targetentry = (TargetEntry *) node;
3449  TargetEntry *newnode;
3450 
3451  FLATCOPY(newnode, targetentry, TargetEntry);
3452  MUTATE(newnode->expr, targetentry->expr, Expr *);
3453  return (Node *) newnode;
3454  }
3455  break;
3456  case T_Query:
3457  /* Do nothing with a sub-Query, per discussion above */
3458  return node;
3459  case T_WindowClause:
3460  {
3461  WindowClause *wc = (WindowClause *) node;
3462  WindowClause *newnode;
3463 
3464  FLATCOPY(newnode, wc, WindowClause);
3465  MUTATE(newnode->partitionClause, wc->partitionClause, List *);
3466  MUTATE(newnode->orderClause, wc->orderClause, List *);
3467  MUTATE(newnode->startOffset, wc->startOffset, Node *);
3468  MUTATE(newnode->endOffset, wc->endOffset, Node *);
3469  MUTATE(newnode->runCondition, wc->runCondition, List *);
3470  return (Node *) newnode;
3471  }
3472  break;
3473  case T_CTECycleClause:
3474  {
3475  CTECycleClause *cc = (CTECycleClause *) node;
3476  CTECycleClause *newnode;
3477 
3478  FLATCOPY(newnode, cc, CTECycleClause);
3479  MUTATE(newnode->cycle_mark_value, cc->cycle_mark_value, Node *);
3481  return (Node *) newnode;
3482  }
3483  break;
3484  case T_CommonTableExpr:
3485  {
3486  CommonTableExpr *cte = (CommonTableExpr *) node;
3487  CommonTableExpr *newnode;
3488 
3489  FLATCOPY(newnode, cte, CommonTableExpr);
3490 
3491  /*
3492  * Also invoke the mutator on the CTE's Query node, so it can
3493  * recurse into the sub-query if it wants to.
3494  */
3495  MUTATE(newnode->ctequery, cte->ctequery, Node *);
3496 
3497  MUTATE(newnode->search_clause, cte->search_clause, CTESearchClause *);
3498  MUTATE(newnode->cycle_clause, cte->cycle_clause, CTECycleClause *);
3499 
3500  return (Node *) newnode;
3501  }
3502  break;
3503  case T_PartitionBoundSpec:
3504  {
3505  PartitionBoundSpec *pbs = (PartitionBoundSpec *) node;
3506  PartitionBoundSpec *newnode;
3507 
3508  FLATCOPY(newnode, pbs, PartitionBoundSpec);
3509  MUTATE(newnode->listdatums, pbs->listdatums, List *);
3510  MUTATE(newnode->lowerdatums, pbs->lowerdatums, List *);
3511  MUTATE(newnode->upperdatums, pbs->upperdatums, List *);
3512  return (Node *) newnode;
3513  }
3514  break;
3515  case T_PartitionRangeDatum:
3516  {
3517  PartitionRangeDatum *prd = (PartitionRangeDatum *) node;
3518  PartitionRangeDatum *newnode;
3519 
3520  FLATCOPY(newnode, prd, PartitionRangeDatum);
3521  MUTATE(newnode->value, prd->value, Node *);
3522  return (Node *) newnode;
3523  }
3524  break;
3525  case T_List:
3526  {
3527  /*
3528  * We assume the mutator isn't interested in the list nodes
3529  * per se, so just invoke it on each list element. NOTE: this
3530  * would fail badly on a list with integer elements!
3531  */
3532  List *resultlist;
3533  ListCell *temp;
3534 
3535  resultlist = NIL;
3536  foreach(temp, (List *) node)
3537  {
3538  resultlist = lappend(resultlist,
3539  mutator((Node *) lfirst(temp),
3540  context));
3541  }
3542  return (Node *) resultlist;
3543  }
3544  break;
3545  case T_FromExpr:
3546  {
3547  FromExpr *from = (FromExpr *) node;
3548  FromExpr *newnode;
3549 
3550  FLATCOPY(newnode, from, FromExpr);
3551  MUTATE(newnode->fromlist, from->fromlist, List *);
3552  MUTATE(newnode->quals, from->quals, Node *);
3553  return (Node *) newnode;
3554  }
3555  break;
3556  case T_OnConflictExpr:
3557  {
3558  OnConflictExpr *oc = (OnConflictExpr *) node;
3559  OnConflictExpr *newnode;
3560 
3561  FLATCOPY(newnode, oc, OnConflictExpr);
3562  MUTATE(newnode->arbiterElems, oc->arbiterElems, List *);
3563  MUTATE(newnode->arbiterWhere, oc->arbiterWhere, Node *);
3564  MUTATE(newnode->onConflictSet, oc->onConflictSet, List *);
3565  MUTATE(newnode->onConflictWhere, oc->onConflictWhere, Node *);
3566  MUTATE(newnode->exclRelTlist, oc->exclRelTlist, List *);
3567 
3568  return (Node *) newnode;
3569  }
3570  break;
3571  case T_MergeAction:
3572  {
3573  MergeAction *action = (MergeAction *) node;
3574  MergeAction *newnode;
3575 
3576  FLATCOPY(newnode, action, MergeAction);
3577  MUTATE(newnode->qual, action->qual, Node *);
3578  MUTATE(newnode->targetList, action->targetList, List *);
3579 
3580  return (Node *) newnode;
3581  }
3582  break;
3583  case T_PartitionPruneStepOp:
3584  {
3585  PartitionPruneStepOp *opstep = (PartitionPruneStepOp *) node;
3586  PartitionPruneStepOp *newnode;
3587 
3588  FLATCOPY(newnode, opstep, PartitionPruneStepOp);
3589  MUTATE(newnode->exprs, opstep->exprs, List *);
3590 
3591  return (Node *) newnode;
3592  }
3593  break;
3594  case T_PartitionPruneStepCombine:
3595  /* no expression sub-nodes */
3596  return (Node *) copyObject(node);
3597  case T_JoinExpr:
3598  {
3599  JoinExpr *join = (JoinExpr *) node;
3600  JoinExpr *newnode;
3601 
3602  FLATCOPY(newnode, join, JoinExpr);
3603  MUTATE(newnode->larg, join->larg, Node *);
3604  MUTATE(newnode->rarg, join->rarg, Node *);
3605  MUTATE(newnode->quals, join->quals, Node *);
3606  /* We do not mutate alias or using by default */
3607  return (Node *) newnode;
3608  }
3609  break;
3610  case T_SetOperationStmt:
3611  {
3612  SetOperationStmt *setop = (SetOperationStmt *) node;
3613  SetOperationStmt *newnode;
3614 
3615  FLATCOPY(newnode, setop, SetOperationStmt);
3616  MUTATE(newnode->larg, setop->larg, Node *);
3617  MUTATE(newnode->rarg, setop->rarg, Node *);
3618  /* We do not mutate groupClauses by default */
3619  return (Node *) newnode;
3620  }
3621  break;
3622  case T_IndexClause:
3623  {
3624  IndexClause *iclause = (IndexClause *) node;
3625  IndexClause *newnode;
3626 
3627  FLATCOPY(newnode, iclause, IndexClause);
3628  MUTATE(newnode->rinfo, iclause->rinfo, RestrictInfo *);
3629  MUTATE(newnode->indexquals, iclause->indexquals, List *);
3630  return (Node *) newnode;
3631  }
3632  break;
3633  case T_PlaceHolderVar:
3634  {
3635  PlaceHolderVar *phv = (PlaceHolderVar *) node;
3636  PlaceHolderVar *newnode;
3637 
3638  FLATCOPY(newnode, phv, PlaceHolderVar);
3639  MUTATE(newnode->phexpr, phv->phexpr, Expr *);
3640  /* Assume we need not copy the relids bitmapsets */
3641  return (Node *) newnode;
3642  }
3643  break;
3644  case T_InferenceElem:
3645  {
3646  InferenceElem *inferenceelemdexpr = (InferenceElem *) node;
3647  InferenceElem *newnode;
3648 
3649  FLATCOPY(newnode, inferenceelemdexpr, InferenceElem);
3650  MUTATE(newnode->expr, newnode->expr, Node *);
3651  return (Node *) newnode;
3652  }
3653  break;
3654  case T_AppendRelInfo:
3655  {
3656  AppendRelInfo *appinfo = (AppendRelInfo *) node;
3657  AppendRelInfo *newnode;
3658 
3659  FLATCOPY(newnode, appinfo, AppendRelInfo);
3660  MUTATE(newnode->translated_vars, appinfo->translated_vars, List *);
3661  /* Assume nothing need be done with parent_colnos[] */
3662  return (Node *) newnode;
3663  }
3664  break;
3665  case T_PlaceHolderInfo:
3666  {
3667  PlaceHolderInfo *phinfo = (PlaceHolderInfo *) node;
3668  PlaceHolderInfo *newnode;
3669 
3670  FLATCOPY(newnode, phinfo, PlaceHolderInfo);
3671  MUTATE(newnode->ph_var, phinfo->ph_var, PlaceHolderVar *);
3672  /* Assume we need not copy the relids bitmapsets */
3673  return (Node *) newnode;
3674  }
3675  break;
3676  case T_RangeTblFunction:
3677  {
3678  RangeTblFunction *rtfunc = (RangeTblFunction *) node;
3679  RangeTblFunction *newnode;
3680 
3681  FLATCOPY(newnode, rtfunc, RangeTblFunction);
3682  MUTATE(newnode->funcexpr, rtfunc->funcexpr, Node *);
3683  /* Assume we need not copy the coldef info lists */
3684  return (Node *) newnode;
3685  }
3686  break;
3687  case T_TableSampleClause:
3688  {
3689  TableSampleClause *tsc = (TableSampleClause *) node;
3690  TableSampleClause *newnode;
3691 
3692  FLATCOPY(newnode, tsc, TableSampleClause);
3693  MUTATE(newnode->args, tsc->args, List *);
3694  MUTATE(newnode->repeatable, tsc->repeatable, Expr *);
3695  return (Node *) newnode;
3696  }
3697  break;
3698  case T_TableFunc:
3699  {
3700  TableFunc *tf = (TableFunc *) node;
3701  TableFunc *newnode;
3702 
3703  FLATCOPY(newnode, tf, TableFunc);
3704  MUTATE(newnode->ns_uris, tf->ns_uris, List *);
3705  MUTATE(newnode->docexpr, tf->docexpr, Node *);
3706  MUTATE(newnode->rowexpr, tf->rowexpr, Node *);
3707  MUTATE(newnode->colexprs, tf->colexprs, List *);
3708  MUTATE(newnode->coldefexprs, tf->coldefexprs, List *);
3709  MUTATE(newnode->colvalexprs, tf->colvalexprs, List *);
3710  MUTATE(newnode->passingvalexprs, tf->passingvalexprs, List *);
3711  return (Node *) newnode;
3712  }
3713  break;
3714  default:
3715  elog(ERROR, "unrecognized node type: %d",
3716  (int) nodeTag(node));
3717  break;
3718  }
3719  /* can't get here, but keep compiler happy */
3720  return NULL;
3721 }
List * lappend(List *list, void *datum)
Definition: list.c:339
List * list_copy(const List *oldlist)
Definition: list.c:1573
#define FLATCOPY(newnode, node, nodetype)
#define MUTATE(newfield, oldfield, fieldtype)
#define lfirst(lc)
Definition: pg_list.h:172
#define NIL
Definition: pg_list.h:68
void check_stack_depth(void)
Definition: postgres.c:3531
List * aggdistinct
Definition: primnodes.h:474
List * aggdirectargs
Definition: primnodes.h:465
List * args
Definition: primnodes.h:468
Expr * aggfilter
Definition: primnodes.h:477
List * aggorder
Definition: primnodes.h:471
List * translated_vars
Definition: pathnodes.h:2985
List * elements
Definition: primnodes.h:1350
List * args
Definition: primnodes.h:910
Expr * arg
Definition: primnodes.h:1954
Node * cycle_mark_default
Definition: parsenodes.h:1663
Node * cycle_mark_value
Definition: parsenodes.h:1662
Expr * arg
Definition: primnodes.h:1283
Expr * defresult
Definition: primnodes.h:1285
List * args
Definition: primnodes.h:1284
Expr * result
Definition: primnodes.h:1296
Expr * expr
Definition: primnodes.h:1295
List * args
Definition: primnodes.h:1462
Expr * arg
Definition: primnodes.h:1249
Expr * arg
Definition: primnodes.h:1098
List * newvals
Definition: primnodes.h:1130
Expr * arg
Definition: primnodes.h:1129
Node * quals
Definition: primnodes.h:2281
List * fromlist
Definition: primnodes.h:2280
List * args
Definition: primnodes.h:738
List * indexquals
Definition: pathnodes.h:1748
struct RestrictInfo * rinfo
Definition: pathnodes.h:1747
Node * quals
Definition: primnodes.h:2261
Node * larg
Definition: primnodes.h:2254
Node * rarg
Definition: primnodes.h:2255
JsonReturning * returning
Definition: primnodes.h:1676
Node * formatted_expr
Definition: primnodes.h:1789
List * passing_values
Definition: primnodes.h:1802
JsonBehavior * on_empty
Definition: primnodes.h:1805
Node * path_spec
Definition: primnodes.h:1795
JsonBehavior * on_error
Definition: primnodes.h:1806
JsonFormat * format
Definition: primnodes.h:1702
JsonFormat * format
Definition: primnodes.h:1633
Expr * formatted_expr
Definition: primnodes.h:1650
JsonFormat * format
Definition: primnodes.h:1651
Expr * raw_expr
Definition: primnodes.h:1649
Definition: pg_list.h:54
Node * qual
Definition: primnodes.h:1982
List * targetList
Definition: primnodes.h:1983
List * args
Definition: primnodes.h:1488
Expr * arg
Definition: primnodes.h:761
Expr * arg
Definition: primnodes.h:1930
List * arbiterElems
Definition: primnodes.h:2299
List * onConflictSet
Definition: primnodes.h:2305
List * exclRelTlist
Definition: primnodes.h:2308
Node * onConflictWhere
Definition: primnodes.h:2306
Node * arbiterWhere
Definition: primnodes.h:2301
List * args
Definition: primnodes.h:806
PlaceHolderVar * ph_var
Definition: pathnodes.h:3073
List * args
Definition: primnodes.h:1381
List * args
Definition: primnodes.h:1061
Node * testexpr
Definition: primnodes.h:1037
Expr * refassgnexpr
Definition: primnodes.h:673
List * refupperindexpr
Definition: primnodes.h:663
Expr * refexpr
Definition: primnodes.h:671
List * reflowerindexpr
Definition: primnodes.h:669
Node * docexpr
Definition: primnodes.h:119
Node * rowexpr
Definition: primnodes.h:121
List * colexprs
Definition: primnodes.h:131
Expr * expr
Definition: primnodes.h:2162
Node * startOffset
Definition: parsenodes.h:1550
List * partitionClause
Definition: parsenodes.h:1546
Node * endOffset
Definition: parsenodes.h:1551
List * orderClause
Definition: parsenodes.h:1548
List * args
Definition: primnodes.h:575
Expr * aggfilter
Definition: primnodes.h:577
List * args
Definition: primnodes.h:1578
List * named_args
Definition: primnodes.h:1574

References generate_unaccent_rules::action, Aggref::aggdirectargs, Aggref::aggdistinct, Aggref::aggfilter, WindowFunc::aggfilter, Aggref::aggorder, OnConflictExpr::arbiterElems, OnConflictExpr::arbiterWhere, NamedArgExpr::arg, FieldSelect::arg, FieldStore::arg, RelabelType::arg, CoerceViaIO::arg, ArrayCoerceExpr::arg, ConvertRowtypeExpr::arg, CollateExpr::arg, CaseExpr::arg, NullTest::arg, BooleanTest::arg, CoerceToDomain::arg, TableSampleClause::args, Aggref::args, WindowFunc::args, FuncExpr::args, OpExpr::args, ScalarArrayOpExpr::args, BoolExpr::args, SubPlan::args, CaseExpr::args, RowExpr::args, CoalesceExpr::args, MinMaxExpr::args, XmlExpr::args, JsonConstructorExpr::args, check_stack_depth(), JsonConstructorExpr::coercion, JsonExpr::coercion_expr, TableFunc::colexprs, context, copyObject, CommonTableExpr::ctequery, CTECycleClause::cycle_mark_default, CTECycleClause::cycle_mark_value, CaseExpr::defresult, TableFunc::docexpr, ArrayExpr::elements, ArrayCoerceExpr::elemexpr, elog, WindowClause::endOffset, ERROR, OnConflictExpr::exclRelTlist, CaseWhen::expr, JsonIsPredicate::expr, JsonBehavior::expr, InferenceElem::expr, TargetEntry::expr, PartitionPruneStepOp::exprs, FLATCOPY, JsonReturning::format, JsonValueExpr::format, JsonIsPredicate::format, JsonValueExpr::formatted_expr, JsonExpr::formatted_expr, FromExpr::fromlist, JsonConstructorExpr::func, RangeTblFunction::funcexpr, IndexClause::indexquals, lappend(), SetOperationStmt::larg, JoinExpr::larg, RowCompareExpr::largs, lfirst, list_copy(), PartitionBoundSpec::listdatums, PartitionBoundSpec::lowerdatums, MUTATE, XmlExpr::named_args, FieldStore::newvals, NIL, nodeTag, JsonExpr::on_empty, JsonExpr::on_error, OnConflictExpr::onConflictSet, OnConflictExpr::onConflictWhere, WindowClause::orderClause, WindowClause::partitionClause, JsonExpr::passing_values, JsonExpr::path_spec, PlaceHolderInfo::ph_var, WithCheckOption::qual, MergeAction::qual, JoinExpr::quals, FromExpr::quals, SetOperationStmt::rarg, JoinExpr::rarg, RowCompareExpr::rargs, JsonValueExpr::raw_expr, SubscriptingRef::refassgnexpr, SubscriptingRef::refexpr, SubscriptingRef::reflowerindexpr, SubscriptingRef::refupperindexpr, TableSampleClause::repeatable, CaseWhen::result, JsonConstructorExpr::returning, IndexClause::rinfo, TableFunc::rowexpr, WindowClause::startOffset, AlternativeSubPlan::subplans, SubLink::subselect, MergeAction::targetList, SubLink::testexpr, SubPlan::testexpr, AppendRelInfo::translated_vars, PartitionBoundSpec::upperdatums, and PartitionRangeDatum::value.

◆ expression_tree_walker_impl()

bool expression_tree_walker_impl ( Node node,
tree_walker_callback  walker,
void *  context 
)

Definition at line 2089 of file nodeFuncs.c.

2092 {
2093  ListCell *temp;
2094 
2095  /*
2096  * The walker has already visited the current node, and so we need only
2097  * recurse into any sub-nodes it has.
2098  *
2099  * We assume that the walker is not interested in List nodes per se, so
2100  * when we expect a List we just recurse directly to self without
2101  * bothering to call the walker.
2102  */
2103 #define WALK(n) walker((Node *) (n), context)
2104 
2105 #define LIST_WALK(l) expression_tree_walker_impl((Node *) (l), walker, context)
2106 
2107  if (node == NULL)
2108  return false;
2109 
2110  /* Guard against stack overflow due to overly complex expressions */
2112 
2113  switch (nodeTag(node))
2114  {
2115  case T_Var:
2116  case T_Const:
2117  case T_Param:
2118  case T_CaseTestExpr:
2119  case T_SQLValueFunction:
2120  case T_CoerceToDomainValue:
2121  case T_SetToDefault:
2122  case T_CurrentOfExpr:
2123  case T_NextValueExpr:
2124  case T_RangeTblRef:
2125  case T_SortGroupClause:
2126  case T_CTESearchClause:
2127  case T_MergeSupportFunc:
2128  /* primitive node types with no expression subnodes */
2129  break;
2130  case T_WithCheckOption:
2131  return WALK(((WithCheckOption *) node)->qual);
2132  case T_Aggref:
2133  {
2134  Aggref *expr = (Aggref *) node;
2135 
2136  /* recurse directly on Lists */
2137  if (LIST_WALK(expr->aggdirectargs))
2138  return true;
2139  if (LIST_WALK(expr->args))
2140  return true;
2141  if (LIST_WALK(expr->aggorder))
2142  return true;
2143  if (LIST_WALK(expr->aggdistinct))
2144  return true;
2145  if (WALK(expr->aggfilter))
2146  return true;
2147  }
2148  break;
2149  case T_GroupingFunc:
2150  {
2151  GroupingFunc *grouping = (GroupingFunc *) node;
2152 
2153  if (LIST_WALK(grouping->args))
2154  return true;
2155  }
2156  break;
2157  case T_WindowFunc:
2158  {
2159  WindowFunc *expr = (WindowFunc *) node;
2160 
2161  /* recurse directly on List */
2162  if (LIST_WALK(expr->args))
2163  return true;
2164  if (WALK(expr->aggfilter))
2165  return true;
2166  }
2167  break;
2168  case T_SubscriptingRef:
2169  {
2170  SubscriptingRef *sbsref = (SubscriptingRef *) node;
2171 
2172  /* recurse directly for upper/lower container index lists */
2173  if (LIST_WALK(sbsref->refupperindexpr))
2174  return true;
2175  if (LIST_WALK(sbsref->reflowerindexpr))
2176  return true;
2177  /* walker must see the refexpr and refassgnexpr, however */
2178  if (WALK(sbsref->refexpr))
2179  return true;
2180 
2181  if (WALK(sbsref->refassgnexpr))
2182  return true;
2183  }
2184  break;
2185  case T_FuncExpr:
2186  {
2187  FuncExpr *expr = (FuncExpr *) node;
2188 
2189  if (LIST_WALK(expr->args))
2190  return true;
2191  }
2192  break;
2193  case T_NamedArgExpr:
2194  return WALK(((NamedArgExpr *) node)->arg);
2195  case T_OpExpr:
2196  case T_DistinctExpr: /* struct-equivalent to OpExpr */
2197  case T_NullIfExpr: /* struct-equivalent to OpExpr */
2198  {
2199  OpExpr *expr = (OpExpr *) node;
2200 
2201  if (LIST_WALK(expr->args))
2202  return true;
2203  }
2204  break;
2205  case T_ScalarArrayOpExpr:
2206  {
2207  ScalarArrayOpExpr *expr = (ScalarArrayOpExpr *) node;
2208 
2209  if (LIST_WALK(expr->args))
2210  return true;
2211  }
2212  break;
2213  case T_BoolExpr:
2214  {
2215  BoolExpr *expr = (BoolExpr *) node;
2216 
2217  if (LIST_WALK(expr->args))
2218  return true;
2219  }
2220  break;
2221  case T_SubLink:
2222  {
2223  SubLink *sublink = (SubLink *) node;
2224 
2225  if (WALK(sublink->testexpr))
2226  return true;
2227 
2228  /*
2229  * Also invoke the walker on the sublink's Query node, so it
2230  * can recurse into the sub-query if it wants to.
2231  */
2232  return WALK(sublink->subselect);
2233  }
2234  break;
2235  case T_SubPlan:
2236  {
2237  SubPlan *subplan = (SubPlan *) node;
2238 
2239  /* recurse into the testexpr, but not into the Plan */
2240  if (WALK(subplan->testexpr))
2241  return true;
2242  /* also examine args list */
2243  if (LIST_WALK(subplan->args))
2244  return true;
2245  }
2246  break;
2247  case T_AlternativeSubPlan:
2248  return LIST_WALK(((AlternativeSubPlan *) node)->subplans);
2249  case T_FieldSelect:
2250  return WALK(((FieldSelect *) node)->arg);
2251  case T_FieldStore:
2252  {
2253  FieldStore *fstore = (FieldStore *) node;
2254 
2255  if (WALK(fstore->arg))
2256  return true;
2257  if (WALK(fstore->newvals))
2258  return true;
2259  }
2260  break;
2261  case T_RelabelType:
2262  return WALK(((RelabelType *) node)->arg);
2263  case T_CoerceViaIO:
2264  return WALK(((CoerceViaIO *) node)->arg);
2265  case T_ArrayCoerceExpr:
2266  {
2267  ArrayCoerceExpr *acoerce = (ArrayCoerceExpr *) node;
2268 
2269  if (WALK(acoerce->arg))
2270  return true;
2271  if (WALK(acoerce->elemexpr))
2272  return true;
2273  }
2274  break;
2275  case T_ConvertRowtypeExpr:
2276  return WALK(((ConvertRowtypeExpr *) node)->arg);
2277  case T_CollateExpr:
2278  return WALK(((CollateExpr *) node)->arg);
2279  case T_CaseExpr:
2280  {
2281  CaseExpr *caseexpr = (CaseExpr *) node;
2282 
2283  if (WALK(caseexpr->arg))
2284  return true;
2285  /* we assume walker doesn't care about CaseWhens, either */
2286  foreach(temp, caseexpr->args)
2287  {
2288  CaseWhen *when = lfirst_node(CaseWhen, temp);
2289 
2290  if (WALK(when->expr))
2291  return true;
2292  if (WALK(when->result))
2293  return true;
2294  }
2295  if (WALK(caseexpr->defresult))
2296  return true;
2297  }
2298  break;
2299  case T_ArrayExpr:
2300  return WALK(((ArrayExpr *) node)->elements);
2301  case T_RowExpr:
2302  /* Assume colnames isn't interesting */
2303  return WALK(((RowExpr *) node)->args);
2304  case T_RowCompareExpr:
2305  {
2306  RowCompareExpr *rcexpr = (RowCompareExpr *) node;
2307 
2308  if (WALK(rcexpr->largs))
2309  return true;
2310  if (WALK(rcexpr->rargs))
2311  return true;
2312  }
2313  break;
2314  case T_CoalesceExpr:
2315  return WALK(((CoalesceExpr *) node)->args);
2316  case T_MinMaxExpr:
2317  return WALK(((MinMaxExpr *) node)->args);
2318  case T_XmlExpr:
2319  {
2320  XmlExpr *xexpr = (XmlExpr *) node;
2321 
2322  if (WALK(xexpr->named_args))
2323  return true;
2324  /* we assume walker doesn't care about arg_names */
2325  if (WALK(xexpr->args))
2326  return true;
2327  }
2328  break;
2329  case T_JsonValueExpr:
2330  {
2331  JsonValueExpr *jve = (JsonValueExpr *) node;
2332 
2333  if (WALK(jve->raw_expr))
2334  return true;
2335  if (WALK(jve->formatted_expr))
2336  return true;
2337  }
2338  break;
2339  case T_JsonConstructorExpr:
2340  {
2341  JsonConstructorExpr *ctor = (JsonConstructorExpr *) node;
2342 
2343  if (WALK(ctor->args))
2344  return true;
2345  if (WALK(ctor->func))
2346  return true;
2347  if (WALK(ctor->coercion))
2348  return true;
2349  }
2350  break;
2351  case T_JsonIsPredicate:
2352  return WALK(((JsonIsPredicate *) node)->expr);
2353  case T_JsonExpr:
2354  {
2355  JsonExpr *jexpr = (JsonExpr *) node;
2356 
2357  if (WALK(jexpr->formatted_expr))
2358  return true;
2359  if (WALK(jexpr->path_spec))
2360  return true;
2361  if (WALK(jexpr->coercion_expr))
2362  return true;
2363  if (WALK(jexpr->passing_values))
2364  return true;
2365  /* we assume walker doesn't care about passing_names */
2366  if (WALK(jexpr->on_empty))
2367  return true;
2368  if (WALK(jexpr->on_error))
2369  return true;
2370  }
2371  break;
2372  case T_JsonBehavior:
2373  {
2374  JsonBehavior *behavior = (JsonBehavior *) node;
2375 
2376  if (WALK(behavior->expr))
2377  return true;
2378  }
2379  break;
2380  case T_NullTest:
2381  return WALK(((NullTest *) node)->arg);
2382  case T_BooleanTest:
2383  return WALK(((BooleanTest *) node)->arg);
2384  case T_CoerceToDomain:
2385  return WALK(((CoerceToDomain *) node)->arg);
2386  case T_TargetEntry:
2387  return WALK(((TargetEntry *) node)->expr);
2388  case T_Query:
2389  /* Do nothing with a sub-Query, per discussion above */
2390  break;
2391  case T_WindowClause:
2392  {
2393  WindowClause *wc = (WindowClause *) node;
2394 
2395  if (WALK(wc->partitionClause))
2396  return true;
2397  if (WALK(wc->orderClause))
2398  return true;
2399  if (WALK(wc->startOffset))
2400  return true;
2401  if (WALK(wc->endOffset))
2402  return true;
2403  if (WALK(wc->runCondition))
2404  return true;
2405  }
2406  break;
2407  case T_CTECycleClause:
2408  {
2409  CTECycleClause *cc = (CTECycleClause *) node;
2410 
2411  if (WALK(cc->cycle_mark_value))
2412  return true;
2413  if (WALK(cc->cycle_mark_default))
2414  return true;
2415  }
2416  break;
2417  case T_CommonTableExpr:
2418  {
2419  CommonTableExpr *cte = (CommonTableExpr *) node;
2420 
2421  /*
2422  * Invoke the walker on the CTE's Query node, so it can
2423  * recurse into the sub-query if it wants to.
2424  */
2425  if (WALK(cte->ctequery))
2426  return true;
2427 
2428  if (WALK(cte->search_clause))
2429  return true;
2430  if (WALK(cte->cycle_clause))
2431  return true;
2432  }
2433  break;
2434  case T_JsonKeyValue:
2435  {
2436  JsonKeyValue *kv = (JsonKeyValue *) node;
2437 
2438  if (WALK(kv->key))
2439  return true;
2440  if (WALK(kv->value))
2441  return true;
2442  }
2443  break;
2444  case T_JsonObjectConstructor:
2445  {
2447 
2448  if (LIST_WALK(ctor->exprs))
2449  return true;
2450  }
2451  break;
2452  case T_JsonArrayConstructor:
2453  {
2454  JsonArrayConstructor *ctor = (JsonArrayConstructor *) node;
2455 
2456  if (LIST_WALK(ctor->exprs))
2457  return true;
2458  }
2459  break;
2460  case T_JsonArrayQueryConstructor:
2461  {
2463 
2464  if (WALK(ctor->query))
2465  return true;
2466  }
2467  break;
2468  case T_JsonAggConstructor:
2469  {
2470  JsonAggConstructor *ctor = (JsonAggConstructor *) node;
2471 
2472  if (WALK(ctor->agg_filter))
2473  return true;
2474  if (WALK(ctor->agg_order))
2475  return true;
2476  if (WALK(ctor->over))
2477  return true;
2478  }
2479  break;
2480  case T_JsonObjectAgg:
2481  {
2482  JsonObjectAgg *ctor = (JsonObjectAgg *) node;
2483 
2484  if (WALK(ctor->constructor))
2485  return true;
2486  if (WALK(ctor->arg))
2487  return true;
2488  }
2489  break;
2490  case T_JsonArrayAgg:
2491  {
2492  JsonArrayAgg *ctor = (JsonArrayAgg *) node;
2493 
2494  if (WALK(ctor->constructor))
2495  return true;
2496  if (WALK(ctor->arg))
2497  return true;
2498  }
2499  break;
2500 
2501  case T_PartitionBoundSpec:
2502  {
2503  PartitionBoundSpec *pbs = (PartitionBoundSpec *) node;
2504 
2505  if (WALK(pbs->listdatums))
2506  return true;
2507  if (WALK(pbs->lowerdatums))
2508  return true;
2509  if (WALK(pbs->upperdatums))
2510  return true;
2511  }
2512  break;
2513  case T_PartitionRangeDatum:
2514  {
2515  PartitionRangeDatum *prd = (PartitionRangeDatum *) node;
2516 
2517  if (WALK(prd->value))
2518  return true;
2519  }
2520  break;
2521  case T_List:
2522  foreach(temp, (List *) node)
2523  {
2524  if (WALK(lfirst(temp)))
2525  return true;
2526  }
2527  break;
2528  case T_FromExpr:
2529  {
2530  FromExpr *from = (FromExpr *) node;
2531 
2532  if (LIST_WALK(from->fromlist))
2533  return true;
2534  if (WALK(from->quals))
2535  return true;
2536  }
2537  break;
2538  case T_OnConflictExpr:
2539  {
2540  OnConflictExpr *onconflict = (OnConflictExpr *) node;
2541 
2542  if (WALK(onconflict->arbiterElems))
2543  return true;
2544  if (WALK(onconflict->arbiterWhere))
2545  return true;
2546  if (WALK(onconflict->onConflictSet))
2547  return true;
2548  if (WALK(onconflict->onConflictWhere))
2549  return true;
2550  if (WALK(onconflict->exclRelTlist))
2551  return true;
2552  }
2553  break;
2554  case T_MergeAction:
2555  {
2556  MergeAction *action = (MergeAction *) node;
2557 
2558  if (WALK(action->qual))
2559  return true;
2560  if (WALK(action->targetList))
2561  return true;
2562  }
2563  break;
2564  case T_PartitionPruneStepOp:
2565  {
2566  PartitionPruneStepOp *opstep = (PartitionPruneStepOp *) node;
2567 
2568  if (WALK(opstep->exprs))
2569  return true;
2570  }
2571  break;
2572  case T_PartitionPruneStepCombine:
2573  /* no expression subnodes */
2574  break;
2575  case T_JoinExpr:
2576  {
2577  JoinExpr *join = (JoinExpr *) node;
2578 
2579  if (WALK(join->larg))
2580  return true;
2581  if (WALK(join->rarg))
2582  return true;
2583  if (WALK(join->quals))
2584  return true;
2585 
2586  /*
2587  * alias clause, using list are deemed uninteresting.
2588  */
2589  }
2590  break;
2591  case T_SetOperationStmt:
2592  {
2593  SetOperationStmt *setop = (SetOperationStmt *) node;
2594 
2595  if (WALK(setop->larg))
2596  return true;
2597  if (WALK(setop->rarg))
2598  return true;
2599 
2600  /* groupClauses are deemed uninteresting */
2601  }
2602  break;
2603  case T_IndexClause:
2604  {
2605  IndexClause *iclause = (IndexClause *) node;
2606 
2607  if (WALK(iclause->rinfo))
2608  return true;
2609  if (LIST_WALK(iclause->indexquals))
2610  return true;
2611  }
2612  break;
2613  case T_PlaceHolderVar:
2614  return WALK(((PlaceHolderVar *) node)->phexpr);
2615  case T_InferenceElem:
2616  return WALK(((InferenceElem *) node)->expr);
2617  case T_AppendRelInfo:
2618  {
2619  AppendRelInfo *appinfo = (AppendRelInfo *) node;
2620 
2621  if (LIST_WALK(appinfo->translated_vars))
2622  return true;
2623  }
2624  break;
2625  case T_PlaceHolderInfo:
2626  return WALK(((PlaceHolderInfo *) node)->ph_var);
2627  case T_RangeTblFunction:
2628  return WALK(((RangeTblFunction *) node)->funcexpr);
2629  case T_TableSampleClause:
2630  {
2631  TableSampleClause *tsc = (TableSampleClause *) node;
2632 
2633  if (LIST_WALK(tsc->args))
2634  return true;
2635  if (WALK(tsc->repeatable))
2636  return true;
2637  }
2638  break;
2639  case T_TableFunc:
2640  {
2641  TableFunc *tf = (TableFunc *) node;
2642 
2643  if (WALK(tf->ns_uris))
2644  return true;
2645  if (WALK(tf->docexpr))
2646  return true;
2647  if (WALK(tf->rowexpr))
2648  return true;
2649  if (WALK(tf->colexprs))
2650  return true;
2651  if (WALK(tf->coldefexprs))
2652  return true;
2653  if (WALK(tf->colvalexprs))
2654  return true;
2655  if (WALK(tf->passingvalexprs))
2656  return true;
2657  }
2658  break;
2659  default:
2660  elog(ERROR, "unrecognized node type: %d",
2661  (int) nodeTag(node));
2662  break;
2663  }
2664  return false;
2665 
2666  /* The WALK() macro can be re-used below, but LIST_WALK() not so much */
2667 #undef LIST_WALK
2668 }
#define LIST_WALK(l)
#define WALK(n)
#define lfirst_node(type, lc)
Definition: pg_list.h:176
struct WindowDef * over
Definition: parsenodes.h:1973
JsonValueExpr * arg
Definition: parsenodes.h:1998
JsonAggConstructor * constructor
Definition: parsenodes.h:1997
JsonValueExpr * value
Definition: parsenodes.h:1881
JsonAggConstructor * constructor
Definition: parsenodes.h:1984
JsonKeyValue * arg
Definition: parsenodes.h:1985
Definition: type.h:88

References generate_unaccent_rules::action, JsonAggConstructor::agg_filter, JsonAggConstructor::agg_order, Aggref::aggdirectargs, Aggref::aggdistinct, Aggref::aggfilter, WindowFunc::aggfilter, Aggref::aggorder, OnConflictExpr::arbiterElems, OnConflictExpr::arbiterWhere, arg, JsonObjectAgg::arg, JsonArrayAgg::arg, FieldStore::arg, ArrayCoerceExpr::arg, CaseExpr::arg, generate_unaccent_rules::args, TableSampleClause::args, Aggref::args, WindowFunc::args, FuncExpr::args, OpExpr::args, ScalarArrayOpExpr::args, BoolExpr::args, SubPlan::args, CaseExpr::args, XmlExpr::args, JsonConstructorExpr::args, check_stack_depth(), JsonConstructorExpr::coercion, JsonExpr::coercion_expr, TableFunc::colexprs, JsonObjectAgg::constructor, JsonArrayAgg::constructor, CommonTableExpr::ctequery, CTECycleClause::cycle_mark_default, CTECycleClause::cycle_mark_value, CaseExpr::defresult, TableFunc::docexpr, ArrayCoerceExpr::elemexpr, elog, WindowClause::endOffset, ERROR, OnConflictExpr::exclRelTlist, JsonBehavior::expr, JsonObjectConstructor::exprs, JsonArrayConstructor::exprs, PartitionPruneStepOp::exprs, JsonValueExpr::formatted_expr, JsonExpr::formatted_expr, FromExpr::fromlist, JsonConstructorExpr::func, IndexClause::indexquals, JsonKeyValue::key, SetOperationStmt::larg, JoinExpr::larg, RowCompareExpr::largs, lfirst, lfirst_node, LIST_WALK, PartitionBoundSpec::listdatums, PartitionBoundSpec::lowerdatums, XmlExpr::named_args, FieldStore::newvals, nodeTag, JsonExpr::on_empty, JsonExpr::on_error, OnConflictExpr::onConflictSet, OnConflictExpr::onConflictWhere, WindowClause::orderClause, JsonAggConstructor::over, WindowClause::partitionClause, JsonExpr::passing_values, JsonExpr::path_spec, JoinExpr::quals, FromExpr::quals, JsonArrayQueryConstructor::query, SetOperationStmt::rarg, JoinExpr::rarg, RowCompareExpr::rargs, JsonValueExpr::raw_expr, SubscriptingRef::refassgnexpr, SubscriptingRef::refexpr, SubscriptingRef::reflowerindexpr, SubscriptingRef::refupperindexpr, TableSampleClause::repeatable, IndexClause::rinfo, TableFunc::rowexpr, WindowClause::startOffset, SubLink::subselect, SubLink::testexpr, SubPlan::testexpr, AppendRelInfo::translated_vars, PartitionBoundSpec::upperdatums, PartitionRangeDatum::value, JsonKeyValue::value, and WALK.

◆ exprInputCollation()

Oid exprInputCollation ( const Node expr)

Definition at line 1071 of file nodeFuncs.c.

1072 {
1073  Oid coll;
1074 
1075  if (!expr)
1076  return InvalidOid;
1077 
1078  switch (nodeTag(expr))
1079  {
1080  case T_Aggref:
1081  coll = ((const Aggref *) expr)->inputcollid;
1082  break;
1083  case T_WindowFunc:
1084  coll = ((const WindowFunc *) expr)->inputcollid;
1085  break;
1086  case T_FuncExpr:
1087  coll = ((const FuncExpr *) expr)->inputcollid;
1088  break;
1089  case T_OpExpr:
1090  coll = ((const OpExpr *) expr)->inputcollid;
1091  break;
1092  case T_DistinctExpr:
1093  coll = ((const DistinctExpr *) expr)->inputcollid;
1094  break;
1095  case T_NullIfExpr:
1096  coll = ((const NullIfExpr *) expr)->inputcollid;
1097  break;
1098  case T_ScalarArrayOpExpr:
1099  coll = ((const ScalarArrayOpExpr *) expr)->inputcollid;
1100  break;
1101  case T_MinMaxExpr:
1102  coll = ((const MinMaxExpr *) expr)->inputcollid;
1103  break;
1104  default:
1105  coll = InvalidOid;
1106  break;
1107  }
1108  return coll;
1109 }

References InvalidOid, and nodeTag.

Referenced by check_simple_rowfilter_expr_walker(), and resolve_polymorphic_tupdesc().

◆ exprIsLengthCoercion()

bool exprIsLengthCoercion ( const Node expr,
int32 coercedTypmod 
)

Definition at line 552 of file nodeFuncs.c.

553 {
554  if (coercedTypmod != NULL)
555  *coercedTypmod = -1; /* default result on failure */
556 
557  /*
558  * Scalar-type length coercions are FuncExprs, array-type length coercions
559  * are ArrayCoerceExprs
560  */
561  if (expr && IsA(expr, FuncExpr))
562  {
563  const FuncExpr *func = (const FuncExpr *) expr;
564  int nargs;
565  Const *second_arg;
566 
567  /*
568  * If it didn't come from a coercion context, reject.
569  */
570  if (func->funcformat != COERCE_EXPLICIT_CAST &&
571  func->funcformat != COERCE_IMPLICIT_CAST)
572  return false;
573 
574  /*
575  * If it's not a two-argument or three-argument function with the
576  * second argument being an int4 constant, it can't have been created
577  * from a length coercion (it must be a type coercion, instead).
578  */
579  nargs = list_length(func->args);
580  if (nargs < 2 || nargs > 3)
581  return false;
582 
583  second_arg = (Const *) lsecond(func->args);
584  if (!IsA(second_arg, Const) ||
585  second_arg->consttype != INT4OID ||
586  second_arg->constisnull)
587  return false;
588 
589  /*
590  * OK, it is indeed a length-coercion function.
591  */
592  if (coercedTypmod != NULL)
593  *coercedTypmod = DatumGetInt32(second_arg->constvalue);
594 
595  return true;
596  }
597 
598  if (expr && IsA(expr, ArrayCoerceExpr))
599  {
600  const ArrayCoerceExpr *acoerce = (const ArrayCoerceExpr *) expr;
601 
602  /* It's not a length coercion unless there's a nondefault typmod */
603  if (acoerce->resulttypmod < 0)
604  return false;
605 
606  /*
607  * OK, it is indeed a length-coercion expression.
608  */
609  if (coercedTypmod != NULL)
610  *coercedTypmod = acoerce->resulttypmod;
611 
612  return true;
613  }
614 
615  return false;
616 }
static int list_length(const List *l)
Definition: pg_list.h:152
#define lsecond(l)
Definition: pg_list.h:183
static int32 DatumGetInt32(Datum X)
Definition: postgres.h:202
@ COERCE_IMPLICIT_CAST
Definition: primnodes.h:706
@ COERCE_EXPLICIT_CAST
Definition: primnodes.h:705

References FuncExpr::args, COERCE_EXPLICIT_CAST, COERCE_IMPLICIT_CAST, Const::consttype, DatumGetInt32(), IsA, list_length(), and lsecond.

Referenced by deparseFuncExpr(), exprTypmod(), and get_func_expr().

◆ exprLocation()

int exprLocation ( const Node expr)

Definition at line 1386 of file nodeFuncs.c.

1387 {
1388  int loc;
1389 
1390  if (expr == NULL)
1391  return -1;
1392  switch (nodeTag(expr))
1393  {
1394  case T_RangeVar:
1395  loc = ((const RangeVar *) expr)->location;
1396  break;
1397  case T_TableFunc:
1398  loc = ((const TableFunc *) expr)->location;
1399  break;
1400  case T_Var:
1401  loc = ((const Var *) expr)->location;
1402  break;
1403  case T_Const:
1404  loc = ((const Const *) expr)->location;
1405  break;
1406  case T_Param:
1407  loc = ((const Param *) expr)->location;
1408  break;
1409  case T_Aggref:
1410  /* function name should always be the first thing */
1411  loc = ((const Aggref *) expr)->location;
1412  break;
1413  case T_GroupingFunc:
1414  loc = ((const GroupingFunc *) expr)->location;
1415  break;
1416  case T_WindowFunc:
1417  /* function name should always be the first thing */
1418  loc = ((const WindowFunc *) expr)->location;
1419  break;
1420  case T_MergeSupportFunc:
1421  loc = ((const MergeSupportFunc *) expr)->location;
1422  break;
1423  case T_SubscriptingRef:
1424  /* just use container argument's location */
1425  loc = exprLocation((Node *) ((const SubscriptingRef *) expr)->refexpr);
1426  break;
1427  case T_FuncExpr:
1428  {
1429  const FuncExpr *fexpr = (const FuncExpr *) expr;
1430 
1431  /* consider both function name and leftmost arg */
1432  loc = leftmostLoc(fexpr->location,
1433  exprLocation((Node *) fexpr->args));
1434  }
1435  break;
1436  case T_NamedArgExpr:
1437  {
1438  const NamedArgExpr *na = (const NamedArgExpr *) expr;
1439 
1440  /* consider both argument name and value */
1441  loc = leftmostLoc(na->location,
1442  exprLocation((Node *) na->arg));
1443  }
1444  break;
1445  case T_OpExpr:
1446  case T_DistinctExpr: /* struct-equivalent to OpExpr */
1447  case T_NullIfExpr: /* struct-equivalent to OpExpr */
1448  {
1449  const OpExpr *opexpr = (const OpExpr *) expr;
1450 
1451  /* consider both operator name and leftmost arg */
1452  loc = leftmostLoc(opexpr->location,
1453  exprLocation((Node *) opexpr->args));
1454  }
1455  break;
1456  case T_ScalarArrayOpExpr:
1457  {
1458  const ScalarArrayOpExpr *saopexpr = (const ScalarArrayOpExpr *) expr;
1459 
1460  /* consider both operator name and leftmost arg */
1461  loc = leftmostLoc(saopexpr->location,
1462  exprLocation((Node *) saopexpr->args));
1463  }
1464  break;
1465  case T_BoolExpr:
1466  {
1467  const BoolExpr *bexpr = (const BoolExpr *) expr;
1468 
1469  /*
1470  * Same as above, to handle either NOT or AND/OR. We can't
1471  * special-case NOT because of the way that it's used for
1472  * things like IS NOT BETWEEN.
1473  */
1474  loc = leftmostLoc(bexpr->location,
1475  exprLocation((Node *) bexpr->args));
1476  }
1477  break;
1478  case T_SubLink:
1479  {
1480  const SubLink *sublink = (const SubLink *) expr;
1481 
1482  /* check the testexpr, if any, and the operator/keyword */
1483  loc = leftmostLoc(exprLocation(sublink->testexpr),
1484  sublink->location);
1485  }
1486  break;
1487  case T_FieldSelect:
1488  /* just use argument's location */
1489  loc = exprLocation((Node *) ((const FieldSelect *) expr)->arg);
1490  break;
1491  case T_FieldStore:
1492  /* just use argument's location */
1493  loc = exprLocation((Node *) ((const FieldStore *) expr)->arg);
1494  break;
1495  case T_RelabelType:
1496  {
1497  const RelabelType *rexpr = (const RelabelType *) expr;
1498 
1499  /* Much as above */
1500  loc = leftmostLoc(rexpr->location,
1501  exprLocation((Node *) rexpr->arg));
1502  }
1503  break;
1504  case T_CoerceViaIO:
1505  {
1506  const CoerceViaIO *cexpr = (const CoerceViaIO *) expr;
1507 
1508  /* Much as above */
1509  loc = leftmostLoc(cexpr->location,
1510  exprLocation((Node *) cexpr->arg));
1511  }
1512  break;
1513  case T_ArrayCoerceExpr:
1514  {
1515  const ArrayCoerceExpr *cexpr = (const ArrayCoerceExpr *) expr;
1516 
1517  /* Much as above */
1518  loc = leftmostLoc(cexpr->location,
1519  exprLocation((Node *) cexpr->arg));
1520  }
1521  break;
1522  case T_ConvertRowtypeExpr:
1523  {
1524  const ConvertRowtypeExpr *cexpr = (const ConvertRowtypeExpr *) expr;
1525 
1526  /* Much as above */
1527  loc = leftmostLoc(cexpr->location,
1528  exprLocation((Node *) cexpr->arg));
1529  }
1530  break;
1531  case T_CollateExpr:
1532  /* just use argument's location */
1533  loc = exprLocation((Node *) ((const CollateExpr *) expr)->arg);
1534  break;
1535  case T_CaseExpr:
1536  /* CASE keyword should always be the first thing */
1537  loc = ((const CaseExpr *) expr)->location;
1538  break;
1539  case T_CaseWhen:
1540  /* WHEN keyword should always be the first thing */
1541  loc = ((const CaseWhen *) expr)->location;
1542  break;
1543  case T_ArrayExpr:
1544  /* the location points at ARRAY or [, which must be leftmost */
1545  loc = ((const ArrayExpr *) expr)->location;
1546  break;
1547  case T_RowExpr:
1548  /* the location points at ROW or (, which must be leftmost */
1549  loc = ((const RowExpr *) expr)->location;
1550  break;
1551  case T_RowCompareExpr:
1552  /* just use leftmost argument's location */
1553  loc = exprLocation((Node *) ((const RowCompareExpr *) expr)->largs);
1554  break;
1555  case T_CoalesceExpr:
1556  /* COALESCE keyword should always be the first thing */
1557  loc = ((const CoalesceExpr *) expr)->location;
1558  break;
1559  case T_MinMaxExpr:
1560  /* GREATEST/LEAST keyword should always be the first thing */
1561  loc = ((const MinMaxExpr *) expr)->location;
1562  break;
1563  case T_SQLValueFunction:
1564  /* function keyword should always be the first thing */
1565  loc = ((const SQLValueFunction *) expr)->location;
1566  break;
1567  case T_XmlExpr:
1568  {
1569  const XmlExpr *xexpr = (const XmlExpr *) expr;
1570 
1571  /* consider both function name and leftmost arg */
1572  loc = leftmostLoc(xexpr->location,
1573  exprLocation((Node *) xexpr->args));
1574  }
1575  break;
1576  case T_JsonFormat:
1577  loc = ((const JsonFormat *) expr)->location;
1578  break;
1579  case T_JsonValueExpr:
1580  loc = exprLocation((Node *) ((const JsonValueExpr *) expr)->raw_expr);
1581  break;
1582  case T_JsonConstructorExpr:
1583  loc = ((const JsonConstructorExpr *) expr)->location;
1584  break;
1585  case T_JsonIsPredicate:
1586  loc = ((const JsonIsPredicate *) expr)->location;
1587  break;
1588  case T_JsonExpr:
1589  {
1590  const JsonExpr *jsexpr = (const JsonExpr *) expr;
1591 
1592  /* consider both function name and leftmost arg */
1593  loc = leftmostLoc(jsexpr->location,
1594  exprLocation(jsexpr->formatted_expr));
1595  }
1596  break;
1597  case T_JsonBehavior:
1598  loc = exprLocation(((JsonBehavior *) expr)->expr);
1599  break;
1600  case T_NullTest:
1601  {
1602  const NullTest *nexpr = (const NullTest *) expr;
1603 
1604  /* Much as above */
1605  loc = leftmostLoc(nexpr->location,
1606  exprLocation((Node *) nexpr->arg));
1607  }
1608  break;
1609  case T_BooleanTest:
1610  {
1611  const BooleanTest *bexpr = (const BooleanTest *) expr;
1612 
1613  /* Much as above */
1614  loc = leftmostLoc(bexpr->location,
1615  exprLocation((Node *) bexpr->arg));
1616  }
1617  break;
1618  case T_CoerceToDomain:
1619  {
1620  const CoerceToDomain *cexpr = (const CoerceToDomain *) expr;
1621 
1622  /* Much as above */
1623  loc = leftmostLoc(cexpr->location,
1624  exprLocation((Node *) cexpr->arg));
1625  }
1626  break;
1627  case T_CoerceToDomainValue:
1628  loc = ((const CoerceToDomainValue *) expr)->location;
1629  break;
1630  case T_SetToDefault:
1631  loc = ((const SetToDefault *) expr)->location;
1632  break;
1633  case T_TargetEntry:
1634  /* just use argument's location */
1635  loc = exprLocation((Node *) ((const TargetEntry *) expr)->expr);
1636  break;
1637  case T_IntoClause:
1638  /* use the contained RangeVar's location --- close enough */
1639  loc = exprLocation((Node *) ((const IntoClause *) expr)->rel);
1640  break;
1641  case T_List:
1642  {
1643  /* report location of first list member that has a location */
1644  ListCell *lc;
1645 
1646  loc = -1; /* just to suppress compiler warning */
1647  foreach(lc, (const List *) expr)
1648  {
1649  loc = exprLocation((Node *) lfirst(lc));
1650  if (loc >= 0)
1651  break;
1652  }
1653  }
1654  break;
1655  case T_A_Expr:
1656  {
1657  const A_Expr *aexpr = (const A_Expr *) expr;
1658 
1659  /* use leftmost of operator or left operand (if any) */
1660  /* we assume right operand can't be to left of operator */
1661  loc = leftmostLoc(aexpr->location,
1662  exprLocation(aexpr->lexpr));
1663  }
1664  break;
1665  case T_ColumnRef:
1666  loc = ((const ColumnRef *) expr)->location;
1667  break;
1668  case T_ParamRef:
1669  loc = ((const ParamRef *) expr)->location;
1670  break;
1671  case T_A_Const:
1672  loc = ((const A_Const *) expr)->location;
1673  break;
1674  case T_FuncCall:
1675  {
1676  const FuncCall *fc = (const FuncCall *) expr;
1677 
1678  /* consider both function name and leftmost arg */
1679  /* (we assume any ORDER BY nodes must be to right of name) */
1680  loc = leftmostLoc(fc->location,
1681  exprLocation((Node *) fc->args));
1682  }
1683  break;
1684  case T_A_ArrayExpr:
1685  /* the location points at ARRAY or [, which must be leftmost */
1686  loc = ((const A_ArrayExpr *) expr)->location;
1687  break;
1688  case T_ResTarget:
1689  /* we need not examine the contained expression (if any) */
1690  loc = ((const ResTarget *) expr)->location;
1691  break;
1692  case T_MultiAssignRef:
1693  loc = exprLocation(((const MultiAssignRef *) expr)->source);
1694  break;
1695  case T_TypeCast:
1696  {
1697  const TypeCast *tc = (const TypeCast *) expr;
1698 
1699  /*
1700  * This could represent CAST(), ::, or TypeName 'literal', so
1701  * any of the components might be leftmost.
1702  */
1703  loc = exprLocation(tc->arg);
1704  loc = leftmostLoc(loc, tc->typeName->location);
1705  loc = leftmostLoc(loc, tc->location);
1706  }
1707  break;
1708  case T_CollateClause:
1709  /* just use argument's location */
1710  loc = exprLocation(((const CollateClause *) expr)->arg);
1711  break;
1712  case T_SortBy:
1713  /* just use argument's location (ignore operator, if any) */
1714  loc = exprLocation(((const SortBy *) expr)->node);
1715  break;
1716  case T_WindowDef:
1717  loc = ((const WindowDef *) expr)->location;
1718  break;
1719  case T_RangeTableSample:
1720  loc = ((const RangeTableSample *) expr)->location;
1721  break;
1722  case T_TypeName:
1723  loc = ((const TypeName *) expr)->location;
1724  break;
1725  case T_ColumnDef:
1726  loc = ((const ColumnDef *) expr)->location;
1727  break;
1728  case T_Constraint:
1729  loc = ((const Constraint *) expr)->location;
1730  break;
1731  case T_FunctionParameter:
1732  /* just use typename's location */
1733  loc = exprLocation((Node *) ((const FunctionParameter *) expr)->argType);
1734  break;
1735  case T_XmlSerialize:
1736  /* XMLSERIALIZE keyword should always be the first thing */
1737  loc = ((const XmlSerialize *) expr)->location;
1738  break;
1739  case T_GroupingSet:
1740  loc = ((const GroupingSet *) expr)->location;
1741  break;
1742  case T_WithClause:
1743  loc = ((const WithClause *) expr)->location;
1744  break;
1745  case T_InferClause:
1746  loc = ((const InferClause *) expr)->location;
1747  break;
1748  case T_OnConflictClause:
1749  loc = ((const OnConflictClause *) expr)->location;
1750  break;
1751  case T_CTESearchClause:
1752  loc = ((const CTESearchClause *) expr)->location;
1753  break;
1754  case T_CTECycleClause:
1755  loc = ((const CTECycleClause *) expr)->location;
1756  break;
1757  case T_CommonTableExpr:
1758  loc = ((const CommonTableExpr *) expr)->location;
1759  break;
1760  case T_JsonKeyValue:
1761  /* just use the key's location */
1762  loc = exprLocation((Node *) ((const JsonKeyValue *) expr)->key);
1763  break;
1764  case T_JsonObjectConstructor:
1765  loc = ((const JsonObjectConstructor *) expr)->location;
1766  break;
1767  case T_JsonArrayConstructor:
1768  loc = ((const JsonArrayConstructor *) expr)->location;
1769  break;
1770  case T_JsonArrayQueryConstructor:
1771  loc = ((const JsonArrayQueryConstructor *) expr)->location;
1772  break;
1773  case T_JsonAggConstructor:
1774  loc = ((const JsonAggConstructor *) expr)->location;
1775  break;
1776  case T_JsonObjectAgg:
1777  loc = exprLocation((Node *) ((const JsonObjectAgg *) expr)->constructor);
1778  break;
1779  case T_JsonArrayAgg:
1780  loc = exprLocation((Node *) ((const JsonArrayAgg *) expr)->constructor);
1781  break;
1782  case T_PlaceHolderVar:
1783  /* just use argument's location */
1784  loc = exprLocation((Node *) ((const PlaceHolderVar *) expr)->phexpr);
1785  break;
1786  case T_InferenceElem:
1787  /* just use nested expr's location */
1788  loc = exprLocation((Node *) ((const InferenceElem *) expr)->expr);
1789  break;
1790  case T_PartitionElem:
1791  loc = ((const PartitionElem *) expr)->location;
1792  break;
1793  case T_PartitionSpec:
1794  loc = ((const PartitionSpec *) expr)->location;
1795  break;
1796  case T_PartitionBoundSpec:
1797  loc = ((const PartitionBoundSpec *) expr)->location;
1798  break;
1799  case T_PartitionRangeDatum:
1800  loc = ((const PartitionRangeDatum *) expr)->location;
1801  break;
1802  default:
1803  /* for any other node type it's just unknown... */
1804  loc = -1;
1805  break;
1806  }
1807  return loc;
1808 }
static int leftmostLoc(int loc1, int loc2)
Definition: nodeFuncs.c:1816
int exprLocation(const Node *expr)
Definition: nodeFuncs.c:1386
static rewind_source * source
Definition: pg_rewind.c:89
static int fc(const char *x)
Definition: preproc-init.c:99
ParseLoc location
Definition: parsenodes.h:338
Node * lexpr
Definition: parsenodes.h:336
ParseLoc location
Definition: primnodes.h:1212
ParseLoc location
Definition: primnodes.h:911
ParseLoc location
Definition: primnodes.h:1956
ParseLoc location
Definition: primnodes.h:2008
ParseLoc location
Definition: primnodes.h:1184
ParseLoc location
Definition: primnodes.h:740
ParseLoc location
Definition: primnodes.h:1831
ParseLoc location
Definition: primnodes.h:767
ParseLoc location
Definition: primnodes.h:1934
ParseLoc location
Definition: primnodes.h:809
ParseLoc location
Definition: primnodes.h:889
TypeName * typeName
Definition: parsenodes.h:374
ParseLoc location
Definition: parsenodes.h:375
Node * arg
Definition: parsenodes.h:373
ParseLoc location
Definition: parsenodes.h:275
ParseLoc location
Definition: primnodes.h:1587

References arg, TypeCast::arg, NamedArgExpr::arg, RelabelType::arg, CoerceViaIO::arg, ArrayCoerceExpr::arg, ConvertRowtypeExpr::arg, NullTest::arg, BooleanTest::arg, CoerceToDomain::arg, FuncExpr::args, OpExpr::args, ScalarArrayOpExpr::args, BoolExpr::args, XmlExpr::args, fc(), JsonExpr::formatted_expr, sort-test::key, leftmostLoc(), A_Expr::lexpr, lfirst, TypeName::location, A_Expr::location, TypeCast::location, FuncExpr::location, NamedArgExpr::location, OpExpr::location, ScalarArrayOpExpr::location, BoolExpr::location, SubLink::location, RelabelType::location, CoerceViaIO::location, ArrayCoerceExpr::location, ConvertRowtypeExpr::location, XmlExpr::location, JsonExpr::location, NullTest::location, BooleanTest::location, CoerceToDomain::location, nodeTag, source, SubLink::testexpr, and TypeCast::typeName.

Referenced by addRangeTableEntryForFunction(), addRangeTableEntryForTableFunc(), addTargetToSortList(), analyzeCTE(), array_subscript_transform(), assign_collations_walker(), check_agg_arguments_walker(), check_simple_rowfilter_expr_walker(), check_srf_call_placement(), checkWellFormedRecursion(), coerce_to_boolean(), coerce_to_common_type(), coerce_to_specific_type_typmod(), coerceJsonFuncExpr(), EvaluateParams(), ExecInitFunc(), ExecInitSubscriptingRef(), finalize_grouping_exprs_walker(), get_matching_location(), hstore_subscript_transform(), init_sexpr(), jsonb_subscript_transform(), parseCheckAggregates(), ParseFuncOrColumn(), parser_coercion_errposition(), resolve_unique_index_expr(), select_common_type(), transformAggregateCall(), transformArrayExpr(), transformAssignedExpr(), transformCaseExpr(), transformCoalesceExpr(), transformContainerSubscripts(), transformDistinctClause(), transformDistinctOnClause(), transformFrameOffset(), transformFromClauseItem(), transformGroupClause(), transformGroupClauseExpr(), transformGroupingSet(), transformIndirection(), transformInsertRow(), transformInsertStmt(), transformJsonBehavior(), transformJsonFuncExpr(), transformJsonParseArg(), transformJsonValueExpr(), transformMultiAssignRef(), transformOnConflictArbiter(), transformPartitionBound(), transformPartitionBoundValue(), transformPartitionRangeBounds(), transformPLAssignStmt(), transformRangeFunction(), transformReturningList(), transformSelectStmt(), transformSetOperationStmt(), transformSetOperationTree(), transformValuesClause(), and validateInfiniteBounds().

◆ exprSetCollation()

void exprSetCollation ( Node expr,
Oid  collation 
)

Definition at line 1119 of file nodeFuncs.c.

1120 {
1121  switch (nodeTag(expr))
1122  {
1123  case T_Var:
1124  ((Var *) expr)->varcollid = collation;
1125  break;
1126  case T_Const:
1127  ((Const *) expr)->constcollid = collation;
1128  break;
1129  case T_Param:
1130  ((Param *) expr)->paramcollid = collation;
1131  break;
1132  case T_Aggref:
1133  ((Aggref *) expr)->aggcollid = collation;
1134  break;
1135  case T_GroupingFunc:
1136  Assert(!OidIsValid(collation));
1137  break;
1138  case T_WindowFunc:
1139  ((WindowFunc *) expr)->wincollid = collation;
1140  break;
1141  case T_MergeSupportFunc:
1142  ((MergeSupportFunc *) expr)->msfcollid = collation;
1143  break;
1144  case T_SubscriptingRef:
1145  ((SubscriptingRef *) expr)->refcollid = collation;
1146  break;
1147  case T_FuncExpr:
1148  ((FuncExpr *) expr)->funccollid = collation;
1149  break;
1150  case T_NamedArgExpr:
1151  Assert(collation == exprCollation((Node *) ((NamedArgExpr *) expr)->arg));
1152  break;
1153  case T_OpExpr:
1154  ((OpExpr *) expr)->opcollid = collation;
1155  break;
1156  case T_DistinctExpr:
1157  ((DistinctExpr *) expr)->opcollid = collation;
1158  break;
1159  case T_NullIfExpr:
1160  ((NullIfExpr *) expr)->opcollid = collation;
1161  break;
1162  case T_ScalarArrayOpExpr:
1163  /* ScalarArrayOpExpr's result is boolean ... */
1164  Assert(!OidIsValid(collation)); /* ... so never set a collation */
1165  break;
1166  case T_BoolExpr:
1167  /* BoolExpr's result is boolean ... */
1168  Assert(!OidIsValid(collation)); /* ... so never set a collation */
1169  break;
1170  case T_SubLink:
1171 #ifdef USE_ASSERT_CHECKING
1172  {
1173  SubLink *sublink = (SubLink *) expr;
1174 
1175  if (sublink->subLinkType == EXPR_SUBLINK ||
1176  sublink->subLinkType == ARRAY_SUBLINK)
1177  {
1178  /* get the collation of subselect's first target column */
1179  Query *qtree = (Query *) sublink->subselect;
1180  TargetEntry *tent;
1181 
1182  if (!qtree || !IsA(qtree, Query))
1183  elog(ERROR, "cannot set collation for untransformed sublink");
1184  tent = linitial_node(TargetEntry, qtree->targetList);
1185  Assert(!tent->resjunk);
1186  Assert(collation == exprCollation((Node *) tent->expr));
1187  }
1188  else
1189  {
1190  /* otherwise, result is RECORD or BOOLEAN */
1191  Assert(!OidIsValid(collation));
1192  }
1193  }
1194 #endif /* USE_ASSERT_CHECKING */
1195  break;
1196  case T_FieldSelect:
1197  ((FieldSelect *) expr)->resultcollid = collation;
1198  break;
1199  case T_FieldStore:
1200  /* FieldStore's result is composite ... */
1201  Assert(!OidIsValid(collation)); /* ... so never set a collation */
1202  break;
1203  case T_RelabelType:
1204  ((RelabelType *) expr)->resultcollid = collation;
1205  break;
1206  case T_CoerceViaIO:
1207  ((CoerceViaIO *) expr)->resultcollid = collation;
1208  break;
1209  case T_ArrayCoerceExpr:
1210  ((ArrayCoerceExpr *) expr)->resultcollid = collation;
1211  break;
1212  case T_ConvertRowtypeExpr:
1213  /* ConvertRowtypeExpr's result is composite ... */
1214  Assert(!OidIsValid(collation)); /* ... so never set a collation */
1215  break;
1216  case T_CaseExpr:
1217  ((CaseExpr *) expr)->casecollid = collation;
1218  break;
1219  case T_ArrayExpr:
1220  ((ArrayExpr *) expr)->array_collid = collation;
1221  break;
1222  case T_RowExpr:
1223  /* RowExpr's result is composite ... */
1224  Assert(!OidIsValid(collation)); /* ... so never set a collation */
1225  break;
1226  case T_RowCompareExpr:
1227  /* RowCompareExpr's result is boolean ... */
1228  Assert(!OidIsValid(collation)); /* ... so never set a collation */
1229  break;
1230  case T_CoalesceExpr:
1231  ((CoalesceExpr *) expr)->coalescecollid = collation;
1232  break;
1233  case T_MinMaxExpr:
1234  ((MinMaxExpr *) expr)->minmaxcollid = collation;
1235  break;
1236  case T_SQLValueFunction:
1237  Assert((((SQLValueFunction *) expr)->type == NAMEOID) ?
1238  (collation == C_COLLATION_OID) :
1239  (collation == InvalidOid));
1240  break;
1241  case T_XmlExpr:
1242  Assert((((XmlExpr *) expr)->op == IS_XMLSERIALIZE) ?
1243  (collation == DEFAULT_COLLATION_OID) :
1244  (collation == InvalidOid));
1245  break;
1246  case T_JsonValueExpr:
1247  exprSetCollation((Node *) ((JsonValueExpr *) expr)->formatted_expr,
1248  collation);
1249  break;
1250  case T_JsonConstructorExpr:
1251  {
1252  JsonConstructorExpr *ctor = (JsonConstructorExpr *) expr;
1253 
1254  if (ctor->coercion)
1255  exprSetCollation((Node *) ctor->coercion, collation);
1256  else
1257  Assert(!OidIsValid(collation)); /* result is always a
1258  * json[b] type */
1259  }
1260  break;
1261  case T_JsonIsPredicate:
1262  Assert(!OidIsValid(collation)); /* result is always boolean */
1263  break;
1264  case T_JsonExpr:
1265  {
1266  JsonExpr *jexpr = (JsonExpr *) expr;
1267 
1268  if (jexpr->coercion_expr)
1269  exprSetCollation((Node *) jexpr->coercion_expr, collation);
1270  else
1271  jexpr->collation = collation;
1272  }
1273  break;
1274  case T_JsonBehavior:
1275  {
1276  JsonBehavior *behavior = (JsonBehavior *) expr;
1277 
1278  if (behavior->expr)
1279  exprSetCollation(behavior->expr, collation);
1280  }
1281  break;
1282  case T_NullTest:
1283  /* NullTest's result is boolean ... */
1284  Assert(!OidIsValid(collation)); /* ... so never set a collation */
1285  break;
1286  case T_BooleanTest:
1287  /* BooleanTest's result is boolean ... */
1288  Assert(!OidIsValid(collation)); /* ... so never set a collation */
1289  break;
1290  case T_CoerceToDomain:
1291  ((CoerceToDomain *) expr)->resultcollid = collation;
1292  break;
1293  case T_CoerceToDomainValue:
1294  ((CoerceToDomainValue *) expr)->collation = collation;
1295  break;
1296  case T_SetToDefault:
1297  ((SetToDefault *) expr)->collation = collation;
1298  break;
1299  case T_CurrentOfExpr:
1300  /* CurrentOfExpr's result is boolean ... */
1301  Assert(!OidIsValid(collation)); /* ... so never set a collation */
1302  break;
1303  case T_NextValueExpr:
1304  /* NextValueExpr's result is an integer type ... */
1305  Assert(!OidIsValid(collation)); /* ... so never set a collation */
1306  break;
1307  default:
1308  elog(ERROR, "unrecognized node type: %d", (int) nodeTag(expr));
1309  break;
1310  }
1311 }
#define OidIsValid(objectId)
Definition: c.h:775
void exprSetCollation(Node *expr, Oid collation)
Definition: nodeFuncs.c:1119

References arg, ARRAY_SUBLINK, Assert, JsonConstructorExpr::coercion, JsonExpr::coercion_expr, JsonExpr::collation, elog, ERROR, JsonBehavior::expr, EXPR_SUBLINK, exprCollation(), if(), InvalidOid, IS_XMLSERIALIZE, IsA, linitial_node, nodeTag, OidIsValid, SubLink::subLinkType, SubLink::subselect, Query::targetList, and type.

Referenced by assign_collations_walker().

◆ exprSetInputCollation()

void exprSetInputCollation ( Node expr,
Oid  inputcollation 
)

Definition at line 1322 of file nodeFuncs.c.

1323 {
1324  switch (nodeTag(expr))
1325  {
1326  case T_Aggref:
1327  ((Aggref *) expr)->inputcollid = inputcollation;
1328  break;
1329  case T_WindowFunc:
1330  ((WindowFunc *) expr)->inputcollid = inputcollation;
1331  break;
1332  case T_FuncExpr:
1333  ((FuncExpr *) expr)->inputcollid = inputcollation;
1334  break;
1335  case T_OpExpr:
1336  ((OpExpr *) expr)->inputcollid = inputcollation;
1337  break;
1338  case T_DistinctExpr:
1339  ((DistinctExpr *) expr)->inputcollid = inputcollation;
1340  break;
1341  case T_NullIfExpr:
1342  ((NullIfExpr *) expr)->inputcollid = inputcollation;
1343  break;
1344  case T_ScalarArrayOpExpr:
1345  ((ScalarArrayOpExpr *) expr)->inputcollid = inputcollation;
1346  break;
1347  case T_MinMaxExpr:
1348  ((MinMaxExpr *) expr)->inputcollid = inputcollation;
1349  break;
1350  default:
1351  break;
1352  }
1353 }

References nodeTag.

Referenced by assign_collations_walker().

◆ exprType()

Oid exprType ( const Node expr)

Definition at line 42 of file nodeFuncs.c.

43 {
44  Oid type;
45 
46  if (!expr)
47  return InvalidOid;
48 
49  switch (nodeTag(expr))
50  {
51  case T_Var:
52  type = ((const Var *) expr)->vartype;
53  break;
54  case T_Const:
55  type = ((const Const *) expr)->consttype;
56  break;
57  case T_Param:
58  type = ((const Param *) expr)->paramtype;
59  break;
60  case T_Aggref:
61  type = ((const Aggref *) expr)->aggtype;
62  break;
63  case T_GroupingFunc:
64  type = INT4OID;
65  break;
66  case T_WindowFunc:
67  type = ((const WindowFunc *) expr)->wintype;
68  break;
69  case T_MergeSupportFunc:
70  type = ((const MergeSupportFunc *) expr)->msftype;
71  break;
72  case T_SubscriptingRef:
73  type = ((const SubscriptingRef *) expr)->refrestype;
74  break;
75  case T_FuncExpr:
76  type = ((const FuncExpr *) expr)->funcresulttype;
77  break;
78  case T_NamedArgExpr:
79  type = exprType((Node *) ((const NamedArgExpr *) expr)->arg);
80  break;
81  case T_OpExpr:
82  type = ((const OpExpr *) expr)->opresulttype;
83  break;
84  case T_DistinctExpr:
85  type = ((const DistinctExpr *) expr)->opresulttype;
86  break;
87  case T_NullIfExpr:
88  type = ((const NullIfExpr *) expr)->opresulttype;
89  break;
90  case T_ScalarArrayOpExpr:
91  type = BOOLOID;
92  break;
93  case T_BoolExpr:
94  type = BOOLOID;
95  break;
96  case T_SubLink:
97  {
98  const SubLink *sublink = (const SubLink *) expr;
99 
100  if (sublink->subLinkType == EXPR_SUBLINK ||
101  sublink->subLinkType == ARRAY_SUBLINK)
102  {
103  /* get the type of the subselect's first target column */
104  Query *qtree = (Query *) sublink->subselect;
105  TargetEntry *tent;
106 
107  if (!qtree || !IsA(qtree, Query))
108  elog(ERROR, "cannot get type for untransformed sublink");
109  tent = linitial_node(TargetEntry, qtree->targetList);
110  Assert(!tent->resjunk);
111  type = exprType((Node *) tent->expr);
112  if (sublink->subLinkType == ARRAY_SUBLINK)
113  {
115  if (!OidIsValid(type))
116  ereport(ERROR,
117  (errcode(ERRCODE_UNDEFINED_OBJECT),
118  errmsg("could not find array type for data type %s",
119  format_type_be(exprType((Node *) tent->expr)))));
120  }
121  }
122  else if (sublink->subLinkType == MULTIEXPR_SUBLINK)
123  {
124  /* MULTIEXPR is always considered to return RECORD */
125  type = RECORDOID;
126  }
127  else
128  {
129  /* for all other sublink types, result is boolean */
130  type = BOOLOID;
131  }
132  }
133  break;
134  case T_SubPlan:
135  {
136  const SubPlan *subplan = (const SubPlan *) expr;
137 
138  if (subplan->subLinkType == EXPR_SUBLINK ||
139  subplan->subLinkType == ARRAY_SUBLINK)
140  {
141  /* get the type of the subselect's first target column */
142  type = subplan->firstColType;
143  if (subplan->subLinkType == ARRAY_SUBLINK)
144  {
146  if (!OidIsValid(type))
147  ereport(ERROR,
148  (errcode(ERRCODE_UNDEFINED_OBJECT),
149  errmsg("could not find array type for data type %s",
150  format_type_be(subplan->firstColType))));
151  }
152  }
153  else if (subplan->subLinkType == MULTIEXPR_SUBLINK)
154  {
155  /* MULTIEXPR is always considered to return RECORD */
156  type = RECORDOID;
157  }
158  else
159  {
160  /* for all other subplan types, result is boolean */
161  type = BOOLOID;
162  }
163  }
164  break;
165  case T_AlternativeSubPlan:
166  {
167  const AlternativeSubPlan *asplan = (const AlternativeSubPlan *) expr;
168 
169  /* subplans should all return the same thing */
170  type = exprType((Node *) linitial(asplan->subplans));
171  }
172  break;
173  case T_FieldSelect:
174  type = ((const FieldSelect *) expr)->resulttype;
175  break;
176  case T_FieldStore:
177  type = ((const FieldStore *) expr)->resulttype;
178  break;
179  case T_RelabelType:
180  type = ((const RelabelType *) expr)->resulttype;
181  break;
182  case T_CoerceViaIO:
183  type = ((const CoerceViaIO *) expr)->resulttype;
184  break;
185  case T_ArrayCoerceExpr:
186  type = ((const ArrayCoerceExpr *) expr)->resulttype;
187  break;
188  case T_ConvertRowtypeExpr:
189  type = ((const ConvertRowtypeExpr *) expr)->resulttype;
190  break;
191  case T_CollateExpr:
192  type = exprType((Node *) ((const CollateExpr *) expr)->arg);
193  break;
194  case T_CaseExpr:
195  type = ((const CaseExpr *) expr)->casetype;
196  break;
197  case T_CaseTestExpr:
198  type = ((const CaseTestExpr *) expr)->typeId;
199  break;
200  case T_ArrayExpr:
201  type = ((const ArrayExpr *) expr)->array_typeid;
202  break;
203  case T_RowExpr:
204  type = ((const RowExpr *) expr)->row_typeid;
205  break;
206  case T_RowCompareExpr:
207  type = BOOLOID;
208  break;
209  case T_CoalesceExpr:
210  type = ((const CoalesceExpr *) expr)->coalescetype;
211  break;
212  case T_MinMaxExpr:
213  type = ((const MinMaxExpr *) expr)->minmaxtype;
214  break;
215  case T_SQLValueFunction:
216  type = ((const SQLValueFunction *) expr)->type;
217  break;
218  case T_XmlExpr:
219  if (((const XmlExpr *) expr)->op == IS_DOCUMENT)
220  type = BOOLOID;
221  else if (((const XmlExpr *) expr)->op == IS_XMLSERIALIZE)
222  type = TEXTOID;
223  else
224  type = XMLOID;
225  break;
226  case T_JsonValueExpr:
227  {
228  const JsonValueExpr *jve = (const JsonValueExpr *) expr;
229 
230  type = exprType((Node *) jve->formatted_expr);
231  }
232  break;
233  case T_JsonConstructorExpr:
234  type = ((const JsonConstructorExpr *) expr)->returning->typid;
235  break;
236  case T_JsonIsPredicate:
237  type = BOOLOID;
238  break;
239  case T_JsonExpr:
240  {
241  const JsonExpr *jexpr = (const JsonExpr *) expr;
242 
243  type = jexpr->returning->typid;
244  break;
245  }
246  case T_JsonBehavior:
247  {
248  const JsonBehavior *behavior = (const JsonBehavior *) expr;
249 
250  type = exprType(behavior->expr);
251  break;
252  }
253  case T_NullTest:
254  type = BOOLOID;
255  break;
256  case T_BooleanTest:
257  type = BOOLOID;
258  break;
259  case T_CoerceToDomain:
260  type = ((const CoerceToDomain *) expr)->resulttype;
261  break;
262  case T_CoerceToDomainValue:
263  type = ((const CoerceToDomainValue *) expr)->typeId;
264  break;
265  case T_SetToDefault:
266  type = ((const SetToDefault *) expr)->typeId;
267  break;
268  case T_CurrentOfExpr:
269  type = BOOLOID;
270  break;
271  case T_NextValueExpr:
272  type = ((const NextValueExpr *) expr)->typeId;
273  break;
274  case T_InferenceElem:
275  {
276  const InferenceElem *n = (const InferenceElem *) expr;
277 
278  type = exprType((Node *) n->expr);
279  }
280  break;
281  case T_PlaceHolderVar:
282  type = exprType((Node *) ((const PlaceHolderVar *) expr)->phexpr);
283  break;
284  default:
285  elog(ERROR, "unrecognized node type: %d", (int) nodeTag(expr));
286  type = InvalidOid; /* keep compiler quiet */
287  break;
288  }
289  return type;
290 }
int errcode(int sqlerrcode)
Definition: elog.c:859
int errmsg(const char *fmt,...)
Definition: elog.c:1072
#define ereport(elevel,...)
Definition: elog.h:149
char * format_type_be(Oid type_oid)
Definition: format_type.c:343
Oid get_promoted_array_type(Oid typid)
Definition: lsyscache.c:2811
@ MULTIEXPR_SUBLINK
Definition: primnodes.h:972
@ IS_DOCUMENT
Definition: primnodes.h:1557
JsonReturning * returning
Definition: primnodes.h:1798
Oid firstColType
Definition: primnodes.h:1044

References arg, ARRAY_SUBLINK, Assert, elog, ereport, errcode(), errmsg(), ERROR, JsonBehavior::expr, InferenceElem::expr, EXPR_SUBLINK, SubPlan::firstColType, format_type_be(), JsonValueExpr::formatted_expr, get_promoted_array_type(), if(), InvalidOid, IS_DOCUMENT, IS_XMLSERIALIZE, IsA, linitial, linitial_node, MULTIEXPR_SUBLINK, nodeTag, OidIsValid, JsonExpr::returning, SubLink::subLinkType, SubPlan::subLinkType, AlternativeSubPlan::subplans, SubLink::subselect, Query::targetList, type, and JsonReturning::typid.

Referenced by add_row_identity_var(), add_setop_child_rel_equivalences(), addRangeTableEntryForFunction(), addRangeTableEntryForSubquery(), addTargetToGroupList(), addTargetToSortList(), agg_args_support_sendreceive(), analyzeCTE(), analyzeCTETargetList(), appendAggOrderBy(), appendOrderByClause(), applyRelabelType(), array_subscript_transform(), assign_collations_walker(), assign_hypothetical_collations(), assign_param_for_placeholdervar(), ATExecAlterColumnType(), ATPrepAlterColumnType(), build_coercion_expression(), build_column_default(), build_subplan(), can_minmax_aggs(), canonicalize_ec_expression(), check_functions_in_node(), check_hashjoinable(), check_memoizable(), check_mergejoinable(), check_simple_rowfilter_expr_walker(), check_sql_fn_retval(), checkRuleResultList(), coerce_fn_result_column(), coerce_record_to_complex(), coerce_to_boolean(), coerce_to_common_type(), coerce_to_specific_type_typmod(), coerceJsonExprOutput(), coerceJsonFuncExpr(), compare_tlist_datatypes(), compute_semijoin_info(), ComputeIndexAttrs(), ComputePartitionAttrs(), ConstructTupleDescriptor(), contain_mutable_functions_walker(), convert_EXISTS_to_ANY(), cookDefault(), cost_qual_eval_walker(), create_ctas_nodata(), create_indexscan_plan(), CreateStatistics(), DefineVirtualRelation(), deparseNullTest(), deparseOpExpr(), estimate_num_groups(), eval_const_expressions_mutator(), EvaluateParams(), examine_attribute(), examine_expression(), examine_variable(), exec_save_simple_expr(), ExecBuildProjectionInfo(), ExecBuildUpdateProjection(), ExecCheckPlanOutput(), ExecEvalJsonIsPredicate(), ExecEvalXmlExpr(), ExecInitExprRec(), ExecInitIndexScan(), ExecInitJsonExpr(), ExecMakeTableFunctionResult(), ExecTypeFromExprList(), ExecTypeFromTLInternal(), ExecWindowAgg(), expandRecordVariable(), expandRTE(), exprTypmod(), find_expr_references_walker(), find_placeholder_info(), fix_indexqual_operand(), foreign_expr_walker(), generate_append_tlist(), generate_join_implied_equalities_normal(), generate_setop_tlist(), generate_subquery_params(), generateClonedIndexStmt(), get_call_expr_argtype(), get_expr_result_tupdesc(), get_expr_result_type(), get_expr_width(), get_first_col_type(), get_fn_expr_rettype(), get_func_expr(), get_oper_expr(), get_rule_expr(), get_rule_expr_funccall(), get_rule_orderby(), get_simple_binary_op_name(), get_sublink_expr(), get_windowfunc_expr_helper(), GetIndexInputType(), hash_ok_operator(), hstore_subscript_transform(), initialize_peragg(), inline_function(), internal_get_result_type(), jsonb_exec_setup(), jsonb_subscript_transform(), JsonTableInitOpaque(), make_op(), make_scalar_array_op(), makeJsonConstructorExpr(), makeVarFromTargetEntry(), makeWholeRowVar(), match_pattern_prefix(), ordered_set_startup(), paraminfo_get_equal_hashops(), ParseFuncOrColumn(), pg_get_indexdef_worker(), pg_get_partkeydef_worker(), prepare_query_params(), preprocess_aggref(), preprocess_minmax_aggregates(), ProcedureCreate(), process_equivalence(), process_matched_tle(), recheck_cast_function_args(), relabel_to_typmod(), RelationBuildPartitionKey(), RelationGetDummyIndexExpressions(), remove_unused_subquery_outputs(), replace_nestloop_param_placeholdervar(), replace_outer_grouping(), replace_outer_merge_support(), replace_outer_placeholdervar(), resolveTargetListUnknowns(), scalararraysel(), select_common_type(), select_common_typmod(), set_append_rel_size(), set_dummy_tlist_references(), set_joinrel_partition_key_exprs(), set_rel_width(), show_sortorder_options(), tlist_same_datatypes(), transformAExprNullIf(), transformAggregateCall(), transformArrayExpr(), transformAssignedExpr(), transformAssignmentIndirection(), transformAssignmentSubscripts(), transformCaseExpr(), transformCollateClause(), transformExprRecurse(), transformFrameOffset(), transformFromClauseItem(), transformIndirection(), transformInsertStmt(), transformJsonBehavior(), transformJsonConstructorOutput(), transformJsonFuncExpr(), transformJsonParseArg(), transformJsonScalarExpr(), transformJsonTableColumns(), transformJsonValueExpr(), transformMultiAssignRef(), transformPartitionBoundValue(), transformPLAssignStmt(), transformSetOperationTree(), transformSubLink(), transformTypeCast(), unknown_attribute(), verify_common_type(), and xmlelement().

◆ exprTypmod()

int32 exprTypmod ( const Node expr)

Definition at line 298 of file nodeFuncs.c.

299 {
300  if (!expr)
301  return -1;
302 
303  switch (nodeTag(expr))
304  {
305  case T_Var:
306  return ((const Var *) expr)->vartypmod;
307  case T_Const:
308  return ((const Const *) expr)->consttypmod;
309  case T_Param:
310  return ((const Param *) expr)->paramtypmod;
311  case T_SubscriptingRef:
312  return ((const SubscriptingRef *) expr)->reftypmod;
313  case T_FuncExpr:
314  {
315  int32 coercedTypmod;
316 
317  /* Be smart about length-coercion functions... */
318  if (exprIsLengthCoercion(expr, &coercedTypmod))
319  return coercedTypmod;
320  }
321  break;
322  case T_NamedArgExpr:
323  return exprTypmod((Node *) ((const NamedArgExpr *) expr)->arg);
324  case T_NullIfExpr:
325  {
326  /*
327  * Result is either first argument or NULL, so we can report
328  * first argument's typmod if known.
329  */
330  const NullIfExpr *nexpr = (const NullIfExpr *) expr;
331 
332  return exprTypmod((Node *) linitial(nexpr->args));
333  }
334  break;
335  case T_SubLink:
336  {
337  const SubLink *sublink = (const SubLink *) expr;
338 
339  if (sublink->subLinkType == EXPR_SUBLINK ||
340  sublink->subLinkType == ARRAY_SUBLINK)
341  {
342  /* get the typmod of the subselect's first target column */
343  Query *qtree = (Query *) sublink->subselect;
344  TargetEntry *tent;
345 
346  if (!qtree || !IsA(qtree, Query))
347  elog(ERROR, "cannot get type for untransformed sublink");
348  tent = linitial_node(TargetEntry, qtree->targetList);
349  Assert(!tent->resjunk);
350  return exprTypmod((Node *) tent->expr);
351  /* note we don't need to care if it's an array */
352  }
353  /* otherwise, result is RECORD or BOOLEAN, typmod is -1 */
354  }
355  break;
356  case T_SubPlan:
357  {
358  const SubPlan *subplan = (const SubPlan *) expr;
359 
360  if (subplan->subLinkType == EXPR_SUBLINK ||
361  subplan->subLinkType == ARRAY_SUBLINK)
362  {
363  /* get the typmod of the subselect's first target column */
364  /* note we don't need to care if it's an array */
365  return subplan->firstColTypmod;
366  }
367  /* otherwise, result is RECORD or BOOLEAN, typmod is -1 */
368  }
369  break;
370  case T_AlternativeSubPlan:
371  {
372  const AlternativeSubPlan *asplan = (const AlternativeSubPlan *) expr;
373 
374  /* subplans should all return the same thing */
375  return exprTypmod((Node *) linitial(asplan->subplans));
376  }
377  break;
378  case T_FieldSelect:
379  return ((const FieldSelect *) expr)->resulttypmod;
380  case T_RelabelType:
381  return ((const RelabelType *) expr)->resulttypmod;
382  case T_ArrayCoerceExpr:
383  return ((const ArrayCoerceExpr *) expr)->resulttypmod;
384  case T_CollateExpr:
385  return exprTypmod((Node *) ((const CollateExpr *) expr)->arg);
386  case T_CaseExpr:
387  {
388  /*
389  * If all the alternatives agree on type/typmod, return that
390  * typmod, else use -1
391  */
392  const CaseExpr *cexpr = (const CaseExpr *) expr;
393  Oid casetype = cexpr->casetype;
394  int32 typmod;
395  ListCell *arg;
396 
397  if (!cexpr->defresult)
398  return -1;
399  if (exprType((Node *) cexpr->defresult) != casetype)
400  return -1;
401  typmod = exprTypmod((Node *) cexpr->defresult);
402  if (typmod < 0)
403  return -1; /* no point in trying harder */
404  foreach(arg, cexpr->args)
405  {
407 
408  if (exprType((Node *) w->result) != casetype)
409  return -1;
410  if (exprTypmod((Node *) w->result) != typmod)
411  return -1;
412  }
413  return typmod;
414  }
415  break;
416  case T_CaseTestExpr:
417  return ((const CaseTestExpr *) expr)->typeMod;
418  case T_ArrayExpr:
419  {
420  /*
421  * If all the elements agree on type/typmod, return that
422  * typmod, else use -1
423  */
424  const ArrayExpr *arrayexpr = (const ArrayExpr *) expr;
425  Oid commontype;
426  int32 typmod;
427  ListCell *elem;
428 
429  if (arrayexpr->elements == NIL)
430  return -1;
431  typmod = exprTypmod((Node *) linitial(arrayexpr->elements));
432  if (typmod < 0)
433  return -1; /* no point in trying harder */
434  if (arrayexpr->multidims)
435  commontype = arrayexpr->array_typeid;
436  else
437  commontype = arrayexpr->element_typeid;
438  foreach(elem, arrayexpr->elements)
439  {
440  Node *e = (Node *) lfirst(elem);
441 
442  if (exprType(e) != commontype)
443  return -1;
444  if (exprTypmod(e) != typmod)
445  return -1;
446  }
447  return typmod;
448  }
449  break;
450  case T_CoalesceExpr:
451  {
452  /*
453  * If all the alternatives agree on type/typmod, return that
454  * typmod, else use -1
455  */
456  const CoalesceExpr *cexpr = (const CoalesceExpr *) expr;
457  Oid coalescetype = cexpr->coalescetype;
458  int32 typmod;
459  ListCell *arg;
460 
461  if (exprType((Node *) linitial(cexpr->args)) != coalescetype)
462  return -1;
463  typmod = exprTypmod((Node *) linitial(cexpr->args));
464  if (typmod < 0)
465  return -1; /* no point in trying harder */
466  for_each_from(arg, cexpr->args, 1)
467  {
468  Node *e = (Node *) lfirst(arg);
469 
470  if (exprType(e) != coalescetype)
471  return -1;
472  if (exprTypmod(e) != typmod)
473  return -1;
474  }
475  return typmod;
476  }
477  break;
478  case T_MinMaxExpr:
479  {
480  /*
481  * If all the alternatives agree on type/typmod, return that
482  * typmod, else use -1
483  */
484  const MinMaxExpr *mexpr = (const MinMaxExpr *) expr;
485  Oid minmaxtype = mexpr->minmaxtype;
486  int32 typmod;
487  ListCell *arg;
488 
489  if (exprType((Node *) linitial(mexpr->args)) != minmaxtype)
490  return -1;
491  typmod = exprTypmod((Node *) linitial(mexpr->args));
492  if (typmod < 0)
493  return -1; /* no point in trying harder */
494  for_each_from(arg, mexpr->args, 1)
495  {
496  Node *e = (Node *) lfirst(arg);
497 
498  if (exprType(e) != minmaxtype)
499  return -1;
500  if (exprTypmod(e) != typmod)
501  return -1;
502  }
503  return typmod;
504  }
505  break;
506  case T_SQLValueFunction:
507  return ((const SQLValueFunction *) expr)->typmod;
508  case T_JsonValueExpr:
509  return exprTypmod((Node *) ((const JsonValueExpr *) expr)->formatted_expr);
510  case T_JsonConstructorExpr:
511  return ((const JsonConstructorExpr *) expr)->returning->typmod;
512  case T_JsonExpr:
513  {
514  const JsonExpr *jexpr = (const JsonExpr *) expr;
515 
516  return jexpr->returning->typmod;
517  }
518  break;
519  case T_JsonBehavior:
520  {
521  const JsonBehavior *behavior = (const JsonBehavior *) expr;
522 
523  return exprTypmod(behavior->expr);
524  }
525  break;
526  case T_CoerceToDomain:
527  return ((const CoerceToDomain *) expr)->resulttypmod;
528  case T_CoerceToDomainValue:
529  return ((const CoerceToDomainValue *) expr)->typeMod;
530  case T_SetToDefault:
531  return ((const SetToDefault *) expr)->typeMod;
532  case T_PlaceHolderVar:
533  return exprTypmod((Node *) ((const PlaceHolderVar *) expr)->phexpr);
534  default:
535  break;
536  }
537  return -1;
538 }
signed int int32
Definition: c.h:494
bool exprIsLengthCoercion(const Node *expr, int32 *coercedTypmod)
Definition: nodeFuncs.c:552
#define for_each_from(cell, lst, N)
Definition: pg_list.h:414
e
Definition: preproc-init.c:82
int32 firstColTypmod
Definition: primnodes.h:1045

References arg, OpExpr::args, CaseExpr::args, CoalesceExpr::args, MinMaxExpr::args, ARRAY_SUBLINK, Assert, CaseExpr::defresult, ArrayExpr::elements, elog, ERROR, JsonBehavior::expr, EXPR_SUBLINK, exprIsLengthCoercion(), exprType(), SubPlan::firstColTypmod, for_each_from, if(), IsA, lfirst, lfirst_node, linitial, linitial_node, NIL, nodeTag, CaseWhen::result, JsonExpr::returning, SubLink::subLinkType, SubPlan::subLinkType, AlternativeSubPlan::subplans, SubLink::subselect, Query::targetList, and JsonReturning::typmod.

Referenced by add_row_identity_var(), addRangeTableEntryForFunction(), addRangeTableEntryForSubquery(), analyzeCTE(), analyzeCTETargetList(), applyRelabelType(), assign_hypothetical_collations(), build_coercion_expression(), build_subplan(), canonicalize_ec_expression(), checkRuleResultList(), coerce_type_typmod(), coerceJsonExprOutput(), ConstructTupleDescriptor(), convert_EXISTS_to_ANY(), create_ctas_nodata(), DefineVirtualRelation(), eval_const_expressions_mutator(), examine_attribute(), examine_expression(), examine_variable(), exec_save_simple_expr(), ExecInitJsonExpr(), ExecTypeFromExprList(), ExecTypeFromTLInternal(), expandRecordVariable(), expandRTE(), find_placeholder_info(), generate_append_tlist(), generate_setop_tlist(), generate_subquery_params(), get_expr_result_type(), get_expr_width(), get_first_col_type(), get_rule_expr(), get_rule_expr_funccall(), interval_support(), JsonTableInitOpaque(), makeJsonConstructorExpr(), makeVarFromTargetEntry(), numeric_support(), preprocess_aggref(), RelationBuildPartitionKey(), RelationGetDummyIndexExpressions(), remove_unused_subquery_outputs(), replace_nestloop_param_placeholdervar(), replace_outer_placeholdervar(), select_common_typmod(), set_append_rel_size(), set_dummy_tlist_references(), set_rel_width(), TemporalSimplify(), transformCaseExpr(), transformFromClauseItem(), transformIndirection(), transformJsonTableColumns(), transformMultiAssignRef(), transformPLAssignStmt(), transformSubLink(), varbit_support(), and varchar_support().

◆ fix_opfuncids()

void fix_opfuncids ( Node node)

Definition at line 1837 of file nodeFuncs.c.

1838 {
1839  /* This tree walk requires no special setup, so away we go... */
1840  fix_opfuncids_walker(node, NULL);
1841 }
static bool fix_opfuncids_walker(Node *node, void *context)
Definition: nodeFuncs.c:1844

References fix_opfuncids_walker().

Referenced by evaluate_expr(), expression_planner(), expression_planner_with_deps(), fetch_statentries_for_relation(), get_qual_for_range(), get_relation_statistics(), operator_predicate_proof(), RelationBuildPartitionKey(), RelationGetIndexExpressions(), and RelationGetIndexPredicate().

◆ get_leftop()

◆ get_notclausearg()

◆ get_rightop()

◆ is_andclause()

◆ is_funcclause()

static bool is_funcclause ( const void *  clause)
inlinestatic

◆ is_notclause()

◆ is_opclause()

◆ is_orclause()

◆ planstate_tree_walker_impl()

bool planstate_tree_walker_impl ( struct PlanState planstate,
planstate_tree_walker_callback  walker,
void *  context 
)

Definition at line 4671 of file nodeFuncs.c.

4674 {
4675  Plan *plan = planstate->plan;
4676  ListCell *lc;
4677 
4678  /* We don't need implicit coercions to Node here */
4679 #define PSWALK(n) walker(n, context)
4680 
4681  /* Guard against stack overflow due to overly complex plan trees */
4683 
4684  /* initPlan-s */
4685  if (planstate_walk_subplans(planstate->initPlan, walker, context))
4686  return true;
4687 
4688  /* lefttree */
4689  if (outerPlanState(planstate))
4690  {
4691  if (PSWALK(outerPlanState(planstate)))
4692  return true;
4693  }
4694 
4695  /* righttree */
4696  if (innerPlanState(planstate))
4697  {
4698  if (PSWALK(innerPlanState(planstate)))
4699  return true;
4700  }
4701 
4702  /* special child plans */
4703  switch (nodeTag(plan))
4704  {
4705  case T_Append:
4706  if (planstate_walk_members(((AppendState *) planstate)->appendplans,
4707  ((AppendState *) planstate)->as_nplans,
4708  walker, context))
4709  return true;
4710  break;
4711  case T_MergeAppend:
4712  if (planstate_walk_members(((MergeAppendState *) planstate)->mergeplans,
4713  ((MergeAppendState *) planstate)->ms_nplans,
4714  walker, context))
4715  return true;
4716  break;
4717  case T_BitmapAnd:
4718  if (planstate_walk_members(((BitmapAndState *) planstate)->bitmapplans,
4719  ((BitmapAndState *) planstate)->nplans,
4720  walker, context))
4721  return true;
4722  break;
4723  case T_BitmapOr:
4724  if (planstate_walk_members(((BitmapOrState *) planstate)->bitmapplans,
4725  ((BitmapOrState *) planstate)->nplans,
4726  walker, context))
4727  return true;
4728  break;
4729  case T_SubqueryScan:
4730  if (PSWALK(((SubqueryScanState *) planstate)->subplan))
4731  return true;
4732  break;
4733  case T_CustomScan:
4734  foreach(lc, ((CustomScanState *) planstate)->custom_ps)
4735  {
4736  if (PSWALK(lfirst(lc)))
4737  return true;
4738  }
4739  break;
4740  default:
4741  break;
4742  }
4743 
4744  /* subPlan-s */
4745  if (planstate_walk_subplans(planstate->subPlan, walker, context))
4746  return true;
4747 
4748  return false;
4749 }
#define outerPlanState(node)
Definition: execnodes.h:1214
#define innerPlanState(node)
Definition: execnodes.h:1213
static bool planstate_walk_subplans(List *plans, planstate_tree_walker_callback walker, void *context)
Definition: nodeFuncs.c:4755
#define PSWALK(n)
static bool planstate_walk_members(PlanState **planstates, int nplans, planstate_tree_walker_callback walker, void *context)
Definition: nodeFuncs.c:4777
#define plan(x)
Definition: pg_regress.c:162
Plan * plan
Definition: execnodes.h:1118
List * initPlan
Definition: execnodes.h:1143

References check_stack_depth(), context, PlanState::initPlan, innerPlanState, lfirst, nodeTag, outerPlanState, PlanState::plan, plan, planstate_walk_members(), planstate_walk_subplans(), PSWALK, and PlanState::subPlan.

◆ query_or_expression_tree_mutator_impl()

Node* query_or_expression_tree_mutator_impl ( Node node,
tree_mutator_callback  mutator,
void *  context,
int  flags 
)

Definition at line 3928 of file nodeFuncs.c.

3932 {
3933  if (node && IsA(node, Query))
3934  return (Node *) query_tree_mutator((Query *) node,
3935  mutator,
3936  context,
3937  flags);
3938  else
3939  return mutator(node, context);
3940 }
#define query_tree_mutator(q, m, c, f)
Definition: nodeFuncs.h:158

References context, IsA, and query_tree_mutator.

◆ query_or_expression_tree_walker_impl()

bool query_or_expression_tree_walker_impl ( Node node,
tree_walker_callback  walker,
void *  context,
int  flags 
)

Definition at line 3905 of file nodeFuncs.c.

3909 {
3910  if (node && IsA(node, Query))
3911  return query_tree_walker((Query *) node,
3912  walker,
3913  context,
3914  flags);
3915  else
3916  return WALK(node);
3917 }
#define query_tree_walker(q, w, c, f)
Definition: nodeFuncs.h:156

References context, IsA, query_tree_walker, and WALK.

◆ query_tree_mutator_impl()

Query* query_tree_mutator_impl ( Query query,
tree_mutator_callback  mutator,
void *  context,
int  flags 
)

Definition at line 3744 of file nodeFuncs.c.

3748 {
3749  Assert(query != NULL && IsA(query, Query));
3750 
3751  if (!(flags & QTW_DONT_COPY_QUERY))
3752  {
3753  Query *newquery;
3754 
3755  FLATCOPY(newquery, query, Query);
3756  query = newquery;
3757  }
3758 
3759  MUTATE(query->targetList, query->targetList, List *);
3760  MUTATE(query->withCheckOptions, query->withCheckOptions, List *);
3761  MUTATE(query->onConflict, query->onConflict, OnConflictExpr *);
3762  MUTATE(query->mergeActionList, query->mergeActionList, List *);
3763  MUTATE(query->mergeJoinCondition, query->mergeJoinCondition, Node *);
3764  MUTATE(query->returningList, query->returningList, List *);
3765  MUTATE(query->jointree, query->jointree, FromExpr *);
3766  MUTATE(query->setOperations, query->setOperations, Node *);
3767  MUTATE(query->havingQual, query->havingQual, Node *);
3768  MUTATE(query->limitOffset, query->limitOffset, Node *);
3769  MUTATE(query->limitCount, query->limitCount, Node *);
3770 
3771  /*
3772  * Most callers aren't interested in SortGroupClause nodes since those
3773  * don't contain actual expressions. However they do contain OIDs, which
3774  * may be of interest to some mutators.
3775  */
3776 
3777  if ((flags & QTW_EXAMINE_SORTGROUP))
3778  {
3779  MUTATE(query->groupClause, query->groupClause, List *);
3780  MUTATE(query->windowClause, query->windowClause, List *);
3781  MUTATE(query->sortClause, query->sortClause, List *);
3782  MUTATE(query->distinctClause, query->distinctClause, List *);
3783  }
3784  else
3785  {
3786  /*
3787  * But we need to mutate the expressions under WindowClause nodes even
3788  * if we're not interested in SortGroupClause nodes.
3789  */
3790  List *resultlist;
3791  ListCell *temp;
3792 
3793  resultlist = NIL;
3794  foreach(temp, query->windowClause)
3795  {
3796  WindowClause *wc = lfirst_node(WindowClause, temp);
3797  WindowClause *newnode;
3798 
3799  FLATCOPY(newnode, wc, WindowClause);
3800  MUTATE(newnode->startOffset, wc->startOffset, Node *);
3801  MUTATE(newnode->endOffset, wc->endOffset, Node *);
3802  MUTATE(newnode->runCondition, wc->runCondition, List *);
3803 
3804  resultlist = lappend(resultlist, (Node *) newnode);
3805  }
3806  query->windowClause = resultlist;
3807  }
3808 
3809  /*
3810  * groupingSets and rowMarks are not mutated:
3811  *
3812  * groupingSets contain only ressortgroup refs (integers) which are
3813  * meaningless without the groupClause or tlist. Accordingly, any mutator
3814  * that needs to care about them needs to handle them itself in its Query
3815  * processing.
3816  *
3817  * rowMarks contains only rangetable indexes (and flags etc.) and
3818  * therefore should be handled at Query level similarly.
3819  */
3820 
3821  if (!(flags & QTW_IGNORE_CTE_SUBQUERIES))
3822  MUTATE(query->cteList, query->cteList, List *);
3823  else /* else copy CTE list as-is */
3824  query->cteList = copyObject(query->cteList);
3825  query->rtable = range_table_mutator(query->rtable,
3826  mutator, context, flags);
3827  return query;
3828 }
#define QTW_DONT_COPY_QUERY
Definition: nodeFuncs.h:29
#define QTW_IGNORE_CTE_SUBQUERIES
Definition: nodeFuncs.h:23
#define QTW_EXAMINE_SORTGROUP
Definition: nodeFuncs.h:30
#define range_table_mutator(rt, m, c, f)
Definition: nodeFuncs.h:163
Node * mergeJoinCondition
Definition: parsenodes.h:189
Node * limitCount
Definition: parsenodes.h:214
FromExpr * jointree
Definition: parsenodes.h:175
List * returningList
Definition: parsenodes.h:198
Node * setOperations
Definition: parsenodes.h:219
List * cteList
Definition: parsenodes.h:166
OnConflictExpr * onConflict
Definition: parsenodes.h:196
List * groupClause
Definition: parsenodes.h:200
Node * havingQual
Definition: parsenodes.h:205
List * rtable
Definition: parsenodes.h:168
Node * limitOffset
Definition: parsenodes.h:213
List * mergeActionList
Definition: parsenodes.h:178
List * windowClause
Definition: parsenodes.h:207
List * distinctClause
Definition: parsenodes.h:209
List * sortClause
Definition: parsenodes.h:211

References Assert, context, copyObject, Query::cteList, Query::distinctClause, WindowClause::endOffset, FLATCOPY, Query::groupClause, Query::havingQual, IsA, Query::jointree, lappend(), lfirst_node, Query::limitCount, Query::limitOffset, Query::mergeActionList, Query::mergeJoinCondition, MUTATE, NIL, Query::onConflict, QTW_DONT_COPY_QUERY, QTW_EXAMINE_SORTGROUP, QTW_IGNORE_CTE_SUBQUERIES, range_table_mutator, Query::returningList, Query::rtable, Query::setOperations, Query::sortClause, WindowClause::startOffset, Query::targetList, and Query::windowClause.

◆ query_tree_walker_impl()

bool query_tree_walker_impl ( Query query,
tree_walker_callback  walker,
void *  context,
int  flags 
)

Definition at line 2686 of file nodeFuncs.c.

2690 {
2691  Assert(query != NULL && IsA(query, Query));
2692 
2693  /*
2694  * We don't walk any utilityStmt here. However, we can't easily assert
2695  * that it is absent, since there are at least two code paths by which
2696  * action statements from CREATE RULE end up here, and NOTIFY is allowed
2697  * in a rule action.
2698  */
2699 
2700  if (WALK(query->targetList))
2701  return true;
2702  if (WALK(query->withCheckOptions))
2703  return true;
2704  if (WALK(query->onConflict))
2705  return true;
2706  if (WALK(query->mergeActionList))
2707  return true;
2708  if (WALK(query->mergeJoinCondition))
2709  return true;
2710  if (WALK(query->returningList))
2711  return true;
2712  if (WALK(query->jointree))
2713  return true;
2714  if (WALK(query->setOperations))
2715  return true;
2716  if (WALK(query->havingQual))
2717  return true;
2718  if (WALK(query->limitOffset))
2719  return true;
2720  if (WALK(query->limitCount))
2721  return true;
2722 
2723  /*
2724  * Most callers aren't interested in SortGroupClause nodes since those
2725  * don't contain actual expressions. However they do contain OIDs which
2726  * may be needed by dependency walkers etc.
2727  */
2728  if ((flags & QTW_EXAMINE_SORTGROUP))
2729  {
2730  if (WALK(query->groupClause))
2731  return true;
2732  if (WALK(query->windowClause))
2733  return true;
2734  if (WALK(query->sortClause))
2735  return true;
2736  if (WALK(query->distinctClause))
2737  return true;
2738  }
2739  else
2740  {
2741  /*
2742  * But we need to walk the expressions under WindowClause nodes even
2743  * if we're not interested in SortGroupClause nodes.
2744  */
2745  ListCell *lc;
2746 
2747  foreach(lc, query->windowClause)
2748  {
2750 
2751  if (WALK(wc->startOffset))
2752  return true;
2753  if (WALK(wc->endOffset))
2754  return true;
2755  if (WALK(wc->runCondition))
2756  return true;
2757  }
2758  }
2759 
2760  /*
2761  * groupingSets and rowMarks are not walked:
2762  *
2763  * groupingSets contain only ressortgrouprefs (integers) which are
2764  * meaningless without the corresponding groupClause or tlist.
2765  * Accordingly, any walker that needs to care about them needs to handle
2766  * them itself in its Query processing.
2767  *
2768  * rowMarks is not walked because it contains only rangetable indexes (and
2769  * flags etc.) and therefore should be handled at Query level similarly.
2770  */
2771 
2772  if (!(flags & QTW_IGNORE_CTE_SUBQUERIES))
2773  {
2774  if (WALK(query->cteList))
2775  return true;
2776  }
2777  if (!(flags & QTW_IGNORE_RANGE_TABLE))
2778  {
2779  if (range_table_walker(query->rtable, walker, context, flags))
2780  return true;
2781  }
2782  return false;
2783 }
#define range_table_walker(rt, w, c, f)
Definition: nodeFuncs.h:161
#define QTW_IGNORE_RANGE_TABLE
Definition: nodeFuncs.h:26

References Assert, context, Query::cteList, Query::distinctClause, WindowClause::endOffset, Query::groupClause, Query::havingQual, IsA, Query::jointree, lfirst_node, Query::limitCount, Query::limitOffset, Query::mergeActionList, Query::mergeJoinCondition, Query::onConflict, QTW_EXAMINE_SORTGROUP, QTW_IGNORE_CTE_SUBQUERIES, QTW_IGNORE_RANGE_TABLE, range_table_walker, Query::returningList, Query::rtable, Query::setOperations, Query::sortClause, WindowClause::startOffset, Query::targetList, WALK, and Query::windowClause.

◆ range_table_entry_walker_impl()

bool range_table_entry_walker_impl ( RangeTblEntry rte,
tree_walker_callback  walker,
void *  context,
int  flags 
)

Definition at line 2812 of file nodeFuncs.c.

2816 {
2817  /*
2818  * Walkers might need to examine the RTE node itself either before or
2819  * after visiting its contents (or, conceivably, both). Note that if you
2820  * specify neither flag, the walker won't be called on the RTE at all.
2821  */
2822  if (flags & QTW_EXAMINE_RTES_BEFORE)
2823  if (WALK(rte))
2824  return true;
2825 
2826  switch (rte->rtekind)
2827  {
2828  case RTE_RELATION:
2829  if (WALK(rte->tablesample))
2830  return true;
2831  break;
2832  case RTE_SUBQUERY:
2833  if (!(flags & QTW_IGNORE_RT_SUBQUERIES))
2834  if (WALK(rte->subquery))
2835  return true;
2836  break;
2837  case RTE_JOIN:
2838  if (!(flags & QTW_IGNORE_JOINALIASES))
2839  if (WALK(rte->joinaliasvars))
2840  return true;
2841  break;
2842  case RTE_FUNCTION:
2843  if (WALK(rte->functions))
2844  return true;
2845  break;
2846  case RTE_TABLEFUNC:
2847  if (WALK(rte->tablefunc))
2848  return true;
2849  break;
2850  case RTE_VALUES:
2851  if (WALK(rte->values_lists))
2852  return true;
2853  break;
2854  case RTE_CTE:
2855  case RTE_NAMEDTUPLESTORE:
2856  case RTE_RESULT:
2857  /* nothing to do */
2858  break;
2859  }
2860 
2861  if (WALK(rte->securityQuals))
2862  return true;
2863 
2864  if (flags & QTW_EXAMINE_RTES_AFTER)
2865  if (WALK(rte))
2866  return true;
2867 
2868  return false;
2869 }
#define QTW_IGNORE_RT_SUBQUERIES
Definition: nodeFuncs.h:22
#define QTW_EXAMINE_RTES_AFTER
Definition: nodeFuncs.h:28
#define QTW_EXAMINE_RTES_BEFORE
Definition: nodeFuncs.h:27
#define QTW_IGNORE_JOINALIASES
Definition: nodeFuncs.h:25
@ RTE_JOIN
Definition: parsenodes.h:1030
@ RTE_CTE
Definition: parsenodes.h:1034
@ RTE_NAMEDTUPLESTORE
Definition: parsenodes.h:1035
@ RTE_VALUES
Definition: parsenodes.h:1033
@ RTE_SUBQUERY
Definition: parsenodes.h:1029
@ RTE_RESULT
Definition: parsenodes.h:1036
@ RTE_FUNCTION
Definition: parsenodes.h:1031
@ RTE_TABLEFUNC
Definition: parsenodes.h:1032
@ RTE_RELATION
Definition: parsenodes.h:1028
TableFunc * tablefunc
Definition: parsenodes.h:1194
struct TableSampleClause * tablesample
Definition: parsenodes.h:1108
Query * subquery
Definition: parsenodes.h:1114
List * values_lists
Definition: parsenodes.h:1200
List * functions
Definition: parsenodes.h:1187
RTEKind rtekind
Definition: parsenodes.h:1057

References RangeTblEntry::functions, QTW_EXAMINE_RTES_AFTER, QTW_EXAMINE_RTES_BEFORE, QTW_IGNORE_JOINALIASES, QTW_IGNORE_RT_SUBQUERIES, RTE_CTE, RTE_FUNCTION, RTE_JOIN, RTE_NAMEDTUPLESTORE, RTE_RELATION, RTE_RESULT, RTE_SUBQUERY, RTE_TABLEFUNC, RTE_VALUES, RangeTblEntry::rtekind, RangeTblEntry::subquery, RangeTblEntry::tablefunc, RangeTblEntry::tablesample, RangeTblEntry::values_lists, and WALK.

◆ range_table_mutator_impl()

List* range_table_mutator_impl ( List rtable,
tree_mutator_callback  mutator,
void *  context,
int  flags 
)

Definition at line 3836 of file nodeFuncs.c.

3840 {
3841  List *newrt = NIL;
3842  ListCell *rt;
3843 
3844  foreach(rt, rtable)
3845  {
3846  RangeTblEntry *rte = (RangeTblEntry *) lfirst(rt);
3847  RangeTblEntry *newrte;
3848 
3849  FLATCOPY(newrte, rte, RangeTblEntry);
3850  switch (rte->rtekind)
3851  {
3852  case RTE_RELATION:
3853  MUTATE(newrte->tablesample, rte->tablesample,
3854  TableSampleClause *);
3855  /* we don't bother to copy eref, aliases, etc; OK? */
3856  break;
3857  case RTE_SUBQUERY:
3858  if (!(flags & QTW_IGNORE_RT_SUBQUERIES))
3859  MUTATE(newrte->subquery, rte->subquery, Query *);
3860  else
3861  {
3862  /* else, copy RT subqueries as-is */
3863  newrte->subquery = copyObject(rte->subquery);
3864  }
3865  break;
3866  case RTE_JOIN:
3867  if (!(flags & QTW_IGNORE_JOINALIASES))
3868  MUTATE(newrte->joinaliasvars, rte->joinaliasvars, List *);
3869  else
3870  {
3871  /* else, copy join aliases as-is */
3872  newrte->joinaliasvars = copyObject(rte->joinaliasvars);
3873  }
3874  break;
3875  case RTE_FUNCTION:
3876  MUTATE(newrte->functions, rte->functions, List *);
3877  break;
3878  case RTE_TABLEFUNC:
3879  MUTATE(newrte->tablefunc, rte->tablefunc, TableFunc *);
3880  break;
3881  case RTE_VALUES:
3882  MUTATE(newrte->values_lists, rte->values_lists, List *);
3883  break;
3884  case RTE_CTE:
3885  case RTE_NAMEDTUPLESTORE:
3886  case RTE_RESULT:
3887  /* nothing to do */
3888  break;
3889  }
3890  MUTATE(newrte->securityQuals, rte->securityQuals, List *);
3891  newrt = lappend(newrt, newrte);
3892  }
3893  return newrt;
3894 }

References copyObject, FLATCOPY, RangeTblEntry::functions, lappend(), lfirst, MUTATE, NIL, QTW_IGNORE_JOINALIASES, QTW_IGNORE_RT_SUBQUERIES, RTE_CTE, RTE_FUNCTION, RTE_JOIN, RTE_NAMEDTUPLESTORE, RTE_RELATION, RTE_RESULT, RTE_SUBQUERY, RTE_TABLEFUNC, RTE_VALUES, RangeTblEntry::rtekind, RangeTblEntry::subquery, RangeTblEntry::tablefunc, RangeTblEntry::tablesample, and RangeTblEntry::values_lists.

◆ range_table_walker_impl()

bool range_table_walker_impl ( List rtable,
tree_walker_callback  walker,
void *  context,
int  flags 
)

Definition at line 2791 of file nodeFuncs.c.

2795 {
2796  ListCell *rt;
2797 
2798  foreach(rt, rtable)
2799  {
2801 
2802  if (range_table_entry_walker(rte, walker, context, flags))
2803  return true;
2804  }
2805  return false;
2806 }
#define range_table_entry_walker(r, w, c, f)
Definition: nodeFuncs.h:166

References context, lfirst_node, and range_table_entry_walker.

◆ raw_expression_tree_walker_impl()

bool raw_expression_tree_walker_impl ( Node node,
tree_walker_callback  walker,
void *  context 
)

Definition at line 3959 of file nodeFuncs.c.

3962 {
3963  ListCell *temp;
3964 
3965  /*
3966  * The walker has already visited the current node, and so we need only
3967  * recurse into any sub-nodes it has.
3968  */
3969  if (node == NULL)
3970  return false;
3971 
3972  /* Guard against stack overflow due to overly complex expressions */
3974 
3975  switch (nodeTag(node))
3976  {
3977  case T_JsonFormat:
3978  case T_SetToDefault:
3979  case T_CurrentOfExpr:
3980  case T_SQLValueFunction:
3981  case T_Integer:
3982  case T_Float:
3983  case T_Boolean:
3984  case T_String:
3985  case T_BitString:
3986  case T_ParamRef:
3987  case T_A_Const:
3988  case T_A_Star:
3989  case T_MergeSupportFunc:
3990  /* primitive node types with no subnodes */
3991  break;
3992  case T_Alias:
3993  /* we assume the colnames list isn't interesting */
3994  break;
3995  case T_RangeVar:
3996  return WALK(((RangeVar *) node)->alias);
3997  case T_GroupingFunc:
3998  return WALK(((GroupingFunc *) node)->args);
3999  case T_SubLink:
4000  {
4001  SubLink *sublink = (SubLink *) node;
4002 
4003  if (WALK(sublink->testexpr))
4004  return true;
4005  /* we assume the operName is not interesting */
4006  if (WALK(sublink->subselect))
4007  return true;
4008  }
4009  break;
4010  case T_CaseExpr:
4011  {
4012  CaseExpr *caseexpr = (CaseExpr *) node;
4013 
4014  if (WALK(caseexpr->arg))
4015  return true;
4016  /* we assume walker doesn't care about CaseWhens, either */
4017  foreach(temp, caseexpr->args)
4018  {
4019  CaseWhen *when = lfirst_node(CaseWhen, temp);
4020 
4021  if (WALK(when->expr))
4022  return true;
4023  if (WALK(when->result))
4024  return true;
4025  }
4026  if (WALK(caseexpr->defresult))
4027  return true;
4028  }
4029  break;
4030  case T_RowExpr:
4031  /* Assume colnames isn't interesting */
4032  return WALK(((RowExpr *) node)->args);
4033  case T_CoalesceExpr:
4034  return WALK(((CoalesceExpr *) node)->args);
4035  case T_MinMaxExpr:
4036  return WALK(((MinMaxExpr *) node)->args);
4037  case T_XmlExpr:
4038  {
4039  XmlExpr *xexpr = (XmlExpr *) node;
4040 
4041  if (WALK(xexpr->named_args))
4042  return true;
4043  /* we assume walker doesn't care about arg_names */
4044  if (WALK(xexpr->args))
4045  return true;
4046  }
4047  break;
4048  case T_JsonReturning:
4049  return WALK(((JsonReturning *) node)->format);
4050  case T_JsonValueExpr:
4051  {
4052  JsonValueExpr *jve = (JsonValueExpr *) node;
4053 
4054  if (WALK(jve->raw_expr))
4055  return true;
4056  if (WALK(jve->formatted_expr))
4057  return true;
4058  if (WALK(jve->format))
4059  return true;
4060  }
4061  break;
4062  case T_JsonParseExpr:
4063  {
4064  JsonParseExpr *jpe = (JsonParseExpr *) node;
4065 
4066  if (WALK(jpe->expr))
4067  return true;
4068  if (WALK(jpe->output))
4069  return true;
4070  }
4071  break;
4072  case T_JsonScalarExpr:
4073  {
4074  JsonScalarExpr *jse = (JsonScalarExpr *) node;
4075 
4076  if (WALK(jse->expr))
4077  return true;
4078  if (WALK(jse->output))
4079  return true;
4080  }
4081  break;
4082  case T_JsonSerializeExpr:
4083  {
4084  JsonSerializeExpr *jse = (JsonSerializeExpr *) node;
4085 
4086  if (WALK(jse->expr))
4087  return true;
4088  if (WALK(jse->output))
4089  return true;
4090  }
4091  break;
4092  case T_JsonConstructorExpr:
4093  {
4094  JsonConstructorExpr *ctor = (JsonConstructorExpr *) node;
4095 
4096  if (WALK(ctor->args))
4097  return true;
4098  if (WALK(ctor->func))
4099  return true;
4100  if (WALK(ctor->coercion))
4101  return true;
4102  if (WALK(ctor->returning))
4103  return true;
4104  }
4105  break;
4106  case T_JsonIsPredicate:
4107  return WALK(((JsonIsPredicate *) node)->expr);
4108  case T_JsonArgument:
4109  return WALK(((JsonArgument *) node)->val);
4110  case T_JsonFuncExpr:
4111  {
4112  JsonFuncExpr *jfe = (JsonFuncExpr *) node;
4113 
4114  if (WALK(jfe->context_item))
4115  return true;
4116  if (WALK(jfe->pathspec))
4117  return true;
4118  if (WALK(jfe->passing))
4119  return true;
4120  if (WALK(jfe->output))
4121  return true;
4122  if (WALK(jfe->on_empty))
4123  return true;
4124  if (WALK(jfe->on_error))
4125  return true;
4126  }
4127  break;
4128  case T_JsonBehavior:
4129  {
4130  JsonBehavior *jb = (JsonBehavior *) node;
4131 
4132  if (WALK(jb->expr))
4133  return true;
4134  }
4135  break;
4136  case T_JsonTable:
4137  {
4138  JsonTable *jt = (JsonTable *) node;
4139 
4140  if (WALK(jt->context_item))
4141  return true;
4142  if (WALK(jt->pathspec))
4143  return true;
4144  if (WALK(jt->passing))
4145  return true;
4146  if (WALK(jt->columns))
4147  return true;
4148  if (WALK(jt->on_error))
4149  return true;
4150  }
4151  break;
4152  case T_JsonTableColumn:
4153  {
4154  JsonTableColumn *jtc = (JsonTableColumn *) node;
4155 
4156  if (WALK(jtc->typeName))
4157  return true;
4158  if (WALK(jtc->on_empty))
4159  return true;
4160  if (WALK(jtc->on_error))
4161  return true;
4162  if (WALK(jtc->columns))
4163  return true;
4164  }
4165  break;
4166  case T_JsonTablePathSpec:
4167  return WALK(((JsonTablePathSpec *) node)->string);
4168  case T_NullTest:
4169  return WALK(((NullTest *) node)->arg);
4170  case T_BooleanTest:
4171  return WALK(((BooleanTest *) node)->arg);
4172  case T_JoinExpr:
4173  {
4174  JoinExpr *join = (JoinExpr *) node;
4175 
4176  if (WALK(join->larg))
4177  return true;
4178  if (WALK(join->rarg))
4179  return true;
4180  if (WALK(join->quals))
4181  return true;
4182  if (WALK(join->alias))
4183  return true;
4184  /* using list is deemed uninteresting */
4185  }
4186  break;
4187  case T_IntoClause:
4188  {
4189  IntoClause *into = (IntoClause *) node;
4190 
4191  if (WALK(into->rel))
4192  return true;
4193  /* colNames, options are deemed uninteresting */
4194  /* viewQuery should be null in raw parsetree, but check it */
4195  if (WALK(into->viewQuery))
4196  return true;
4197  }
4198  break;
4199  case T_List:
4200  foreach(temp, (List *) node)
4201  {
4202  if (WALK((Node *) lfirst(temp)))
4203  return true;
4204  }
4205  break;
4206  case T_InsertStmt:
4207  {
4208  InsertStmt *stmt = (InsertStmt *) node;
4209 
4210  if (WALK(stmt->relation))
4211  return true;
4212  if (WALK(stmt->cols))
4213  return true;
4214  if (WALK(stmt->selectStmt))
4215  return true;
4216  if (WALK(stmt->onConflictClause))
4217  return true;
4218  if (WALK(stmt->returningList))
4219  return true;
4220  if (WALK(stmt->withClause))
4221  return true;
4222  }
4223  break;
4224  case T_DeleteStmt:
4225  {
4226  DeleteStmt *stmt = (DeleteStmt *) node;
4227 
4228  if (WALK(stmt->relation))
4229  return true;
4230  if (WALK(stmt->usingClause))
4231  return true;
4232  if (WALK(stmt->whereClause))
4233  return true;
4234  if (WALK(stmt->returningList))
4235  return true;
4236  if (WALK(stmt->withClause))
4237  return true;
4238  }
4239  break;
4240  case T_UpdateStmt:
4241  {
4242  UpdateStmt *stmt = (UpdateStmt *) node;
4243 
4244  if (WALK(stmt->relation))
4245  return true;
4246  if (WALK(stmt->targetList))
4247  return true;
4248  if (WALK(stmt->whereClause))
4249  return true;
4250  if (WALK(stmt->fromClause))
4251  return true;
4252  if (WALK(stmt->returningList))
4253  return true;
4254  if (WALK(stmt->withClause))
4255  return true;
4256  }
4257  break;
4258  case T_MergeStmt:
4259  {
4260  MergeStmt *stmt = (MergeStmt *) node;
4261 
4262  if (WALK(stmt->relation))
4263  return true;
4264  if (WALK(stmt->sourceRelation))
4265  return true;
4266  if (WALK(stmt->joinCondition))
4267  return true;
4268  if (WALK(stmt->mergeWhenClauses))
4269  return true;
4270  if (WALK(stmt->returningList))
4271  return true;
4272  if (WALK(stmt->withClause))
4273  return true;
4274  }
4275  break;
4276  case T_MergeWhenClause:
4277  {
4278  MergeWhenClause *mergeWhenClause = (MergeWhenClause *) node;
4279 
4280  if (WALK(mergeWhenClause->condition))
4281  return true;
4282  if (WALK(mergeWhenClause->targetList))
4283  return true;
4284  if (WALK(mergeWhenClause->values))
4285  return true;
4286  }
4287  break;
4288  case T_SelectStmt:
4289  {
4290  SelectStmt *stmt = (SelectStmt *) node;
4291 
4292  if (WALK(stmt->distinctClause))
4293  return true;
4294  if (WALK(stmt->intoClause))
4295  return true;
4296  if (WALK(stmt->targetList))
4297  return true;
4298  if (WALK(stmt->fromClause))
4299  return true;
4300  if (WALK(stmt->whereClause))
4301  return true;
4302  if (WALK(stmt->groupClause))
4303  return true;
4304  if (WALK(stmt->havingClause))
4305  return true;
4306  if (WALK(stmt->windowClause))
4307  return true;
4308  if (WALK(stmt->valuesLists))
4309  return true;
4310  if (WALK(stmt->sortClause))
4311  return true;
4312  if (WALK(stmt->limitOffset))
4313  return true;
4314  if (WALK(stmt->limitCount))
4315  return true;
4316  if (WALK(stmt->lockingClause))
4317  return true;
4318  if (WALK(stmt->withClause))
4319  return true;
4320  if (WALK(stmt->larg))
4321  return true;
4322  if (WALK(stmt->rarg))
4323  return true;
4324  }
4325  break;
4326  case T_PLAssignStmt:
4327  {
4328  PLAssignStmt *stmt = (PLAssignStmt *) node;
4329 
4330  if (WALK(stmt->indirection))
4331  return true;
4332  if (WALK(stmt->val))
4333  return true;
4334  }
4335  break;
4336  case T_A_Expr:
4337  {
4338  A_Expr *expr = (A_Expr *) node;
4339 
4340  if (WALK(expr->lexpr))
4341  return true;
4342  if (WALK(expr->rexpr))
4343  return true;
4344  /* operator name is deemed uninteresting */
4345  }
4346  break;
4347  case T_BoolExpr:
4348  {
4349  BoolExpr *expr = (BoolExpr *) node;
4350 
4351  if (WALK(expr->args))
4352  return true;