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 QTW_IGNORE_GROUPEXPRS   0x100 /* GROUP expressions list */
 
#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 155 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 153 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 179 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_GROUPEXPRS

#define QTW_IGNORE_GROUPEXPRS   0x100 /* GROUP expressions list */

Definition at line 32 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 173 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 171 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 160 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 158 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 168 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 165 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 163 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 176 of file nodeFuncs.h.

Typedef Documentation

◆ check_function_callback

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

Definition at line 35 of file nodeFuncs.h.

◆ planstate_tree_walker_callback

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

Definition at line 39 of file nodeFuncs.h.

◆ tree_mutator_callback

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

Definition at line 43 of file nodeFuncs.h.

◆ tree_walker_callback

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

Definition at line 38 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:1185
ParseLoc location
Definition: primnodes.h:1192
Expr * arg
Definition: primnodes.h:1184

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 1899 of file nodeFuncs.c.

1901 {
1902  switch (nodeTag(node))
1903  {
1904  case T_Aggref:
1905  {
1906  Aggref *expr = (Aggref *) node;
1907 
1908  if (checker(expr->aggfnoid, context))
1909  return true;
1910  }
1911  break;
1912  case T_WindowFunc:
1913  {
1914  WindowFunc *expr = (WindowFunc *) node;
1915 
1916  if (checker(expr->winfnoid, context))
1917  return true;
1918  }
1919  break;
1920  case T_FuncExpr:
1921  {
1922  FuncExpr *expr = (FuncExpr *) node;
1923 
1924  if (checker(expr->funcid, context))
1925  return true;
1926  }
1927  break;
1928  case T_OpExpr:
1929  case T_DistinctExpr: /* struct-equivalent to OpExpr */
1930  case T_NullIfExpr: /* struct-equivalent to OpExpr */
1931  {
1932  OpExpr *expr = (OpExpr *) node;
1933 
1934  /* Set opfuncid if it wasn't set already */
1935  set_opfuncid(expr);
1936  if (checker(expr->opfuncid, context))
1937  return true;
1938  }
1939  break;
1940  case T_ScalarArrayOpExpr:
1941  {
1942  ScalarArrayOpExpr *expr = (ScalarArrayOpExpr *) node;
1943 
1944  set_sa_opfuncid(expr);
1945  if (checker(expr->opfuncid, context))
1946  return true;
1947  }
1948  break;
1949  case T_CoerceViaIO:
1950  {
1951  CoerceViaIO *expr = (CoerceViaIO *) node;
1952  Oid iofunc;
1953  Oid typioparam;
1954  bool typisvarlena;
1955 
1956  /* check the result type's input function */
1958  &iofunc, &typioparam);
1959  if (checker(iofunc, context))
1960  return true;
1961  /* check the input type's output function */
1962  getTypeOutputInfo(exprType((Node *) expr->arg),
1963  &iofunc, &typisvarlena);
1964  if (checker(iofunc, context))
1965  return true;
1966  }
1967  break;
1968  case T_RowCompareExpr:
1969  {
1970  RowCompareExpr *rcexpr = (RowCompareExpr *) node;
1971  ListCell *opid;
1972 
1973  foreach(opid, rcexpr->opnos)
1974  {
1975  Oid opfuncid = get_opcode(lfirst_oid(opid));
1976 
1977  if (checker(opfuncid, context))
1978  return true;
1979  }
1980  }
1981  break;
1982  default:
1983  break;
1984  }
1985  return false;
1986 }
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:1872
void set_opfuncid(OpExpr *opexpr)
Definition: nodeFuncs.c:1861
#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:1835
Oid aggfnoid
Definition: primnodes.h:444
Expr * arg
Definition: primnodes.h:1207
Oid resulttype
Definition: primnodes.h:1208
Oid funcid
Definition: primnodes.h:750
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  coll = jsexpr->collation;
1010  }
1011  break;
1012  case T_JsonBehavior:
1013  {
1014  const JsonBehavior *behavior = (JsonBehavior *) expr;
1015 
1016  if (behavior->expr)
1017  coll = exprCollation(behavior->expr);
1018  else
1019  coll = InvalidOid;
1020  }
1021  break;
1022  case T_NullTest:
1023  /* NullTest's result is boolean ... */
1024  coll = InvalidOid; /* ... so it has no collation */
1025  break;
1026  case T_BooleanTest:
1027  /* BooleanTest's result is boolean ... */
1028  coll = InvalidOid; /* ... so it has no collation */
1029  break;
1030  case T_CoerceToDomain:
1031  coll = ((const CoerceToDomain *) expr)->resultcollid;
1032  break;
1033  case T_CoerceToDomainValue:
1034  coll = ((const CoerceToDomainValue *) expr)->collation;
1035  break;
1036  case T_SetToDefault:
1037  coll = ((const SetToDefault *) expr)->collation;
1038  break;
1039  case T_CurrentOfExpr:
1040  /* CurrentOfExpr's result is boolean ... */
1041  coll = InvalidOid; /* ... so it has no collation */
1042  break;
1043  case T_NextValueExpr:
1044  /* NextValueExpr's result is an integer type ... */
1045  coll = InvalidOid; /* ... so it has no collation */
1046  break;
1047  case T_InferenceElem:
1048  coll = exprCollation((Node *) ((const InferenceElem *) expr)->expr);
1049  break;
1050  case T_PlaceHolderVar:
1051  coll = exprCollation((Node *) ((const PlaceHolderVar *) expr)->phexpr);
1052  break;
1053  default:
1054  elog(ERROR, "unrecognized node type: %d", (int) nodeTag(expr));
1055  coll = InvalidOid; /* keep compiler quiet */
1056  break;
1057  }
1058  return coll;
1059 }
#define Assert(condition)
Definition: c.h:849
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:225
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:76
#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:1003
@ EXPR_SUBLINK
Definition: primnodes.h:1001
@ IS_XMLSERIALIZE
Definition: primnodes.h:1586
Node * expr
Definition: primnodes.h:1791
Oid collation
Definition: primnodes.h:1856
List * targetList
Definition: parsenodes.h:193
Oid firstColCollation
Definition: primnodes.h:1076
SubLinkType subLinkType
Definition: primnodes.h:1065
Definition: primnodes.h:248
const char * type

References arg, ARRAY_SUBLINK, Assert, JsonConstructorExpr::coercion, 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(), addRangeTableEntryForGroup(), 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_attr_stat_type(), 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 2937 of file nodeFuncs.c.

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

References generate_unaccent_rules::action, Aggref::aggdirectargs, Aggref::aggdistinct, Aggref::aggfilter, WindowFunc::aggfilter, Aggref::aggorder, OnConflictExpr::arbiterElems, OnConflictExpr::arbiterWhere, WindowFuncRunCondition::arg, 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, 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 2082 of file nodeFuncs.c.

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

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

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:736
@ COERCE_EXPLICIT_CAST
Definition: primnodes.h:735

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 1380 of file nodeFuncs.c.

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

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 1116 of file nodeFuncs.c.

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

References arg, ARRAY_SUBLINK, Assert, JsonConstructorExpr::coercion, 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 1316 of file nodeFuncs.c.

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

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:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#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:1002
@ IS_DOCUMENT
Definition: primnodes.h:1587
JsonReturning * returning
Definition: primnodes.h:1832
Oid firstColType
Definition: primnodes.h:1074

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(), addRangeTableEntryForGroup(), 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(), calculate_frame_offsets(), CallStmtResultDesc(), 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(), 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(), ExecInitSubPlanExpr(), ExecMakeTableFunctionResult(), ExecTypeFromExprList(), ExecTypeFromTLInternal(), 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_attr_stat_type(), 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:496
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:1075

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(), addRangeTableEntryForGroup(), addRangeTableEntryForSubquery(), analyzeCTE(), analyzeCTETargetList(), applyRelabelType(), assign_hypothetical_collations(), build_coercion_expression(), build_subplan(), canonicalize_ec_expression(), checkRuleResultList(), coerce_type_typmod(), 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_attr_stat_type(), 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 1830 of file nodeFuncs.c.

1831 {
1832  /* This tree walk requires no special setup, so away we go... */
1833  fix_opfuncids_walker(node, NULL);
1834 }
static bool fix_opfuncids_walker(Node *node, void *context)
Definition: nodeFuncs.c:1837

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()

◆ 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 4689 of file nodeFuncs.c.

4692 {
4693  Plan *plan = planstate->plan;
4694  ListCell *lc;
4695 
4696  /* We don't need implicit coercions to Node here */
4697 #define PSWALK(n) walker(n, context)
4698 
4699  /* Guard against stack overflow due to overly complex plan trees */
4701 
4702  /* initPlan-s */
4703  if (planstate_walk_subplans(planstate->initPlan, walker, context))
4704  return true;
4705 
4706  /* lefttree */
4707  if (outerPlanState(planstate))
4708  {
4709  if (PSWALK(outerPlanState(planstate)))
4710  return true;
4711  }
4712 
4713  /* righttree */
4714  if (innerPlanState(planstate))
4715  {
4716  if (PSWALK(innerPlanState(planstate)))
4717  return true;
4718  }
4719 
4720  /* special child plans */
4721  switch (nodeTag(plan))
4722  {
4723  case T_Append:
4724  if (planstate_walk_members(((AppendState *) planstate)->appendplans,
4725  ((AppendState *) planstate)->as_nplans,
4726  walker, context))
4727  return true;
4728  break;
4729  case T_MergeAppend:
4730  if (planstate_walk_members(((MergeAppendState *) planstate)->mergeplans,
4731  ((MergeAppendState *) planstate)->ms_nplans,
4732  walker, context))
4733  return true;
4734  break;
4735  case T_BitmapAnd:
4736  if (planstate_walk_members(((BitmapAndState *) planstate)->bitmapplans,
4737  ((BitmapAndState *) planstate)->nplans,
4738  walker, context))
4739  return true;
4740  break;
4741  case T_BitmapOr:
4742  if (planstate_walk_members(((BitmapOrState *) planstate)->bitmapplans,
4743  ((BitmapOrState *) planstate)->nplans,
4744  walker, context))
4745  return true;
4746  break;
4747  case T_SubqueryScan:
4748  if (PSWALK(((SubqueryScanState *) planstate)->subplan))
4749  return true;
4750  break;
4751  case T_CustomScan:
4752  foreach(lc, ((CustomScanState *) planstate)->custom_ps)
4753  {
4754  if (PSWALK(lfirst(lc)))
4755  return true;
4756  }
4757  break;
4758  default:
4759  break;
4760  }
4761 
4762  /* subPlan-s */
4763  if (planstate_walk_subplans(planstate->subPlan, walker, context))
4764  return true;
4765 
4766  return false;
4767 }
#define outerPlanState(node)
Definition: execnodes.h:1223
#define innerPlanState(node)
Definition: execnodes.h:1222
static bool planstate_walk_subplans(List *plans, planstate_tree_walker_callback walker, void *context)
Definition: nodeFuncs.c:4773
#define PSWALK(n)
static bool planstate_walk_members(PlanState **planstates, int nplans, planstate_tree_walker_callback walker, void *context)
Definition: nodeFuncs.c:4795
#define plan(x)
Definition: pg_regress.c:161
Plan * plan
Definition: execnodes.h:1127
List * initPlan
Definition: execnodes.h:1152

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 3946 of file nodeFuncs.c.

3950 {
3951  if (node && IsA(node, Query))
3952  return (Node *) query_tree_mutator((Query *) node,
3953  mutator,
3954  context,
3955  flags);
3956  else
3957  return mutator(node, context);
3958 }
#define query_tree_mutator(q, m, c, f)
Definition: nodeFuncs.h:160

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 3923 of file nodeFuncs.c.

3927 {
3928  if (node && IsA(node, Query))
3929  return query_tree_walker((Query *) node,
3930  walker,
3931  context,
3932  flags);
3933  else
3934  return WALK(node);
3935 }
#define query_tree_walker(q, w, c, f)
Definition: nodeFuncs.h:158

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 3754 of file nodeFuncs.c.

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

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 2685 of file nodeFuncs.c.

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

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

References RangeTblEntry::functions, QTW_EXAMINE_RTES_AFTER, QTW_EXAMINE_RTES_BEFORE, QTW_IGNORE_GROUPEXPRS, QTW_IGNORE_JOINALIASES, QTW_IGNORE_RT_SUBQUERIES, RTE_CTE, RTE_FUNCTION, RTE_GROUP, 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 3845 of file nodeFuncs.c.

3849 {
3850  List *newrt = NIL;
3851  ListCell *rt;
3852 
3853  foreach(rt, rtable)
3854  {
3855  RangeTblEntry *rte = (RangeTblEntry *) lfirst(rt);
3856  RangeTblEntry *newrte;
3857 
3858  FLATCOPY(newrte, rte, RangeTblEntry);
3859  switch (rte->rtekind)
3860  {
3861  case RTE_RELATION:
3862  MUTATE(newrte->tablesample, rte->tablesample,
3863  TableSampleClause *);
3864  /* we don't bother to copy eref, aliases, etc; OK? */
3865  break;
3866  case RTE_SUBQUERY:
3867  if (!(flags & QTW_IGNORE_RT_SUBQUERIES))
3868  MUTATE(newrte->subquery, rte->subquery, Query *);
3869  else
3870  {
3871  /* else, copy RT subqueries as-is */
3872  newrte->subquery = copyObject(rte->subquery);
3873  }
3874  break;
3875  case RTE_JOIN:
3876  if (!(flags & QTW_IGNORE_JOINALIASES))
3877  MUTATE(newrte->joinaliasvars, rte->joinaliasvars, List *);
3878  else
3879  {
3880  /* else, copy join aliases as-is */
3881  newrte->joinaliasvars = copyObject(rte->joinaliasvars);
3882  }
3883  break;
3884  case RTE_FUNCTION:
3885  MUTATE(newrte->functions, rte->functions, List *);
3886  break;
3887  case RTE_TABLEFUNC:
3888  MUTATE(newrte->tablefunc, rte->tablefunc, TableFunc *);
3889  break;
3890  case RTE_VALUES:
3891  MUTATE(newrte->values_lists, rte->values_lists, List *);
3892  break;
3893  case RTE_CTE:
3894  case RTE_NAMEDTUPLESTORE:
3895  case RTE_RESULT:
3896  /* nothing to do */
3897  break;
3898  case RTE_GROUP:
3899  if (!(flags & QTW_IGNORE_GROUPEXPRS))
3900  MUTATE(newrte->groupexprs, rte->groupexprs, List *);
3901  else
3902  {
3903  /* else, copy grouping exprs as-is */
3904  newrte->groupexprs = copyObject(rte->groupexprs);
3905  }
3906  break;
3907  }
3908  MUTATE(newrte->securityQuals, rte->securityQuals, List *);
3909  newrt = lappend(newrt, newrte);
3910  }
3911  return newrt;
3912 }

References copyObject, FLATCOPY, RangeTblEntry::functions, lappend(), lfirst, MUTATE, NIL, QTW_IGNORE_GROUPEXPRS, QTW_IGNORE_JOINALIASES, QTW_IGNORE_RT_SUBQUERIES, RTE_CTE, RTE_FUNCTION, RTE_GROUP, 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 2788 of file nodeFuncs.c.

2792 {
2793  ListCell *rt;
2794 
2795  foreach(rt, rtable)
2796  {
2798 
2799  if (range_table_entry_walker(rte, walker, context, flags))
2800  return true;
2801  }
2802  return false;
2803 }
#define range_table_entry_walker(r, w, c, f)
Definition: nodeFuncs.h:168

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 3977 of file nodeFuncs.c.

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