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

Go to the source code of this file.

Macros

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

Typedefs

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

Functions

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

Macro Definition Documentation

◆ expression_tree_mutator

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

Definition at line 153 of file nodeFuncs.h.

◆ expression_tree_walker

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

Definition at line 151 of file nodeFuncs.h.

◆ planstate_tree_walker

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

Definition at line 177 of file nodeFuncs.h.

◆ QTW_DONT_COPY_QUERY

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

Definition at line 29 of file nodeFuncs.h.

◆ QTW_EXAMINE_RTES_AFTER

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

Definition at line 28 of file nodeFuncs.h.

◆ QTW_EXAMINE_RTES_BEFORE

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

Definition at line 27 of file nodeFuncs.h.

◆ QTW_EXAMINE_SORTGROUP

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

Definition at line 30 of file nodeFuncs.h.

◆ QTW_IGNORE_CTE_SUBQUERIES

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

Definition at line 23 of file nodeFuncs.h.

◆ QTW_IGNORE_JOINALIASES

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

Definition at line 25 of file nodeFuncs.h.

◆ QTW_IGNORE_RANGE_TABLE

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

Definition at line 26 of file nodeFuncs.h.

◆ QTW_IGNORE_RC_SUBQUERIES

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

Definition at line 24 of file nodeFuncs.h.

◆ QTW_IGNORE_RT_SUBQUERIES

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

Definition at line 22 of file nodeFuncs.h.

◆ query_or_expression_tree_mutator

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

Definition at line 171 of file nodeFuncs.h.

◆ query_or_expression_tree_walker

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

Definition at line 169 of file nodeFuncs.h.

◆ query_tree_mutator

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

Definition at line 158 of file nodeFuncs.h.

◆ query_tree_walker

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

Definition at line 156 of file nodeFuncs.h.

◆ range_table_entry_walker

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

Definition at line 166 of file nodeFuncs.h.

◆ range_table_mutator

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

Definition at line 163 of file nodeFuncs.h.

◆ range_table_walker

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

Definition at line 161 of file nodeFuncs.h.

◆ raw_expression_tree_walker

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

Definition at line 174 of file nodeFuncs.h.

Typedef Documentation

◆ check_function_callback

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

Definition at line 33 of file nodeFuncs.h.

◆ planstate_tree_walker_callback

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

Definition at line 37 of file nodeFuncs.h.

◆ tree_mutator_callback

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

Definition at line 41 of file nodeFuncs.h.

◆ tree_walker_callback

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

Definition at line 36 of file nodeFuncs.h.

Function Documentation

◆ applyRelabelType()

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

Definition at line 601 of file nodeFuncs.c.

603 {
604  /*
605  * If we find stacked RelabelTypes (eg, from foo::int::oid) we can discard
606  * all but the top one, and must do so to ensure that semantically
607  * equivalent expressions are equal().
608  */
609  while (arg && IsA(arg, RelabelType))
610  arg = (Node *) ((RelabelType *) arg)->arg;
611 
612  if (arg && IsA(arg, Const))
613  {
614  /* Modify the Const directly to preserve const-flatness. */
615  Const *con = (Const *) arg;
616 
617  if (!overwrite_ok)
618  con = copyObject(con);
619  con->consttype = rtype;
620  con->consttypmod = rtypmod;
621  con->constcollid = rcollid;
622  /* We keep the Const's original location. */
623  return (Node *) con;
624  }
625  else if (exprType(arg) == rtype &&
626  exprTypmod(arg) == rtypmod &&
627  exprCollation(arg) == rcollid)
628  {
629  /* Sometimes we find a nest of relabels that net out to nothing. */
630  return arg;
631  }
632  else
633  {
634  /* Nope, gotta have a RelabelType. */
635  RelabelType *newrelabel = makeNode(RelabelType);
636 
637  newrelabel->arg = (Expr *) arg;
638  newrelabel->resulttype = rtype;
639  newrelabel->resulttypmod = rtypmod;
640  newrelabel->resultcollid = rcollid;
641  newrelabel->relabelformat = rformat;
642  newrelabel->location = rlocation;
643  return (Node *) newrelabel;
644  }
645 }
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:43
int32 exprTypmod(const Node *expr)
Definition: nodeFuncs.c:282
Oid exprCollation(const Node *expr)
Definition: nodeFuncs.c:786
#define IsA(nodeptr, _type_)
Definition: nodes.h:179
#define copyObject(obj)
Definition: nodes.h:244
#define makeNode(_type_)
Definition: nodes.h:176
void * arg
Oid consttype
Definition: primnodes.h:298
Definition: nodes.h:129
Oid resulttype
Definition: primnodes.h:1120
Expr * arg
Definition: primnodes.h:1119

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

1819 {
1820  switch (nodeTag(node))
1821  {
1822  case T_Aggref:
1823  {
1824  Aggref *expr = (Aggref *) node;
1825 
1826  if (checker(expr->aggfnoid, context))
1827  return true;
1828  }
1829  break;
1830  case T_WindowFunc:
1831  {
1832  WindowFunc *expr = (WindowFunc *) node;
1833 
1834  if (checker(expr->winfnoid, context))
1835  return true;
1836  }
1837  break;
1838  case T_FuncExpr:
1839  {
1840  FuncExpr *expr = (FuncExpr *) node;
1841 
1842  if (checker(expr->funcid, context))
1843  return true;
1844  }
1845  break;
1846  case T_OpExpr:
1847  case T_DistinctExpr: /* struct-equivalent to OpExpr */
1848  case T_NullIfExpr: /* struct-equivalent to OpExpr */
1849  {
1850  OpExpr *expr = (OpExpr *) node;
1851 
1852  /* Set opfuncid if it wasn't set already */
1853  set_opfuncid(expr);
1854  if (checker(expr->opfuncid, context))
1855  return true;
1856  }
1857  break;
1858  case T_ScalarArrayOpExpr:
1859  {
1860  ScalarArrayOpExpr *expr = (ScalarArrayOpExpr *) node;
1861 
1862  set_sa_opfuncid(expr);
1863  if (checker(expr->opfuncid, context))
1864  return true;
1865  }
1866  break;
1867  case T_CoerceViaIO:
1868  {
1869  CoerceViaIO *expr = (CoerceViaIO *) node;
1870  Oid iofunc;
1871  Oid typioparam;
1872  bool typisvarlena;
1873 
1874  /* check the result type's input function */
1876  &iofunc, &typioparam);
1877  if (checker(iofunc, context))
1878  return true;
1879  /* check the input type's output function */
1880  getTypeOutputInfo(exprType((Node *) expr->arg),
1881  &iofunc, &typisvarlena);
1882  if (checker(iofunc, context))
1883  return true;
1884  }
1885  break;
1886  case T_RowCompareExpr:
1887  {
1888  RowCompareExpr *rcexpr = (RowCompareExpr *) node;
1889  ListCell *opid;
1890 
1891  foreach(opid, rcexpr->opnos)
1892  {
1893  Oid opfuncid = get_opcode(lfirst_oid(opid));
1894 
1895  if (checker(opfuncid, context))
1896  return true;
1897  }
1898  }
1899  break;
1900  default:
1901  break;
1902  }
1903  return false;
1904 }
void getTypeOutputInfo(Oid type, Oid *typOutput, bool *typIsVarlena)
Definition: lsyscache.c:2889
RegProcedure get_opcode(Oid opno)
Definition: lsyscache.c:1289
void getTypeInputInfo(Oid type, Oid *typInput, Oid *typIOParam)
Definition: lsyscache.c:2856
void set_sa_opfuncid(ScalarArrayOpExpr *opexpr)
Definition: nodeFuncs.c:1790
void set_opfuncid(OpExpr *opexpr)
Definition: nodeFuncs.c:1779
#define nodeTag(nodeptr)
Definition: nodes.h:133
#define lfirst_oid(lc)
Definition: pg_list.h:174
unsigned int Oid
Definition: postgres_ext.h:31
Oid aggfnoid
Definition: primnodes.h:430
Expr * arg
Definition: primnodes.h:1142
Oid resulttype
Definition: primnodes.h:1143
Oid funcid
Definition: primnodes.h:685
Oid winfnoid
Definition: primnodes.h:553

References Aggref::aggfnoid, CoerceViaIO::arg, 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 786 of file nodeFuncs.c.

787 {
788  Oid coll;
789 
790  if (!expr)
791  return InvalidOid;
792 
793  switch (nodeTag(expr))
794  {
795  case T_Var:
796  coll = ((const Var *) expr)->varcollid;
797  break;
798  case T_Const:
799  coll = ((const Const *) expr)->constcollid;
800  break;
801  case T_Param:
802  coll = ((const Param *) expr)->paramcollid;
803  break;
804  case T_Aggref:
805  coll = ((const Aggref *) expr)->aggcollid;
806  break;
807  case T_GroupingFunc:
808  coll = InvalidOid;
809  break;
810  case T_WindowFunc:
811  coll = ((const WindowFunc *) expr)->wincollid;
812  break;
813  case T_SubscriptingRef:
814  coll = ((const SubscriptingRef *) expr)->refcollid;
815  break;
816  case T_FuncExpr:
817  coll = ((const FuncExpr *) expr)->funccollid;
818  break;
819  case T_NamedArgExpr:
820  coll = exprCollation((Node *) ((const NamedArgExpr *) expr)->arg);
821  break;
822  case T_OpExpr:
823  coll = ((const OpExpr *) expr)->opcollid;
824  break;
825  case T_DistinctExpr:
826  coll = ((const DistinctExpr *) expr)->opcollid;
827  break;
828  case T_NullIfExpr:
829  coll = ((const NullIfExpr *) expr)->opcollid;
830  break;
831  case T_ScalarArrayOpExpr:
832  /* ScalarArrayOpExpr's result is boolean ... */
833  coll = InvalidOid; /* ... so it has no collation */
834  break;
835  case T_BoolExpr:
836  /* BoolExpr's result is boolean ... */
837  coll = InvalidOid; /* ... so it has no collation */
838  break;
839  case T_SubLink:
840  {
841  const SubLink *sublink = (const SubLink *) expr;
842 
843  if (sublink->subLinkType == EXPR_SUBLINK ||
844  sublink->subLinkType == ARRAY_SUBLINK)
845  {
846  /* get the collation of subselect's first target column */
847  Query *qtree = (Query *) sublink->subselect;
848  TargetEntry *tent;
849 
850  if (!qtree || !IsA(qtree, Query))
851  elog(ERROR, "cannot get collation for untransformed sublink");
852  tent = linitial_node(TargetEntry, qtree->targetList);
853  Assert(!tent->resjunk);
854  coll = exprCollation((Node *) tent->expr);
855  /* collation doesn't change if it's converted to array */
856  }
857  else
858  {
859  /* otherwise, SubLink's result is RECORD or BOOLEAN */
860  coll = InvalidOid; /* ... so it has no collation */
861  }
862  }
863  break;
864  case T_SubPlan:
865  {
866  const SubPlan *subplan = (const SubPlan *) expr;
867 
868  if (subplan->subLinkType == EXPR_SUBLINK ||
869  subplan->subLinkType == ARRAY_SUBLINK)
870  {
871  /* get the collation of subselect's first target column */
872  coll = subplan->firstColCollation;
873  /* collation doesn't change if it's converted to array */
874  }
875  else
876  {
877  /* otherwise, SubPlan's result is RECORD or BOOLEAN */
878  coll = InvalidOid; /* ... so it has no collation */
879  }
880  }
881  break;
882  case T_AlternativeSubPlan:
883  {
884  const AlternativeSubPlan *asplan = (const AlternativeSubPlan *) expr;
885 
886  /* subplans should all return the same thing */
887  coll = exprCollation((Node *) linitial(asplan->subplans));
888  }
889  break;
890  case T_FieldSelect:
891  coll = ((const FieldSelect *) expr)->resultcollid;
892  break;
893  case T_FieldStore:
894  /* FieldStore's result is composite ... */
895  coll = InvalidOid; /* ... so it has no collation */
896  break;
897  case T_RelabelType:
898  coll = ((const RelabelType *) expr)->resultcollid;
899  break;
900  case T_CoerceViaIO:
901  coll = ((const CoerceViaIO *) expr)->resultcollid;
902  break;
903  case T_ArrayCoerceExpr:
904  coll = ((const ArrayCoerceExpr *) expr)->resultcollid;
905  break;
906  case T_ConvertRowtypeExpr:
907  /* ConvertRowtypeExpr's result is composite ... */
908  coll = InvalidOid; /* ... so it has no collation */
909  break;
910  case T_CollateExpr:
911  coll = ((const CollateExpr *) expr)->collOid;
912  break;
913  case T_CaseExpr:
914  coll = ((const CaseExpr *) expr)->casecollid;
915  break;
916  case T_CaseTestExpr:
917  coll = ((const CaseTestExpr *) expr)->collation;
918  break;
919  case T_ArrayExpr:
920  coll = ((const ArrayExpr *) expr)->array_collid;
921  break;
922  case T_RowExpr:
923  /* RowExpr's result is composite ... */
924  coll = InvalidOid; /* ... so it has no collation */
925  break;
926  case T_RowCompareExpr:
927  /* RowCompareExpr's result is boolean ... */
928  coll = InvalidOid; /* ... so it has no collation */
929  break;
930  case T_CoalesceExpr:
931  coll = ((const CoalesceExpr *) expr)->coalescecollid;
932  break;
933  case T_MinMaxExpr:
934  coll = ((const MinMaxExpr *) expr)->minmaxcollid;
935  break;
936  case T_SQLValueFunction:
937  /* Returns either NAME or a non-collatable type */
938  if (((const SQLValueFunction *) expr)->type == NAMEOID)
939  coll = C_COLLATION_OID;
940  else
941  coll = InvalidOid;
942  break;
943  case T_XmlExpr:
944 
945  /*
946  * XMLSERIALIZE returns text from non-collatable inputs, so its
947  * collation is always default. The other cases return boolean or
948  * XML, which are non-collatable.
949  */
950  if (((const XmlExpr *) expr)->op == IS_XMLSERIALIZE)
951  coll = DEFAULT_COLLATION_OID;
952  else
953  coll = InvalidOid;
954  break;
955  case T_JsonValueExpr:
956  coll = exprCollation((Node *) ((const JsonValueExpr *) expr)->formatted_expr);
957  break;
958  case T_JsonConstructorExpr:
959  {
960  const JsonConstructorExpr *ctor = (const JsonConstructorExpr *) expr;
961 
962  if (ctor->coercion)
963  coll = exprCollation((Node *) ctor->coercion);
964  else
965  coll = InvalidOid;
966  }
967  break;
968  case T_JsonIsPredicate:
969  /* IS JSON's result is boolean ... */
970  coll = InvalidOid; /* ... so it has no collation */
971  break;
972  case T_NullTest:
973  /* NullTest's result is boolean ... */
974  coll = InvalidOid; /* ... so it has no collation */
975  break;
976  case T_BooleanTest:
977  /* BooleanTest's result is boolean ... */
978  coll = InvalidOid; /* ... so it has no collation */
979  break;
980  case T_CoerceToDomain:
981  coll = ((const CoerceToDomain *) expr)->resultcollid;
982  break;
983  case T_CoerceToDomainValue:
984  coll = ((const CoerceToDomainValue *) expr)->collation;
985  break;
986  case T_SetToDefault:
987  coll = ((const SetToDefault *) expr)->collation;
988  break;
989  case T_CurrentOfExpr:
990  /* CurrentOfExpr's result is boolean ... */
991  coll = InvalidOid; /* ... so it has no collation */
992  break;
993  case T_NextValueExpr:
994  /* NextValueExpr's result is an integer type ... */
995  coll = InvalidOid; /* ... so it has no collation */
996  break;
997  case T_InferenceElem:
998  coll = exprCollation((Node *) ((const InferenceElem *) expr)->expr);
999  break;
1000  case T_PlaceHolderVar:
1001  coll = exprCollation((Node *) ((const PlaceHolderVar *) expr)->phexpr);
1002  break;
1003  default:
1004  elog(ERROR, "unrecognized node type: %d", (int) nodeTag(expr));
1005  coll = InvalidOid; /* keep compiler quiet */
1006  break;
1007  }
1008  return coll;
1009 }
#define ERROR
Definition: elog.h:39
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:77
Assert(fmt[strlen(fmt) - 1] !='\n')
#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:938
@ EXPR_SUBLINK
Definition: primnodes.h:936
@ IS_XMLSERIALIZE
Definition: primnodes.h:1521
List * targetList
Definition: parsenodes.h:181
Oid firstColCollation
Definition: primnodes.h:1011
SubLinkType subLinkType
Definition: primnodes.h:1000
Definition: primnodes.h:234
const char * type

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

Referenced by addRangeTableEntryForFunction(), addRangeTableEntryForSubquery(), analyzeCTE(), analyzeCTETargetList(), applyRelabelType(), assign_collations_walker(), assign_hypothetical_collations(), build_expression_pathkey(), build_pertrans_for_aggref(), build_subplan(), canonicalize_ec_expression(), check_simple_rowfilter_expr_walker(), coerce_type_typmod(), ComputeIndexAttrs(), ComputePartitionAttrs(), convert_EXISTS_to_ANY(), create_ctas_nodata(), create_limit_plan(), create_memoize_plan(), create_unique_plan(), create_windowagg_plan(), DefineVirtualRelation(), eval_const_expressions_mutator(), examine_attribute(), examine_expression(), ExecInitFunctionScan(), ExecInitIndexScan(), ExecTypeFromExprList(), ExecTypeFromTLInternal(), expandRecordVariable(), expandRTE(), exprSetCollation(), extract_grouping_collations(), fix_indexqual_operand(), generate_setop_tlist(), generate_subquery_params(), get_expr_result_type(), get_first_col_type(), inline_function(), make_pathkey_from_sortop(), make_recursive_union(), make_setop(), make_sort_from_groupcols(), make_sort_from_sortclauses(), make_unique_from_sortclauses(), makeJsonConstructorExpr(), makeVarFromTargetEntry(), makeWholeRowVar(), mcv_match_expression(), ordered_set_startup(), pg_get_indexdef_worker(), pg_get_partkeydef_worker(), preprocess_minmax_aggregates(), relabel_to_typmod(), RelationBuildPartitionKey(), RelationGetDummyIndexExpressions(), remove_unused_subquery_outputs(), replace_nestloop_param_placeholdervar(), replace_outer_placeholdervar(), scalararraysel(), set_dummy_tlist_references(), set_joinrel_partition_key_exprs(), tlist_same_collations(), transformCaseExpr(), transformFromClauseItem(), 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 2808 of file nodeFuncs.c.

2811 {
2812  /*
2813  * The mutator has already decided not to modify the current node, but we
2814  * must call the mutator for any sub-nodes.
2815  */
2816 
2817 #define FLATCOPY(newnode, node, nodetype) \
2818  ( (newnode) = (nodetype *) palloc(sizeof(nodetype)), \
2819  memcpy((newnode), (node), sizeof(nodetype)) )
2820 
2821 #define MUTATE(newfield, oldfield, fieldtype) \
2822  ( (newfield) = (fieldtype) mutator((Node *) (oldfield), context) )
2823 
2824  if (node == NULL)
2825  return NULL;
2826 
2827  /* Guard against stack overflow due to overly complex expressions */
2829 
2830  switch (nodeTag(node))
2831  {
2832  /*
2833  * Primitive node types with no expression subnodes. Var and
2834  * Const are frequent enough to deserve special cases, the others
2835  * we just use copyObject for.
2836  */
2837  case T_Var:
2838  {
2839  Var *var = (Var *) node;
2840  Var *newnode;
2841 
2842  FLATCOPY(newnode, var, Var);
2843  /* Assume we need not copy the varnullingrels bitmapset */
2844  return (Node *) newnode;
2845  }
2846  break;
2847  case T_Const:
2848  {
2849  Const *oldnode = (Const *) node;
2850  Const *newnode;
2851 
2852  FLATCOPY(newnode, oldnode, Const);
2853  /* XXX we don't bother with datumCopy; should we? */
2854  return (Node *) newnode;
2855  }
2856  break;
2857  case T_Param:
2858  case T_CaseTestExpr:
2859  case T_SQLValueFunction:
2860  case T_JsonFormat:
2861  case T_CoerceToDomainValue:
2862  case T_SetToDefault:
2863  case T_CurrentOfExpr:
2864  case T_NextValueExpr:
2865  case T_RangeTblRef:
2866  case T_SortGroupClause:
2867  case T_CTESearchClause:
2868  return (Node *) copyObject(node);
2869  case T_WithCheckOption:
2870  {
2871  WithCheckOption *wco = (WithCheckOption *) node;
2872  WithCheckOption *newnode;
2873 
2874  FLATCOPY(newnode, wco, WithCheckOption);
2875  MUTATE(newnode->qual, wco->qual, Node *);
2876  return (Node *) newnode;
2877  }
2878  case T_Aggref:
2879  {
2880  Aggref *aggref = (Aggref *) node;
2881  Aggref *newnode;
2882 
2883  FLATCOPY(newnode, aggref, Aggref);
2884  /* assume mutation doesn't change types of arguments */
2885  newnode->aggargtypes = list_copy(aggref->aggargtypes);
2886  MUTATE(newnode->aggdirectargs, aggref->aggdirectargs, List *);
2887  MUTATE(newnode->args, aggref->args, List *);
2888  MUTATE(newnode->aggorder, aggref->aggorder, List *);
2889  MUTATE(newnode->aggdistinct, aggref->aggdistinct, List *);
2890  MUTATE(newnode->aggfilter, aggref->aggfilter, Expr *);
2891  return (Node *) newnode;
2892  }
2893  break;
2894  case T_GroupingFunc:
2895  {
2896  GroupingFunc *grouping = (GroupingFunc *) node;
2897  GroupingFunc *newnode;
2898 
2899  FLATCOPY(newnode, grouping, GroupingFunc);
2900  MUTATE(newnode->args, grouping->args, List *);
2901 
2902  /*
2903  * We assume here that mutating the arguments does not change
2904  * the semantics, i.e. that the arguments are not mutated in a
2905  * way that makes them semantically different from their
2906  * previously matching expressions in the GROUP BY clause.
2907  *
2908  * If a mutator somehow wanted to do this, it would have to
2909  * handle the refs and cols lists itself as appropriate.
2910  */
2911  newnode->refs = list_copy(grouping->refs);
2912  newnode->cols = list_copy(grouping->cols);
2913 
2914  return (Node *) newnode;
2915  }
2916  break;
2917  case T_WindowFunc:
2918  {
2919  WindowFunc *wfunc = (WindowFunc *) node;
2920  WindowFunc *newnode;
2921 
2922  FLATCOPY(newnode, wfunc, WindowFunc);
2923  MUTATE(newnode->args, wfunc->args, List *);
2924  MUTATE(newnode->aggfilter, wfunc->aggfilter, Expr *);
2925  return (Node *) newnode;
2926  }
2927  break;
2928  case T_SubscriptingRef:
2929  {
2930  SubscriptingRef *sbsref = (SubscriptingRef *) node;
2931  SubscriptingRef *newnode;
2932 
2933  FLATCOPY(newnode, sbsref, SubscriptingRef);
2934  MUTATE(newnode->refupperindexpr, sbsref->refupperindexpr,
2935  List *);
2936  MUTATE(newnode->reflowerindexpr, sbsref->reflowerindexpr,
2937  List *);
2938  MUTATE(newnode->refexpr, sbsref->refexpr,
2939  Expr *);
2940  MUTATE(newnode->refassgnexpr, sbsref->refassgnexpr,
2941  Expr *);
2942 
2943  return (Node *) newnode;
2944  }
2945  break;
2946  case T_FuncExpr:
2947  {
2948  FuncExpr *expr = (FuncExpr *) node;
2949  FuncExpr *newnode;
2950 
2951  FLATCOPY(newnode, expr, FuncExpr);
2952  MUTATE(newnode->args, expr->args, List *);
2953  return (Node *) newnode;
2954  }
2955  break;
2956  case T_NamedArgExpr:
2957  {
2958  NamedArgExpr *nexpr = (NamedArgExpr *) node;
2959  NamedArgExpr *newnode;
2960 
2961  FLATCOPY(newnode, nexpr, NamedArgExpr);
2962  MUTATE(newnode->arg, nexpr->arg, Expr *);
2963  return (Node *) newnode;
2964  }
2965  break;
2966  case T_OpExpr:
2967  {
2968  OpExpr *expr = (OpExpr *) node;
2969  OpExpr *newnode;
2970 
2971  FLATCOPY(newnode, expr, OpExpr);
2972  MUTATE(newnode->args, expr->args, List *);
2973  return (Node *) newnode;
2974  }
2975  break;
2976  case T_DistinctExpr:
2977  {
2978  DistinctExpr *expr = (DistinctExpr *) node;
2979  DistinctExpr *newnode;
2980 
2981  FLATCOPY(newnode, expr, DistinctExpr);
2982  MUTATE(newnode->args, expr->args, List *);
2983  return (Node *) newnode;
2984  }
2985  break;
2986  case T_NullIfExpr:
2987  {
2988  NullIfExpr *expr = (NullIfExpr *) node;
2989  NullIfExpr *newnode;
2990 
2991  FLATCOPY(newnode, expr, NullIfExpr);
2992  MUTATE(newnode->args, expr->args, List *);
2993  return (Node *) newnode;
2994  }
2995  break;
2996  case T_ScalarArrayOpExpr:
2997  {
2998  ScalarArrayOpExpr *expr = (ScalarArrayOpExpr *) node;
2999  ScalarArrayOpExpr *newnode;
3000 
3001  FLATCOPY(newnode, expr, ScalarArrayOpExpr);
3002  MUTATE(newnode->args, expr->args, List *);
3003  return (Node *) newnode;
3004  }
3005  break;
3006  case T_BoolExpr:
3007  {
3008  BoolExpr *expr = (BoolExpr *) node;
3009  BoolExpr *newnode;
3010 
3011  FLATCOPY(newnode, expr, BoolExpr);
3012  MUTATE(newnode->args, expr->args, List *);
3013  return (Node *) newnode;
3014  }
3015  break;
3016  case T_SubLink:
3017  {
3018  SubLink *sublink = (SubLink *) node;
3019  SubLink *newnode;
3020 
3021  FLATCOPY(newnode, sublink, SubLink);
3022  MUTATE(newnode->testexpr, sublink->testexpr, Node *);
3023 
3024  /*
3025  * Also invoke the mutator on the sublink's Query node, so it
3026  * can recurse into the sub-query if it wants to.
3027  */
3028  MUTATE(newnode->subselect, sublink->subselect, Node *);
3029  return (Node *) newnode;
3030  }
3031  break;
3032  case T_SubPlan:
3033  {
3034  SubPlan *subplan = (SubPlan *) node;
3035  SubPlan *newnode;
3036 
3037  FLATCOPY(newnode, subplan, SubPlan);
3038  /* transform testexpr */
3039  MUTATE(newnode->testexpr, subplan->testexpr, Node *);
3040  /* transform args list (params to be passed to subplan) */
3041  MUTATE(newnode->args, subplan->args, List *);
3042  /* but not the sub-Plan itself, which is referenced as-is */
3043  return (Node *) newnode;
3044  }
3045  break;
3046  case T_AlternativeSubPlan:
3047  {
3048  AlternativeSubPlan *asplan = (AlternativeSubPlan *) node;
3049  AlternativeSubPlan *newnode;
3050 
3051  FLATCOPY(newnode, asplan, AlternativeSubPlan);
3052  MUTATE(newnode->subplans, asplan->subplans, List *);
3053  return (Node *) newnode;
3054  }
3055  break;
3056  case T_FieldSelect:
3057  {
3058  FieldSelect *fselect = (FieldSelect *) node;
3059  FieldSelect *newnode;
3060 
3061  FLATCOPY(newnode, fselect, FieldSelect);
3062  MUTATE(newnode->arg, fselect->arg, Expr *);
3063  return (Node *) newnode;
3064  }
3065  break;
3066  case T_FieldStore:
3067  {
3068  FieldStore *fstore = (FieldStore *) node;
3069  FieldStore *newnode;
3070 
3071  FLATCOPY(newnode, fstore, FieldStore);
3072  MUTATE(newnode->arg, fstore->arg, Expr *);
3073  MUTATE(newnode->newvals, fstore->newvals, List *);
3074  newnode->fieldnums = list_copy(fstore->fieldnums);
3075  return (Node *) newnode;
3076  }
3077  break;
3078  case T_RelabelType:
3079  {
3080  RelabelType *relabel = (RelabelType *) node;
3081  RelabelType *newnode;
3082 
3083  FLATCOPY(newnode, relabel, RelabelType);
3084  MUTATE(newnode->arg, relabel->arg, Expr *);
3085  return (Node *) newnode;
3086  }
3087  break;
3088  case T_CoerceViaIO:
3089  {
3090  CoerceViaIO *iocoerce = (CoerceViaIO *) node;
3091  CoerceViaIO *newnode;
3092 
3093  FLATCOPY(newnode, iocoerce, CoerceViaIO);
3094  MUTATE(newnode->arg, iocoerce->arg, Expr *);
3095  return (Node *) newnode;
3096  }
3097  break;
3098  case T_ArrayCoerceExpr:
3099  {
3100  ArrayCoerceExpr *acoerce = (ArrayCoerceExpr *) node;
3101  ArrayCoerceExpr *newnode;
3102 
3103  FLATCOPY(newnode, acoerce, ArrayCoerceExpr);
3104  MUTATE(newnode->arg, acoerce->arg, Expr *);
3105  MUTATE(newnode->elemexpr, acoerce->elemexpr, Expr *);
3106  return (Node *) newnode;
3107  }
3108  break;
3109  case T_ConvertRowtypeExpr:
3110  {
3111  ConvertRowtypeExpr *convexpr = (ConvertRowtypeExpr *) node;
3112  ConvertRowtypeExpr *newnode;
3113 
3114  FLATCOPY(newnode, convexpr, ConvertRowtypeExpr);
3115  MUTATE(newnode->arg, convexpr->arg, Expr *);
3116  return (Node *) newnode;
3117  }
3118  break;
3119  case T_CollateExpr:
3120  {
3121  CollateExpr *collate = (CollateExpr *) node;
3122  CollateExpr *newnode;
3123 
3124  FLATCOPY(newnode, collate, CollateExpr);
3125  MUTATE(newnode->arg, collate->arg, Expr *);
3126  return (Node *) newnode;
3127  }
3128  break;
3129  case T_CaseExpr:
3130  {
3131  CaseExpr *caseexpr = (CaseExpr *) node;
3132  CaseExpr *newnode;
3133 
3134  FLATCOPY(newnode, caseexpr, CaseExpr);
3135  MUTATE(newnode->arg, caseexpr->arg, Expr *);
3136  MUTATE(newnode->args, caseexpr->args, List *);
3137  MUTATE(newnode->defresult, caseexpr->defresult, Expr *);
3138  return (Node *) newnode;
3139  }
3140  break;
3141  case T_CaseWhen:
3142  {
3143  CaseWhen *casewhen = (CaseWhen *) node;
3144  CaseWhen *newnode;
3145 
3146  FLATCOPY(newnode, casewhen, CaseWhen);
3147  MUTATE(newnode->expr, casewhen->expr, Expr *);
3148  MUTATE(newnode->result, casewhen->result, Expr *);
3149  return (Node *) newnode;
3150  }
3151  break;
3152  case T_ArrayExpr:
3153  {
3154  ArrayExpr *arrayexpr = (ArrayExpr *) node;
3155  ArrayExpr *newnode;
3156 
3157  FLATCOPY(newnode, arrayexpr, ArrayExpr);
3158  MUTATE(newnode->elements, arrayexpr->elements, List *);
3159  return (Node *) newnode;
3160  }
3161  break;
3162  case T_RowExpr:
3163  {
3164  RowExpr *rowexpr = (RowExpr *) node;
3165  RowExpr *newnode;
3166 
3167  FLATCOPY(newnode, rowexpr, RowExpr);
3168  MUTATE(newnode->args, rowexpr->args, List *);
3169  /* Assume colnames needn't be duplicated */
3170  return (Node *) newnode;
3171  }
3172  break;
3173  case T_RowCompareExpr:
3174  {
3175  RowCompareExpr *rcexpr = (RowCompareExpr *) node;
3176  RowCompareExpr *newnode;
3177 
3178  FLATCOPY(newnode, rcexpr, RowCompareExpr);
3179  MUTATE(newnode->largs, rcexpr->largs, List *);
3180  MUTATE(newnode->rargs, rcexpr->rargs, List *);
3181  return (Node *) newnode;
3182  }
3183  break;
3184  case T_CoalesceExpr:
3185  {
3186  CoalesceExpr *coalesceexpr = (CoalesceExpr *) node;
3187  CoalesceExpr *newnode;
3188 
3189  FLATCOPY(newnode, coalesceexpr, CoalesceExpr);
3190  MUTATE(newnode->args, coalesceexpr->args, List *);
3191  return (Node *) newnode;
3192  }
3193  break;
3194  case T_MinMaxExpr:
3195  {
3196  MinMaxExpr *minmaxexpr = (MinMaxExpr *) node;
3197  MinMaxExpr *newnode;
3198 
3199  FLATCOPY(newnode, minmaxexpr, MinMaxExpr);
3200  MUTATE(newnode->args, minmaxexpr->args, List *);
3201  return (Node *) newnode;
3202  }
3203  break;
3204  case T_XmlExpr:
3205  {
3206  XmlExpr *xexpr = (XmlExpr *) node;
3207  XmlExpr *newnode;
3208 
3209  FLATCOPY(newnode, xexpr, XmlExpr);
3210  MUTATE(newnode->named_args, xexpr->named_args, List *);
3211  /* assume mutator does not care about arg_names */
3212  MUTATE(newnode->args, xexpr->args, List *);
3213  return (Node *) newnode;
3214  }
3215  break;
3216  case T_JsonReturning:
3217  {
3218  JsonReturning *jr = (JsonReturning *) node;
3219  JsonReturning *newnode;
3220 
3221  FLATCOPY(newnode, jr, JsonReturning);
3222  MUTATE(newnode->format, jr->format, JsonFormat *);
3223 
3224  return (Node *) newnode;
3225  }
3226  case T_JsonValueExpr:
3227  {
3228  JsonValueExpr *jve = (JsonValueExpr *) node;
3229  JsonValueExpr *newnode;
3230 
3231  FLATCOPY(newnode, jve, JsonValueExpr);
3232  MUTATE(newnode->raw_expr, jve->raw_expr, Expr *);
3233  MUTATE(newnode->formatted_expr, jve->formatted_expr, Expr *);
3234  MUTATE(newnode->format, jve->format, JsonFormat *);
3235 
3236  return (Node *) newnode;
3237  }
3238  case T_JsonConstructorExpr:
3239  {
3240  JsonConstructorExpr *jce = (JsonConstructorExpr *) node;
3241  JsonConstructorExpr *newnode;
3242 
3243  FLATCOPY(newnode, jce, JsonConstructorExpr);
3244  MUTATE(newnode->args, jce->args, List *);
3245  MUTATE(newnode->func, jce->func, Expr *);
3246  MUTATE(newnode->coercion, jce->coercion, Expr *);
3247  MUTATE(newnode->returning, jce->returning, JsonReturning *);
3248 
3249  return (Node *) newnode;
3250  }
3251  case T_JsonIsPredicate:
3252  {
3253  JsonIsPredicate *pred = (JsonIsPredicate *) node;
3254  JsonIsPredicate *newnode;
3255 
3256  FLATCOPY(newnode, pred, JsonIsPredicate);
3257  MUTATE(newnode->expr, pred->expr, Node *);
3258  MUTATE(newnode->format, pred->format, JsonFormat *);
3259 
3260  return (Node *) newnode;
3261  }
3262  case T_NullTest:
3263  {
3264  NullTest *ntest = (NullTest *) node;
3265  NullTest *newnode;
3266 
3267  FLATCOPY(newnode, ntest, NullTest);
3268  MUTATE(newnode->arg, ntest->arg, Expr *);
3269  return (Node *) newnode;
3270  }
3271  break;
3272  case T_BooleanTest:
3273  {
3274  BooleanTest *btest = (BooleanTest *) node;
3275  BooleanTest *newnode;
3276 
3277  FLATCOPY(newnode, btest, BooleanTest);
3278  MUTATE(newnode->arg, btest->arg, Expr *);
3279  return (Node *) newnode;
3280  }
3281  break;
3282  case T_CoerceToDomain:
3283  {
3284  CoerceToDomain *ctest = (CoerceToDomain *) node;
3285  CoerceToDomain *newnode;
3286 
3287  FLATCOPY(newnode, ctest, CoerceToDomain);
3288  MUTATE(newnode->arg, ctest->arg, Expr *);
3289  return (Node *) newnode;
3290  }
3291  break;
3292  case T_TargetEntry:
3293  {
3294  TargetEntry *targetentry = (TargetEntry *) node;
3295  TargetEntry *newnode;
3296 
3297  FLATCOPY(newnode, targetentry, TargetEntry);
3298  MUTATE(newnode->expr, targetentry->expr, Expr *);
3299  return (Node *) newnode;
3300  }
3301  break;
3302  case T_Query:
3303  /* Do nothing with a sub-Query, per discussion above */
3304  return node;
3305  case T_WindowClause:
3306  {
3307  WindowClause *wc = (WindowClause *) node;
3308  WindowClause *newnode;
3309 
3310  FLATCOPY(newnode, wc, WindowClause);
3311  MUTATE(newnode->partitionClause, wc->partitionClause, List *);
3312  MUTATE(newnode->orderClause, wc->orderClause, List *);
3313  MUTATE(newnode->startOffset, wc->startOffset, Node *);
3314  MUTATE(newnode->endOffset, wc->endOffset, Node *);
3315  return (Node *) newnode;
3316  }
3317  break;
3318  case T_CTECycleClause:
3319  {
3320  CTECycleClause *cc = (CTECycleClause *) node;
3321  CTECycleClause *newnode;
3322 
3323  FLATCOPY(newnode, cc, CTECycleClause);
3324  MUTATE(newnode->cycle_mark_value, cc->cycle_mark_value, Node *);
3326  return (Node *) newnode;
3327  }
3328  break;
3329  case T_CommonTableExpr:
3330  {
3331  CommonTableExpr *cte = (CommonTableExpr *) node;
3332  CommonTableExpr *newnode;
3333 
3334  FLATCOPY(newnode, cte, CommonTableExpr);
3335 
3336  /*
3337  * Also invoke the mutator on the CTE's Query node, so it can
3338  * recurse into the sub-query if it wants to.
3339  */
3340  MUTATE(newnode->ctequery, cte->ctequery, Node *);
3341 
3342  MUTATE(newnode->search_clause, cte->search_clause, CTESearchClause *);
3343  MUTATE(newnode->cycle_clause, cte->cycle_clause, CTECycleClause *);
3344 
3345  return (Node *) newnode;
3346  }
3347  break;
3348  case T_PartitionBoundSpec:
3349  {
3350  PartitionBoundSpec *pbs = (PartitionBoundSpec *) node;
3351  PartitionBoundSpec *newnode;
3352 
3353  FLATCOPY(newnode, pbs, PartitionBoundSpec);
3354  MUTATE(newnode->listdatums, pbs->listdatums, List *);
3355  MUTATE(newnode->lowerdatums, pbs->lowerdatums, List *);
3356  MUTATE(newnode->upperdatums, pbs->upperdatums, List *);
3357  return (Node *) newnode;
3358  }
3359  break;
3360  case T_PartitionRangeDatum:
3361  {
3362  PartitionRangeDatum *prd = (PartitionRangeDatum *) node;
3363  PartitionRangeDatum *newnode;
3364 
3365  FLATCOPY(newnode, prd, PartitionRangeDatum);
3366  MUTATE(newnode->value, prd->value, Node *);
3367  return (Node *) newnode;
3368  }
3369  break;
3370  case T_List:
3371  {
3372  /*
3373  * We assume the mutator isn't interested in the list nodes
3374  * per se, so just invoke it on each list element. NOTE: this
3375  * would fail badly on a list with integer elements!
3376  */
3377  List *resultlist;
3378  ListCell *temp;
3379 
3380  resultlist = NIL;
3381  foreach(temp, (List *) node)
3382  {
3383  resultlist = lappend(resultlist,
3384  mutator((Node *) lfirst(temp),
3385  context));
3386  }
3387  return (Node *) resultlist;
3388  }
3389  break;
3390  case T_FromExpr:
3391  {
3392  FromExpr *from = (FromExpr *) node;
3393  FromExpr *newnode;
3394 
3395  FLATCOPY(newnode, from, FromExpr);
3396  MUTATE(newnode->fromlist, from->fromlist, List *);
3397  MUTATE(newnode->quals, from->quals, Node *);
3398  return (Node *) newnode;
3399  }
3400  break;
3401  case T_OnConflictExpr:
3402  {
3403  OnConflictExpr *oc = (OnConflictExpr *) node;
3404  OnConflictExpr *newnode;
3405 
3406  FLATCOPY(newnode, oc, OnConflictExpr);
3407  MUTATE(newnode->arbiterElems, oc->arbiterElems, List *);
3408  MUTATE(newnode->arbiterWhere, oc->arbiterWhere, Node *);
3409  MUTATE(newnode->onConflictSet, oc->onConflictSet, List *);
3410  MUTATE(newnode->onConflictWhere, oc->onConflictWhere, Node *);
3411  MUTATE(newnode->exclRelTlist, oc->exclRelTlist, List *);
3412 
3413  return (Node *) newnode;
3414  }
3415  break;
3416  case T_MergeAction:
3417  {
3418  MergeAction *action = (MergeAction *) node;
3419  MergeAction *newnode;
3420 
3421  FLATCOPY(newnode, action, MergeAction);
3422  MUTATE(newnode->qual, action->qual, Node *);
3423  MUTATE(newnode->targetList, action->targetList, List *);
3424 
3425  return (Node *) newnode;
3426  }
3427  break;
3428  case T_PartitionPruneStepOp:
3429  {
3430  PartitionPruneStepOp *opstep = (PartitionPruneStepOp *) node;
3431  PartitionPruneStepOp *newnode;
3432 
3433  FLATCOPY(newnode, opstep, PartitionPruneStepOp);
3434  MUTATE(newnode->exprs, opstep->exprs, List *);
3435 
3436  return (Node *) newnode;
3437  }
3438  break;
3439  case T_PartitionPruneStepCombine:
3440  /* no expression sub-nodes */
3441  return (Node *) copyObject(node);
3442  case T_JoinExpr:
3443  {
3444  JoinExpr *join = (JoinExpr *) node;
3445  JoinExpr *newnode;
3446 
3447  FLATCOPY(newnode, join, JoinExpr);
3448  MUTATE(newnode->larg, join->larg, Node *);
3449  MUTATE(newnode->rarg, join->rarg, Node *);
3450  MUTATE(newnode->quals, join->quals, Node *);
3451  /* We do not mutate alias or using by default */
3452  return (Node *) newnode;
3453  }
3454  break;
3455  case T_SetOperationStmt:
3456  {
3457  SetOperationStmt *setop = (SetOperationStmt *) node;
3458  SetOperationStmt *newnode;
3459 
3460  FLATCOPY(newnode, setop, SetOperationStmt);
3461  MUTATE(newnode->larg, setop->larg, Node *);
3462  MUTATE(newnode->rarg, setop->rarg, Node *);
3463  /* We do not mutate groupClauses by default */
3464  return (Node *) newnode;
3465  }
3466  break;
3467  case T_IndexClause:
3468  {
3469  IndexClause *iclause = (IndexClause *) node;
3470  IndexClause *newnode;
3471 
3472  FLATCOPY(newnode, iclause, IndexClause);
3473  MUTATE(newnode->rinfo, iclause->rinfo, RestrictInfo *);
3474  MUTATE(newnode->indexquals, iclause->indexquals, List *);
3475  return (Node *) newnode;
3476  }
3477  break;
3478  case T_PlaceHolderVar:
3479  {
3480  PlaceHolderVar *phv = (PlaceHolderVar *) node;
3481  PlaceHolderVar *newnode;
3482 
3483  FLATCOPY(newnode, phv, PlaceHolderVar);
3484  MUTATE(newnode->phexpr, phv->phexpr, Expr *);
3485  /* Assume we need not copy the relids bitmapsets */
3486  return (Node *) newnode;
3487  }
3488  break;
3489  case T_InferenceElem:
3490  {
3491  InferenceElem *inferenceelemdexpr = (InferenceElem *) node;
3492  InferenceElem *newnode;
3493 
3494  FLATCOPY(newnode, inferenceelemdexpr, InferenceElem);
3495  MUTATE(newnode->expr, newnode->expr, Node *);
3496  return (Node *) newnode;
3497  }
3498  break;
3499  case T_AppendRelInfo:
3500  {
3501  AppendRelInfo *appinfo = (AppendRelInfo *) node;
3502  AppendRelInfo *newnode;
3503 
3504  FLATCOPY(newnode, appinfo, AppendRelInfo);
3505  MUTATE(newnode->translated_vars, appinfo->translated_vars, List *);
3506  /* Assume nothing need be done with parent_colnos[] */
3507  return (Node *) newnode;
3508  }
3509  break;
3510  case T_PlaceHolderInfo:
3511  {
3512  PlaceHolderInfo *phinfo = (PlaceHolderInfo *) node;
3513  PlaceHolderInfo *newnode;
3514 
3515  FLATCOPY(newnode, phinfo, PlaceHolderInfo);
3516  MUTATE(newnode->ph_var, phinfo->ph_var, PlaceHolderVar *);
3517  /* Assume we need not copy the relids bitmapsets */
3518  return (Node *) newnode;
3519  }
3520  break;
3521  case T_RangeTblFunction:
3522  {
3523  RangeTblFunction *rtfunc = (RangeTblFunction *) node;
3524  RangeTblFunction *newnode;
3525 
3526  FLATCOPY(newnode, rtfunc, RangeTblFunction);
3527  MUTATE(newnode->funcexpr, rtfunc->funcexpr, Node *);
3528  /* Assume we need not copy the coldef info lists */
3529  return (Node *) newnode;
3530  }
3531  break;
3532  case T_TableSampleClause:
3533  {
3534  TableSampleClause *tsc = (TableSampleClause *) node;
3535  TableSampleClause *newnode;
3536 
3537  FLATCOPY(newnode, tsc, TableSampleClause);
3538  MUTATE(newnode->args, tsc->args, List *);
3539  MUTATE(newnode->repeatable, tsc->repeatable, Expr *);
3540  return (Node *) newnode;
3541  }
3542  break;
3543  case T_TableFunc:
3544  {
3545  TableFunc *tf = (TableFunc *) node;
3546  TableFunc *newnode;
3547 
3548  FLATCOPY(newnode, tf, TableFunc);
3549  MUTATE(newnode->ns_uris, tf->ns_uris, List *);
3550  MUTATE(newnode->docexpr, tf->docexpr, Node *);
3551  MUTATE(newnode->rowexpr, tf->rowexpr, Node *);
3552  MUTATE(newnode->colexprs, tf->colexprs, List *);
3553  MUTATE(newnode->coldefexprs, tf->coldefexprs, List *);
3554  return (Node *) newnode;
3555  }
3556  break;
3557  default:
3558  elog(ERROR, "unrecognized node type: %d",
3559  (int) nodeTag(node));
3560  break;
3561  }
3562  /* can't get here, but keep compiler happy */
3563  return NULL;
3564 }
List * lappend(List *list, void *datum)
Definition: list.c:338
List * list_copy(const List *oldlist)
Definition: list.c:1572
#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:3520
List * aggdistinct
Definition: primnodes.h:460
List * aggdirectargs
Definition: primnodes.h:451
List * args
Definition: primnodes.h:454
Expr * aggfilter
Definition: primnodes.h:463
List * aggorder
Definition: primnodes.h:457
List * translated_vars
Definition: pathnodes.h:2956
List * elements
Definition: primnodes.h:1315
List * args
Definition: primnodes.h:875
Expr * arg
Definition: primnodes.h:1724
Node * cycle_mark_default
Definition: parsenodes.h:1606
Node * cycle_mark_value
Definition: parsenodes.h:1605
Expr * arg
Definition: primnodes.h:1248
Expr * defresult
Definition: primnodes.h:1250
List * args
Definition: primnodes.h:1249
Expr * result
Definition: primnodes.h:1261
Expr * expr
Definition: primnodes.h:1260
List * args
Definition: primnodes.h:1427
Expr * arg
Definition: primnodes.h:1214
Expr * arg
Definition: primnodes.h:1063
List * newvals
Definition: primnodes.h:1095
Expr * arg
Definition: primnodes.h:1094
Node * quals
Definition: primnodes.h:2041
List * fromlist
Definition: primnodes.h:2040
List * args
Definition: primnodes.h:703
List * indexquals
Definition: pathnodes.h:1727
struct RestrictInfo * rinfo
Definition: pathnodes.h:1726
Node * quals
Definition: primnodes.h:2021
Node * larg
Definition: primnodes.h:2014
Node * rarg
Definition: primnodes.h:2015
JsonReturning * returning
Definition: primnodes.h:1641
JsonFormat * format
Definition: primnodes.h:1667
JsonFormat * format
Definition: primnodes.h:1598
Expr * formatted_expr
Definition: primnodes.h:1615
JsonFormat * format
Definition: primnodes.h:1616
Expr * raw_expr
Definition: primnodes.h:1614
Definition: pg_list.h:54
Node * qual
Definition: primnodes.h:1742
List * targetList
Definition: primnodes.h:1743
List * args
Definition: primnodes.h:1453
Expr * arg
Definition: primnodes.h:726
Expr * arg
Definition: primnodes.h:1700
List * arbiterElems
Definition: primnodes.h:2059
List * onConflictSet
Definition: primnodes.h:2065
List * exclRelTlist
Definition: primnodes.h:2068
Node * onConflictWhere
Definition: primnodes.h:2066
Node * arbiterWhere
Definition: primnodes.h:2061
List * args
Definition: primnodes.h:771
PlaceHolderVar * ph_var
Definition: pathnodes.h:3044
List * args
Definition: primnodes.h:1346
List * args
Definition: primnodes.h:1026
Node * testexpr
Definition: primnodes.h:1002
Expr * refassgnexpr
Definition: primnodes.h:638
List * refupperindexpr
Definition: primnodes.h:628
Expr * refexpr
Definition: primnodes.h:636
List * reflowerindexpr
Definition: primnodes.h:634
Node * docexpr
Definition: primnodes.h:111
Node * rowexpr
Definition: primnodes.h:113
List * colexprs
Definition: primnodes.h:123
Expr * expr
Definition: primnodes.h:1922
Node * startOffset
Definition: parsenodes.h:1493
List * partitionClause
Definition: parsenodes.h:1489
Node * endOffset
Definition: parsenodes.h:1494
List * orderClause
Definition: parsenodes.h:1491
List * args
Definition: primnodes.h:561
Expr * aggfilter
Definition: primnodes.h:563
List * args
Definition: primnodes.h:1543
List * named_args
Definition: primnodes.h:1539

References generate_unaccent_rules::action, Aggref::aggdirectargs, Aggref::aggdistinct, Aggref::aggfilter, WindowFunc::aggfilter, Aggref::aggorder, OnConflictExpr::arbiterElems, OnConflictExpr::arbiterWhere, NamedArgExpr::arg, FieldSelect::arg, FieldStore::arg, RelabelType::arg, CoerceViaIO::arg, ArrayCoerceExpr::arg, ConvertRowtypeExpr::arg, CollateExpr::arg, CaseExpr::arg, NullTest::arg, BooleanTest::arg, CoerceToDomain::arg, TableSampleClause::args, Aggref::args, WindowFunc::args, FuncExpr::args, OpExpr::args, ScalarArrayOpExpr::args, BoolExpr::args, SubPlan::args, CaseExpr::args, RowExpr::args, CoalesceExpr::args, MinMaxExpr::args, XmlExpr::args, JsonConstructorExpr::args, check_stack_depth(), JsonConstructorExpr::coercion, TableFunc::colexprs, 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, InferenceElem::expr, TargetEntry::expr, PartitionPruneStepOp::exprs, FLATCOPY, JsonReturning::format, JsonValueExpr::format, JsonIsPredicate::format, JsonValueExpr::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, OnConflictExpr::onConflictSet, OnConflictExpr::onConflictWhere, WindowClause::orderClause, WindowClause::partitionClause, 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 2000 of file nodeFuncs.c.

2003 {
2004  ListCell *temp;
2005 
2006  /*
2007  * The walker has already visited the current node, and so we need only
2008  * recurse into any sub-nodes it has.
2009  *
2010  * We assume that the walker is not interested in List nodes per se, so
2011  * when we expect a List we just recurse directly to self without
2012  * bothering to call the walker.
2013  */
2014 #define WALK(n) walker((Node *) (n), context)
2015 
2016 #define LIST_WALK(l) expression_tree_walker_impl((Node *) (l), walker, context)
2017 
2018  if (node == NULL)
2019  return false;
2020 
2021  /* Guard against stack overflow due to overly complex expressions */
2023 
2024  switch (nodeTag(node))
2025  {
2026  case T_Var:
2027  case T_Const:
2028  case T_Param:
2029  case T_CaseTestExpr:
2030  case T_SQLValueFunction:
2031  case T_CoerceToDomainValue:
2032  case T_SetToDefault:
2033  case T_CurrentOfExpr:
2034  case T_NextValueExpr:
2035  case T_RangeTblRef:
2036  case T_SortGroupClause:
2037  case T_CTESearchClause:
2038  /* primitive node types with no expression subnodes */
2039  break;
2040  case T_WithCheckOption:
2041  return WALK(((WithCheckOption *) node)->qual);
2042  case T_Aggref:
2043  {
2044  Aggref *expr = (Aggref *) node;
2045 
2046  /* recurse directly on Lists */
2047  if (LIST_WALK(expr->aggdirectargs))
2048  return true;
2049  if (LIST_WALK(expr->args))
2050  return true;
2051  if (LIST_WALK(expr->aggorder))
2052  return true;
2053  if (LIST_WALK(expr->aggdistinct))
2054  return true;
2055  if (WALK(expr->aggfilter))
2056  return true;
2057  }
2058  break;
2059  case T_GroupingFunc:
2060  {
2061  GroupingFunc *grouping = (GroupingFunc *) node;
2062 
2063  if (LIST_WALK(grouping->args))
2064  return true;
2065  }
2066  break;
2067  case T_WindowFunc:
2068  {
2069  WindowFunc *expr = (WindowFunc *) node;
2070 
2071  /* recurse directly on List */
2072  if (LIST_WALK(expr->args))
2073  return true;
2074  if (WALK(expr->aggfilter))
2075  return true;
2076  }
2077  break;
2078  case T_SubscriptingRef:
2079  {
2080  SubscriptingRef *sbsref = (SubscriptingRef *) node;
2081 
2082  /* recurse directly for upper/lower container index lists */
2083  if (LIST_WALK(sbsref->refupperindexpr))
2084  return true;
2085  if (LIST_WALK(sbsref->reflowerindexpr))
2086  return true;
2087  /* walker must see the refexpr and refassgnexpr, however */
2088  if (WALK(sbsref->refexpr))
2089  return true;
2090 
2091  if (WALK(sbsref->refassgnexpr))
2092  return true;
2093  }
2094  break;
2095  case T_FuncExpr:
2096  {
2097  FuncExpr *expr = (FuncExpr *) node;
2098 
2099  if (LIST_WALK(expr->args))
2100  return true;
2101  }
2102  break;
2103  case T_NamedArgExpr:
2104  return WALK(((NamedArgExpr *) node)->arg);
2105  case T_OpExpr:
2106  case T_DistinctExpr: /* struct-equivalent to OpExpr */
2107  case T_NullIfExpr: /* struct-equivalent to OpExpr */
2108  {
2109  OpExpr *expr = (OpExpr *) node;
2110 
2111  if (LIST_WALK(expr->args))
2112  return true;
2113  }
2114  break;
2115  case T_ScalarArrayOpExpr:
2116  {
2117  ScalarArrayOpExpr *expr = (ScalarArrayOpExpr *) node;
2118 
2119  if (LIST_WALK(expr->args))
2120  return true;
2121  }
2122  break;
2123  case T_BoolExpr:
2124  {
2125  BoolExpr *expr = (BoolExpr *) node;
2126 
2127  if (LIST_WALK(expr->args))
2128  return true;
2129  }
2130  break;
2131  case T_SubLink:
2132  {
2133  SubLink *sublink = (SubLink *) node;
2134 
2135  if (WALK(sublink->testexpr))
2136  return true;
2137 
2138  /*
2139  * Also invoke the walker on the sublink's Query node, so it
2140  * can recurse into the sub-query if it wants to.
2141  */
2142  return WALK(sublink->subselect);
2143  }
2144  break;
2145  case T_SubPlan:
2146  {
2147  SubPlan *subplan = (SubPlan *) node;
2148 
2149  /* recurse into the testexpr, but not into the Plan */
2150  if (WALK(subplan->testexpr))
2151  return true;
2152  /* also examine args list */
2153  if (LIST_WALK(subplan->args))
2154  return true;
2155  }
2156  break;
2157  case T_AlternativeSubPlan:
2158  return LIST_WALK(((AlternativeSubPlan *) node)->subplans);
2159  case T_FieldSelect:
2160  return WALK(((FieldSelect *) node)->arg);
2161  case T_FieldStore:
2162  {
2163  FieldStore *fstore = (FieldStore *) node;
2164 
2165  if (WALK(fstore->arg))
2166  return true;
2167  if (WALK(fstore->newvals))
2168  return true;
2169  }
2170  break;
2171  case T_RelabelType:
2172  return WALK(((RelabelType *) node)->arg);
2173  case T_CoerceViaIO:
2174  return WALK(((CoerceViaIO *) node)->arg);
2175  case T_ArrayCoerceExpr:
2176  {
2177  ArrayCoerceExpr *acoerce = (ArrayCoerceExpr *) node;
2178 
2179  if (WALK(acoerce->arg))
2180  return true;
2181  if (WALK(acoerce->elemexpr))
2182  return true;
2183  }
2184  break;
2185  case T_ConvertRowtypeExpr:
2186  return WALK(((ConvertRowtypeExpr *) node)->arg);
2187  case T_CollateExpr:
2188  return WALK(((CollateExpr *) node)->arg);
2189  case T_CaseExpr:
2190  {
2191  CaseExpr *caseexpr = (CaseExpr *) node;
2192 
2193  if (WALK(caseexpr->arg))
2194  return true;
2195  /* we assume walker doesn't care about CaseWhens, either */
2196  foreach(temp, caseexpr->args)
2197  {
2198  CaseWhen *when = lfirst_node(CaseWhen, temp);
2199 
2200  if (WALK(when->expr))
2201  return true;
2202  if (WALK(when->result))
2203  return true;
2204  }
2205  if (WALK(caseexpr->defresult))
2206  return true;
2207  }
2208  break;
2209  case T_ArrayExpr:
2210  return WALK(((ArrayExpr *) node)->elements);
2211  case T_RowExpr:
2212  /* Assume colnames isn't interesting */
2213  return WALK(((RowExpr *) node)->args);
2214  case T_RowCompareExpr:
2215  {
2216  RowCompareExpr *rcexpr = (RowCompareExpr *) node;
2217 
2218  if (WALK(rcexpr->largs))
2219  return true;
2220  if (WALK(rcexpr->rargs))
2221  return true;
2222  }
2223  break;
2224  case T_CoalesceExpr:
2225  return WALK(((CoalesceExpr *) node)->args);
2226  case T_MinMaxExpr:
2227  return WALK(((MinMaxExpr *) node)->args);
2228  case T_XmlExpr:
2229  {
2230  XmlExpr *xexpr = (XmlExpr *) node;
2231 
2232  if (WALK(xexpr->named_args))
2233  return true;
2234  /* we assume walker doesn't care about arg_names */
2235  if (WALK(xexpr->args))
2236  return true;
2237  }
2238  break;
2239  case T_JsonValueExpr:
2240  {
2241  JsonValueExpr *jve = (JsonValueExpr *) node;
2242 
2243  if (WALK(jve->raw_expr))
2244  return true;
2245  if (WALK(jve->formatted_expr))
2246  return true;
2247  }
2248  break;
2249  case T_JsonConstructorExpr:
2250  {
2251  JsonConstructorExpr *ctor = (JsonConstructorExpr *) node;
2252 
2253  if (WALK(ctor->args))
2254  return true;
2255  if (WALK(ctor->func))
2256  return true;
2257  if (WALK(ctor->coercion))
2258  return true;
2259  }
2260  break;
2261  case T_JsonIsPredicate:
2262  return WALK(((JsonIsPredicate *) node)->expr);
2263  case T_NullTest:
2264  return WALK(((NullTest *) node)->arg);
2265  case T_BooleanTest:
2266  return WALK(((BooleanTest *) node)->arg);
2267  case T_CoerceToDomain:
2268  return WALK(((CoerceToDomain *) node)->arg);
2269  case T_TargetEntry:
2270  return WALK(((TargetEntry *) node)->expr);
2271  case T_Query:
2272  /* Do nothing with a sub-Query, per discussion above */
2273  break;
2274  case T_WindowClause:
2275  {
2276  WindowClause *wc = (WindowClause *) node;
2277 
2278  if (WALK(wc->partitionClause))
2279  return true;
2280  if (WALK(wc->orderClause))
2281  return true;
2282  if (WALK(wc->startOffset))
2283  return true;
2284  if (WALK(wc->endOffset))
2285  return true;
2286  }
2287  break;
2288  case T_CTECycleClause:
2289  {
2290  CTECycleClause *cc = (CTECycleClause *) node;
2291 
2292  if (WALK(cc->cycle_mark_value))
2293  return true;
2294  if (WALK(cc->cycle_mark_default))
2295  return true;
2296  }
2297  break;
2298  case T_CommonTableExpr:
2299  {
2300  CommonTableExpr *cte = (CommonTableExpr *) node;
2301 
2302  /*
2303  * Invoke the walker on the CTE's Query node, so it can
2304  * recurse into the sub-query if it wants to.
2305  */
2306  if (WALK(cte->ctequery))
2307  return true;
2308 
2309  if (WALK(cte->search_clause))
2310  return true;
2311  if (WALK(cte->cycle_clause))
2312  return true;
2313  }
2314  break;
2315  case T_JsonKeyValue:
2316  {
2317  JsonKeyValue *kv = (JsonKeyValue *) node;
2318 
2319  if (WALK(kv->key))
2320  return true;
2321  if (WALK(kv->value))
2322  return true;
2323  }
2324  break;
2325  case T_JsonObjectConstructor:
2326  {
2328 
2329  if (LIST_WALK(ctor->exprs))
2330  return true;
2331  }
2332  break;
2333  case T_JsonArrayConstructor:
2334  {
2335  JsonArrayConstructor *ctor = (JsonArrayConstructor *) node;
2336 
2337  if (LIST_WALK(ctor->exprs))
2338  return true;
2339  }
2340  break;
2341  case T_JsonArrayQueryConstructor:
2342  {
2344 
2345  if (WALK(ctor->query))
2346  return true;
2347  }
2348  break;
2349  case T_JsonAggConstructor:
2350  {
2351  JsonAggConstructor *ctor = (JsonAggConstructor *) node;
2352 
2353  if (WALK(ctor->agg_filter))
2354  return true;
2355  if (WALK(ctor->agg_order))
2356  return true;
2357  if (WALK(ctor->over))
2358  return true;
2359  }
2360  break;
2361  case T_JsonObjectAgg:
2362  {
2363  JsonObjectAgg *ctor = (JsonObjectAgg *) node;
2364 
2365  if (WALK(ctor->constructor))
2366  return true;
2367  if (WALK(ctor->arg))
2368  return true;
2369  }
2370  break;
2371  case T_JsonArrayAgg:
2372  {
2373  JsonArrayAgg *ctor = (JsonArrayAgg *) node;
2374 
2375  if (WALK(ctor->constructor))
2376  return true;
2377  if (WALK(ctor->arg))
2378  return true;
2379  }
2380  break;
2381 
2382  case T_PartitionBoundSpec:
2383  {
2384  PartitionBoundSpec *pbs = (PartitionBoundSpec *) node;
2385 
2386  if (WALK(pbs->listdatums))
2387  return true;
2388  if (WALK(pbs->lowerdatums))
2389  return true;
2390  if (WALK(pbs->upperdatums))
2391  return true;
2392  }
2393  break;
2394  case T_PartitionRangeDatum:
2395  {
2396  PartitionRangeDatum *prd = (PartitionRangeDatum *) node;
2397 
2398  if (WALK(prd->value))
2399  return true;
2400  }
2401  break;
2402  case T_List:
2403  foreach(temp, (List *) node)
2404  {
2405  if (WALK(lfirst(temp)))
2406  return true;
2407  }
2408  break;
2409  case T_FromExpr:
2410  {
2411  FromExpr *from = (FromExpr *) node;
2412 
2413  if (LIST_WALK(from->fromlist))
2414  return true;
2415  if (WALK(from->quals))
2416  return true;
2417  }
2418  break;
2419  case T_OnConflictExpr:
2420  {
2421  OnConflictExpr *onconflict = (OnConflictExpr *) node;
2422 
2423  if (WALK(onconflict->arbiterElems))
2424  return true;
2425  if (WALK(onconflict->arbiterWhere))
2426  return true;
2427  if (WALK(onconflict->onConflictSet))
2428  return true;
2429  if (WALK(onconflict->onConflictWhere))
2430  return true;
2431  if (WALK(onconflict->exclRelTlist))
2432  return true;
2433  }
2434  break;
2435  case T_MergeAction:
2436  {
2437  MergeAction *action = (MergeAction *) node;
2438 
2439  if (WALK(action->qual))
2440  return true;
2441  if (WALK(action->targetList))
2442  return true;
2443  }
2444  break;
2445  case T_PartitionPruneStepOp:
2446  {
2447  PartitionPruneStepOp *opstep = (PartitionPruneStepOp *) node;
2448 
2449  if (WALK(opstep->exprs))
2450  return true;
2451  }
2452  break;
2453  case T_PartitionPruneStepCombine:
2454  /* no expression subnodes */
2455  break;
2456  case T_JoinExpr:
2457  {
2458  JoinExpr *join = (JoinExpr *) node;
2459 
2460  if (WALK(join->larg))
2461  return true;
2462  if (WALK(join->rarg))
2463  return true;
2464  if (WALK(join->quals))
2465  return true;
2466 
2467  /*
2468  * alias clause, using list are deemed uninteresting.
2469  */
2470  }
2471  break;
2472  case T_SetOperationStmt:
2473  {
2474  SetOperationStmt *setop = (SetOperationStmt *) node;
2475 
2476  if (WALK(setop->larg))
2477  return true;
2478  if (WALK(setop->rarg))
2479  return true;
2480 
2481  /* groupClauses are deemed uninteresting */
2482  }
2483  break;
2484  case T_IndexClause:
2485  {
2486  IndexClause *iclause = (IndexClause *) node;
2487 
2488  if (WALK(iclause->rinfo))
2489  return true;
2490  if (LIST_WALK(iclause->indexquals))
2491  return true;
2492  }
2493  break;
2494  case T_PlaceHolderVar:
2495  return WALK(((PlaceHolderVar *) node)->phexpr);
2496  case T_InferenceElem:
2497  return WALK(((InferenceElem *) node)->expr);
2498  case T_AppendRelInfo:
2499  {
2500  AppendRelInfo *appinfo = (AppendRelInfo *) node;
2501 
2502  if (LIST_WALK(appinfo->translated_vars))
2503  return true;
2504  }
2505  break;
2506  case T_PlaceHolderInfo:
2507  return WALK(((PlaceHolderInfo *) node)->ph_var);
2508  case T_RangeTblFunction:
2509  return WALK(((RangeTblFunction *) node)->funcexpr);
2510  case T_TableSampleClause:
2511  {
2512  TableSampleClause *tsc = (TableSampleClause *) node;
2513 
2514  if (LIST_WALK(tsc->args))
2515  return true;
2516  if (WALK(tsc->repeatable))
2517  return true;
2518  }
2519  break;
2520  case T_TableFunc:
2521  {
2522  TableFunc *tf = (TableFunc *) node;
2523 
2524  if (WALK(tf->ns_uris))
2525  return true;
2526  if (WALK(tf->docexpr))
2527  return true;
2528  if (WALK(tf->rowexpr))
2529  return true;
2530  if (WALK(tf->colexprs))
2531  return true;
2532  if (WALK(tf->coldefexprs))
2533  return true;
2534  }
2535  break;
2536  default:
2537  elog(ERROR, "unrecognized node type: %d",
2538  (int) nodeTag(node));
2539  break;
2540  }
2541  return false;
2542 
2543  /* The WALK() macro can be re-used below, but LIST_WALK() not so much */
2544 #undef LIST_WALK
2545 }
#define LIST_WALK(l)
#define WALK(n)
#define lfirst_node(type, lc)
Definition: pg_list.h:176
struct WindowDef * over
Definition: parsenodes.h:1807
JsonValueExpr * arg
Definition: parsenodes.h:1832
JsonAggConstructor * constructor
Definition: parsenodes.h:1831
JsonValueExpr * value
Definition: parsenodes.h:1715
JsonAggConstructor * constructor
Definition: parsenodes.h:1818
JsonKeyValue * arg
Definition: parsenodes.h:1819
Definition: type.h:88

References generate_unaccent_rules::action, JsonAggConstructor::agg_filter, JsonAggConstructor::agg_order, Aggref::aggdirectargs, Aggref::aggdistinct, Aggref::aggfilter, WindowFunc::aggfilter, Aggref::aggorder, OnConflictExpr::arbiterElems, OnConflictExpr::arbiterWhere, arg, JsonObjectAgg::arg, JsonArrayAgg::arg, FieldStore::arg, ArrayCoerceExpr::arg, CaseExpr::arg, generate_unaccent_rules::args, TableSampleClause::args, Aggref::args, WindowFunc::args, FuncExpr::args, OpExpr::args, ScalarArrayOpExpr::args, BoolExpr::args, SubPlan::args, CaseExpr::args, XmlExpr::args, JsonConstructorExpr::args, check_stack_depth(), JsonConstructorExpr::coercion, 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, JsonObjectConstructor::exprs, JsonArrayConstructor::exprs, PartitionPruneStepOp::exprs, JsonValueExpr::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, OnConflictExpr::onConflictSet, OnConflictExpr::onConflictWhere, WindowClause::orderClause, JsonAggConstructor::over, WindowClause::partitionClause, 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 1018 of file nodeFuncs.c.

1019 {
1020  Oid coll;
1021 
1022  if (!expr)
1023  return InvalidOid;
1024 
1025  switch (nodeTag(expr))
1026  {
1027  case T_Aggref:
1028  coll = ((const Aggref *) expr)->inputcollid;
1029  break;
1030  case T_WindowFunc:
1031  coll = ((const WindowFunc *) expr)->inputcollid;
1032  break;
1033  case T_FuncExpr:
1034  coll = ((const FuncExpr *) expr)->inputcollid;
1035  break;
1036  case T_OpExpr:
1037  coll = ((const OpExpr *) expr)->inputcollid;
1038  break;
1039  case T_DistinctExpr:
1040  coll = ((const DistinctExpr *) expr)->inputcollid;
1041  break;
1042  case T_NullIfExpr:
1043  coll = ((const NullIfExpr *) expr)->inputcollid;
1044  break;
1045  case T_ScalarArrayOpExpr:
1046  coll = ((const ScalarArrayOpExpr *) expr)->inputcollid;
1047  break;
1048  case T_MinMaxExpr:
1049  coll = ((const MinMaxExpr *) expr)->inputcollid;
1050  break;
1051  default:
1052  coll = InvalidOid;
1053  break;
1054  }
1055  return coll;
1056 }

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

523 {
524  if (coercedTypmod != NULL)
525  *coercedTypmod = -1; /* default result on failure */
526 
527  /*
528  * Scalar-type length coercions are FuncExprs, array-type length coercions
529  * are ArrayCoerceExprs
530  */
531  if (expr && IsA(expr, FuncExpr))
532  {
533  const FuncExpr *func = (const FuncExpr *) expr;
534  int nargs;
535  Const *second_arg;
536 
537  /*
538  * If it didn't come from a coercion context, reject.
539  */
540  if (func->funcformat != COERCE_EXPLICIT_CAST &&
541  func->funcformat != COERCE_IMPLICIT_CAST)
542  return false;
543 
544  /*
545  * If it's not a two-argument or three-argument function with the
546  * second argument being an int4 constant, it can't have been created
547  * from a length coercion (it must be a type coercion, instead).
548  */
549  nargs = list_length(func->args);
550  if (nargs < 2 || nargs > 3)
551  return false;
552 
553  second_arg = (Const *) lsecond(func->args);
554  if (!IsA(second_arg, Const) ||
555  second_arg->consttype != INT4OID ||
556  second_arg->constisnull)
557  return false;
558 
559  /*
560  * OK, it is indeed a length-coercion function.
561  */
562  if (coercedTypmod != NULL)
563  *coercedTypmod = DatumGetInt32(second_arg->constvalue);
564 
565  return true;
566  }
567 
568  if (expr && IsA(expr, ArrayCoerceExpr))
569  {
570  const ArrayCoerceExpr *acoerce = (const ArrayCoerceExpr *) expr;
571 
572  /* It's not a length coercion unless there's a nondefault typmod */
573  if (acoerce->resulttypmod < 0)
574  return false;
575 
576  /*
577  * OK, it is indeed a length-coercion expression.
578  */
579  if (coercedTypmod != NULL)
580  *coercedTypmod = acoerce->resulttypmod;
581 
582  return true;
583  }
584 
585  return false;
586 }
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:671
@ COERCE_EXPLICIT_CAST
Definition: primnodes.h:670

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

1313 {
1314  int loc;
1315 
1316  if (expr == NULL)
1317  return -1;
1318  switch (nodeTag(expr))
1319  {
1320  case T_RangeVar:
1321  loc = ((const RangeVar *) expr)->location;
1322  break;
1323  case T_TableFunc:
1324  loc = ((const TableFunc *) expr)->location;
1325  break;
1326  case T_Var:
1327  loc = ((const Var *) expr)->location;
1328  break;
1329  case T_Const:
1330  loc = ((const Const *) expr)->location;
1331  break;
1332  case T_Param:
1333  loc = ((const Param *) expr)->location;
1334  break;
1335  case T_Aggref:
1336  /* function name should always be the first thing */
1337  loc = ((const Aggref *) expr)->location;
1338  break;
1339  case T_GroupingFunc:
1340  loc = ((const GroupingFunc *) expr)->location;
1341  break;
1342  case T_WindowFunc:
1343  /* function name should always be the first thing */
1344  loc = ((const WindowFunc *) expr)->location;
1345  break;
1346  case T_SubscriptingRef:
1347  /* just use container argument's location */
1348  loc = exprLocation((Node *) ((const SubscriptingRef *) expr)->refexpr);
1349  break;
1350  case T_FuncExpr:
1351  {
1352  const FuncExpr *fexpr = (const FuncExpr *) expr;
1353 
1354  /* consider both function name and leftmost arg */
1355  loc = leftmostLoc(fexpr->location,
1356  exprLocation((Node *) fexpr->args));
1357  }
1358  break;
1359  case T_NamedArgExpr:
1360  {
1361  const NamedArgExpr *na = (const NamedArgExpr *) expr;
1362 
1363  /* consider both argument name and value */
1364  loc = leftmostLoc(na->location,
1365  exprLocation((Node *) na->arg));
1366  }
1367  break;
1368  case T_OpExpr:
1369  case T_DistinctExpr: /* struct-equivalent to OpExpr */
1370  case T_NullIfExpr: /* struct-equivalent to OpExpr */
1371  {
1372  const OpExpr *opexpr = (const OpExpr *) expr;
1373 
1374  /* consider both operator name and leftmost arg */
1375  loc = leftmostLoc(opexpr->location,
1376  exprLocation((Node *) opexpr->args));
1377  }
1378  break;
1379  case T_ScalarArrayOpExpr:
1380  {
1381  const ScalarArrayOpExpr *saopexpr = (const ScalarArrayOpExpr *) expr;
1382 
1383  /* consider both operator name and leftmost arg */
1384  loc = leftmostLoc(saopexpr->location,
1385  exprLocation((Node *) saopexpr->args));
1386  }
1387  break;
1388  case T_BoolExpr:
1389  {
1390  const BoolExpr *bexpr = (const BoolExpr *) expr;
1391 
1392  /*
1393  * Same as above, to handle either NOT or AND/OR. We can't
1394  * special-case NOT because of the way that it's used for
1395  * things like IS NOT BETWEEN.
1396  */
1397  loc = leftmostLoc(bexpr->location,
1398  exprLocation((Node *) bexpr->args));
1399  }
1400  break;
1401  case T_SubLink:
1402  {
1403  const SubLink *sublink = (const SubLink *) expr;
1404 
1405  /* check the testexpr, if any, and the operator/keyword */
1406  loc = leftmostLoc(exprLocation(sublink->testexpr),
1407  sublink->location);
1408  }
1409  break;
1410  case T_FieldSelect:
1411  /* just use argument's location */
1412  loc = exprLocation((Node *) ((const FieldSelect *) expr)->arg);
1413  break;
1414  case T_FieldStore:
1415  /* just use argument's location */
1416  loc = exprLocation((Node *) ((const FieldStore *) expr)->arg);
1417  break;
1418  case T_RelabelType:
1419  {
1420  const RelabelType *rexpr = (const RelabelType *) expr;
1421 
1422  /* Much as above */
1423  loc = leftmostLoc(rexpr->location,
1424  exprLocation((Node *) rexpr->arg));
1425  }
1426  break;
1427  case T_CoerceViaIO:
1428  {
1429  const CoerceViaIO *cexpr = (const CoerceViaIO *) expr;
1430 
1431  /* Much as above */
1432  loc = leftmostLoc(cexpr->location,
1433  exprLocation((Node *) cexpr->arg));
1434  }
1435  break;
1436  case T_ArrayCoerceExpr:
1437  {
1438  const ArrayCoerceExpr *cexpr = (const ArrayCoerceExpr *) expr;
1439 
1440  /* Much as above */
1441  loc = leftmostLoc(cexpr->location,
1442  exprLocation((Node *) cexpr->arg));
1443  }
1444  break;
1445  case T_ConvertRowtypeExpr:
1446  {
1447  const ConvertRowtypeExpr *cexpr = (const ConvertRowtypeExpr *) expr;
1448 
1449  /* Much as above */
1450  loc = leftmostLoc(cexpr->location,
1451  exprLocation((Node *) cexpr->arg));
1452  }
1453  break;
1454  case T_CollateExpr:
1455  /* just use argument's location */
1456  loc = exprLocation((Node *) ((const CollateExpr *) expr)->arg);
1457  break;
1458  case T_CaseExpr:
1459  /* CASE keyword should always be the first thing */
1460  loc = ((const CaseExpr *) expr)->location;
1461  break;
1462  case T_CaseWhen:
1463  /* WHEN keyword should always be the first thing */
1464  loc = ((const CaseWhen *) expr)->location;
1465  break;
1466  case T_ArrayExpr:
1467  /* the location points at ARRAY or [, which must be leftmost */
1468  loc = ((const ArrayExpr *) expr)->location;
1469  break;
1470  case T_RowExpr:
1471  /* the location points at ROW or (, which must be leftmost */
1472  loc = ((const RowExpr *) expr)->location;
1473  break;
1474  case T_RowCompareExpr:
1475  /* just use leftmost argument's location */
1476  loc = exprLocation((Node *) ((const RowCompareExpr *) expr)->largs);
1477  break;
1478  case T_CoalesceExpr:
1479  /* COALESCE keyword should always be the first thing */
1480  loc = ((const CoalesceExpr *) expr)->location;
1481  break;
1482  case T_MinMaxExpr:
1483  /* GREATEST/LEAST keyword should always be the first thing */
1484  loc = ((const MinMaxExpr *) expr)->location;
1485  break;
1486  case T_SQLValueFunction:
1487  /* function keyword should always be the first thing */
1488  loc = ((const SQLValueFunction *) expr)->location;
1489  break;
1490  case T_XmlExpr:
1491  {
1492  const XmlExpr *xexpr = (const XmlExpr *) expr;
1493 
1494  /* consider both function name and leftmost arg */
1495  loc = leftmostLoc(xexpr->location,
1496  exprLocation((Node *) xexpr->args));
1497  }
1498  break;
1499  case T_JsonFormat:
1500  loc = ((const JsonFormat *) expr)->location;
1501  break;
1502  case T_JsonValueExpr:
1503  loc = exprLocation((Node *) ((const JsonValueExpr *) expr)->raw_expr);
1504  break;
1505  case T_JsonConstructorExpr:
1506  loc = ((const JsonConstructorExpr *) expr)->location;
1507  break;
1508  case T_JsonIsPredicate:
1509  loc = ((const JsonIsPredicate *) expr)->location;
1510  break;
1511  case T_NullTest:
1512  {
1513  const NullTest *nexpr = (const NullTest *) expr;
1514 
1515  /* Much as above */
1516  loc = leftmostLoc(nexpr->location,
1517  exprLocation((Node *) nexpr->arg));
1518  }
1519  break;
1520  case T_BooleanTest:
1521  {
1522  const BooleanTest *bexpr = (const BooleanTest *) expr;
1523 
1524  /* Much as above */
1525  loc = leftmostLoc(bexpr->location,
1526  exprLocation((Node *) bexpr->arg));
1527  }
1528  break;
1529  case T_CoerceToDomain:
1530  {
1531  const CoerceToDomain *cexpr = (const CoerceToDomain *) expr;
1532 
1533  /* Much as above */
1534  loc = leftmostLoc(cexpr->location,
1535  exprLocation((Node *) cexpr->arg));
1536  }
1537  break;
1538  case T_CoerceToDomainValue:
1539  loc = ((const CoerceToDomainValue *) expr)->location;
1540  break;
1541  case T_SetToDefault:
1542  loc = ((const SetToDefault *) expr)->location;
1543  break;
1544  case T_TargetEntry:
1545  /* just use argument's location */
1546  loc = exprLocation((Node *) ((const TargetEntry *) expr)->expr);
1547  break;
1548  case T_IntoClause:
1549  /* use the contained RangeVar's location --- close enough */
1550  loc = exprLocation((Node *) ((const IntoClause *) expr)->rel);
1551  break;
1552  case T_List:
1553  {
1554  /* report location of first list member that has a location */
1555  ListCell *lc;
1556 
1557  loc = -1; /* just to suppress compiler warning */
1558  foreach(lc, (const List *) expr)
1559  {
1560  loc = exprLocation((Node *) lfirst(lc));
1561  if (loc >= 0)
1562  break;
1563  }
1564  }
1565  break;
1566  case T_A_Expr:
1567  {
1568  const A_Expr *aexpr = (const A_Expr *) expr;
1569 
1570  /* use leftmost of operator or left operand (if any) */
1571  /* we assume right operand can't be to left of operator */
1572  loc = leftmostLoc(aexpr->location,
1573  exprLocation(aexpr->lexpr));
1574  }
1575  break;
1576  case T_ColumnRef:
1577  loc = ((const ColumnRef *) expr)->location;
1578  break;
1579  case T_ParamRef:
1580  loc = ((const ParamRef *) expr)->location;
1581  break;
1582  case T_A_Const:
1583  loc = ((const A_Const *) expr)->location;
1584  break;
1585  case T_FuncCall:
1586  {
1587  const FuncCall *fc = (const FuncCall *) expr;
1588 
1589  /* consider both function name and leftmost arg */
1590  /* (we assume any ORDER BY nodes must be to right of name) */
1591  loc = leftmostLoc(fc->location,
1592  exprLocation((Node *) fc->args));
1593  }
1594  break;
1595  case T_A_ArrayExpr:
1596  /* the location points at ARRAY or [, which must be leftmost */
1597  loc = ((const A_ArrayExpr *) expr)->location;
1598  break;
1599  case T_ResTarget:
1600  /* we need not examine the contained expression (if any) */
1601  loc = ((const ResTarget *) expr)->location;
1602  break;
1603  case T_MultiAssignRef:
1604  loc = exprLocation(((const MultiAssignRef *) expr)->source);
1605  break;
1606  case T_TypeCast:
1607  {
1608  const TypeCast *tc = (const TypeCast *) expr;
1609 
1610  /*
1611  * This could represent CAST(), ::, or TypeName 'literal', so
1612  * any of the components might be leftmost.
1613  */
1614  loc = exprLocation(tc->arg);
1615  loc = leftmostLoc(loc, tc->typeName->location);
1616  loc = leftmostLoc(loc, tc->location);
1617  }
1618  break;
1619  case T_CollateClause:
1620  /* just use argument's location */
1621  loc = exprLocation(((const CollateClause *) expr)->arg);
1622  break;
1623  case T_SortBy:
1624  /* just use argument's location (ignore operator, if any) */
1625  loc = exprLocation(((const SortBy *) expr)->node);
1626  break;
1627  case T_WindowDef:
1628  loc = ((const WindowDef *) expr)->location;
1629  break;
1630  case T_RangeTableSample:
1631  loc = ((const RangeTableSample *) expr)->location;
1632  break;
1633  case T_TypeName:
1634  loc = ((const TypeName *) expr)->location;
1635  break;
1636  case T_ColumnDef:
1637  loc = ((const ColumnDef *) expr)->location;
1638  break;
1639  case T_Constraint:
1640  loc = ((const Constraint *) expr)->location;
1641  break;
1642  case T_FunctionParameter:
1643  /* just use typename's location */
1644  loc = exprLocation((Node *) ((const FunctionParameter *) expr)->argType);
1645  break;
1646  case T_XmlSerialize:
1647  /* XMLSERIALIZE keyword should always be the first thing */
1648  loc = ((const XmlSerialize *) expr)->location;
1649  break;
1650  case T_GroupingSet:
1651  loc = ((const GroupingSet *) expr)->location;
1652  break;
1653  case T_WithClause:
1654  loc = ((const WithClause *) expr)->location;
1655  break;
1656  case T_InferClause:
1657  loc = ((const InferClause *) expr)->location;
1658  break;
1659  case T_OnConflictClause:
1660  loc = ((const OnConflictClause *) expr)->location;
1661  break;
1662  case T_CTESearchClause:
1663  loc = ((const CTESearchClause *) expr)->location;
1664  break;
1665  case T_CTECycleClause:
1666  loc = ((const CTECycleClause *) expr)->location;
1667  break;
1668  case T_CommonTableExpr:
1669  loc = ((const CommonTableExpr *) expr)->location;
1670  break;
1671  case T_JsonKeyValue:
1672  /* just use the key's location */
1673  loc = exprLocation((Node *) ((const JsonKeyValue *) expr)->key);
1674  break;
1675  case T_JsonObjectConstructor:
1676  loc = ((const JsonObjectConstructor *) expr)->location;
1677  break;
1678  case T_JsonArrayConstructor:
1679  loc = ((const JsonArrayConstructor *) expr)->location;
1680  break;
1681  case T_JsonArrayQueryConstructor:
1682  loc = ((const JsonArrayQueryConstructor *) expr)->location;
1683  break;
1684  case T_JsonAggConstructor:
1685  loc = ((const JsonAggConstructor *) expr)->location;
1686  break;
1687  case T_JsonObjectAgg:
1688  loc = exprLocation((Node *) ((const JsonObjectAgg *) expr)->constructor);
1689  break;
1690  case T_JsonArrayAgg:
1691  loc = exprLocation((Node *) ((const JsonArrayAgg *) expr)->constructor);
1692  break;
1693  case T_PlaceHolderVar:
1694  /* just use argument's location */
1695  loc = exprLocation((Node *) ((const PlaceHolderVar *) expr)->phexpr);
1696  break;
1697  case T_InferenceElem:
1698  /* just use nested expr's location */
1699  loc = exprLocation((Node *) ((const InferenceElem *) expr)->expr);
1700  break;
1701  case T_PartitionElem:
1702  loc = ((const PartitionElem *) expr)->location;
1703  break;
1704  case T_PartitionSpec:
1705  loc = ((const PartitionSpec *) expr)->location;
1706  break;
1707  case T_PartitionBoundSpec:
1708  loc = ((const PartitionBoundSpec *) expr)->location;
1709  break;
1710  case T_PartitionRangeDatum:
1711  loc = ((const PartitionRangeDatum *) expr)->location;
1712  break;
1713  default:
1714  /* for any other node type it's just unknown... */
1715  loc = -1;
1716  break;
1717  }
1718  return loc;
1719 }
static int leftmostLoc(int loc1, int loc2)
Definition: nodeFuncs.c:1727
int exprLocation(const Node *expr)
Definition: nodeFuncs.c:1312
static rewind_source * source
Definition: pg_rewind.c:89
static int fc(const char *x)
Definition: preproc-init.c:99
int location
Definition: parsenodes.h:328
Node * lexpr
Definition: parsenodes.h:326
int location
Definition: primnodes.h:876
int location
Definition: primnodes.h:705
int location
Definition: primnodes.h:1704
int location
Definition: primnodes.h:774
TypeName * typeName
Definition: parsenodes.h:364
int location
Definition: parsenodes.h:365
Node * arg
Definition: parsenodes.h:363
int location
Definition: parsenodes.h:265
int location
Definition: primnodes.h:1552

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(), 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, 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(), 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 1066 of file nodeFuncs.c.

1067 {
1068  switch (nodeTag(expr))
1069  {
1070  case T_Var:
1071  ((Var *) expr)->varcollid = collation;
1072  break;
1073  case T_Const:
1074  ((Const *) expr)->constcollid = collation;
1075  break;
1076  case T_Param:
1077  ((Param *) expr)->paramcollid = collation;
1078  break;
1079  case T_Aggref:
1080  ((Aggref *) expr)->aggcollid = collation;
1081  break;
1082  case T_GroupingFunc:
1083  Assert(!OidIsValid(collation));
1084  break;
1085  case T_WindowFunc:
1086  ((WindowFunc *) expr)->wincollid = collation;
1087  break;
1088  case T_SubscriptingRef:
1089  ((SubscriptingRef *) expr)->refcollid = collation;
1090  break;
1091  case T_FuncExpr:
1092  ((FuncExpr *) expr)->funccollid = collation;
1093  break;
1094  case T_NamedArgExpr:
1095  Assert(collation == exprCollation((Node *) ((NamedArgExpr *) expr)->arg));
1096  break;
1097  case T_OpExpr:
1098  ((OpExpr *) expr)->opcollid = collation;
1099  break;
1100  case T_DistinctExpr:
1101  ((DistinctExpr *) expr)->opcollid = collation;
1102  break;
1103  case T_NullIfExpr:
1104  ((NullIfExpr *) expr)->opcollid = collation;
1105  break;
1106  case T_ScalarArrayOpExpr:
1107  /* ScalarArrayOpExpr's result is boolean ... */
1108  Assert(!OidIsValid(collation)); /* ... so never set a collation */
1109  break;
1110  case T_BoolExpr:
1111  /* BoolExpr's result is boolean ... */
1112  Assert(!OidIsValid(collation)); /* ... so never set a collation */
1113  break;
1114  case T_SubLink:
1115 #ifdef USE_ASSERT_CHECKING
1116  {
1117  SubLink *sublink = (SubLink *) expr;
1118 
1119  if (sublink->subLinkType == EXPR_SUBLINK ||
1120  sublink->subLinkType == ARRAY_SUBLINK)
1121  {
1122  /* get the collation of subselect's first target column */
1123  Query *qtree = (Query *) sublink->subselect;
1124  TargetEntry *tent;
1125 
1126  if (!qtree || !IsA(qtree, Query))
1127  elog(ERROR, "cannot set collation for untransformed sublink");
1128  tent = linitial_node(TargetEntry, qtree->targetList);
1129  Assert(!tent->resjunk);
1130  Assert(collation == exprCollation((Node *) tent->expr));
1131  }
1132  else
1133  {
1134  /* otherwise, result is RECORD or BOOLEAN */
1135  Assert(!OidIsValid(collation));
1136  }
1137  }
1138 #endif /* USE_ASSERT_CHECKING */
1139  break;
1140  case T_FieldSelect:
1141  ((FieldSelect *) expr)->resultcollid = collation;
1142  break;
1143  case T_FieldStore:
1144  /* FieldStore's result is composite ... */
1145  Assert(!OidIsValid(collation)); /* ... so never set a collation */
1146  break;
1147  case T_RelabelType:
1148  ((RelabelType *) expr)->resultcollid = collation;
1149  break;
1150  case T_CoerceViaIO:
1151  ((CoerceViaIO *) expr)->resultcollid = collation;
1152  break;
1153  case T_ArrayCoerceExpr:
1154  ((ArrayCoerceExpr *) expr)->resultcollid = collation;
1155  break;
1156  case T_ConvertRowtypeExpr:
1157  /* ConvertRowtypeExpr's result is composite ... */
1158  Assert(!OidIsValid(collation)); /* ... so never set a collation */
1159  break;
1160  case T_CaseExpr:
1161  ((CaseExpr *) expr)->casecollid = collation;
1162  break;
1163  case T_ArrayExpr:
1164  ((ArrayExpr *) expr)->array_collid = collation;
1165  break;
1166  case T_RowExpr:
1167  /* RowExpr's result is composite ... */
1168  Assert(!OidIsValid(collation)); /* ... so never set a collation */
1169  break;
1170  case T_RowCompareExpr:
1171  /* RowCompareExpr's result is boolean ... */
1172  Assert(!OidIsValid(collation)); /* ... so never set a collation */
1173  break;
1174  case T_CoalesceExpr:
1175  ((CoalesceExpr *) expr)->coalescecollid = collation;
1176  break;
1177  case T_MinMaxExpr:
1178  ((MinMaxExpr *) expr)->minmaxcollid = collation;
1179  break;
1180  case T_SQLValueFunction:
1181  Assert((((SQLValueFunction *) expr)->type == NAMEOID) ?
1182  (collation == C_COLLATION_OID) :
1183  (collation == InvalidOid));
1184  break;
1185  case T_XmlExpr:
1186  Assert((((XmlExpr *) expr)->op == IS_XMLSERIALIZE) ?
1187  (collation == DEFAULT_COLLATION_OID) :
1188  (collation == InvalidOid));
1189  break;
1190  case T_JsonValueExpr:
1191  exprSetCollation((Node *) ((JsonValueExpr *) expr)->formatted_expr,
1192  collation);
1193  break;
1194  case T_JsonConstructorExpr:
1195  {
1196  JsonConstructorExpr *ctor = (JsonConstructorExpr *) expr;
1197 
1198  if (ctor->coercion)
1199  exprSetCollation((Node *) ctor->coercion, collation);
1200  else
1201  Assert(!OidIsValid(collation)); /* result is always a
1202  * json[b] type */
1203  }
1204  break;
1205  case T_JsonIsPredicate:
1206  Assert(!OidIsValid(collation)); /* result is always boolean */
1207  break;
1208  case T_NullTest:
1209  /* NullTest's result is boolean ... */
1210  Assert(!OidIsValid(collation)); /* ... so never set a collation */
1211  break;
1212  case T_BooleanTest:
1213  /* BooleanTest's result is boolean ... */
1214  Assert(!OidIsValid(collation)); /* ... so never set a collation */
1215  break;
1216  case T_CoerceToDomain:
1217  ((CoerceToDomain *) expr)->resultcollid = collation;
1218  break;
1219  case T_CoerceToDomainValue:
1220  ((CoerceToDomainValue *) expr)->collation = collation;
1221  break;
1222  case T_SetToDefault:
1223  ((SetToDefault *) expr)->collation = collation;
1224  break;
1225  case T_CurrentOfExpr:
1226  /* CurrentOfExpr's result is boolean ... */
1227  Assert(!OidIsValid(collation)); /* ... so never set a collation */
1228  break;
1229  case T_NextValueExpr:
1230  /* NextValueExpr's result is an integer type ... */
1231  Assert(!OidIsValid(collation)); /* ... so never set a collation */
1232  break;
1233  default:
1234  elog(ERROR, "unrecognized node type: %d", (int) nodeTag(expr));
1235  break;
1236  }
1237 }
#define OidIsValid(objectId)
Definition: c.h:764
void exprSetCollation(Node *expr, Oid collation)
Definition: nodeFuncs.c:1066

References arg, ARRAY_SUBLINK, Assert(), JsonConstructorExpr::coercion, elog(), ERROR, 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 1248 of file nodeFuncs.c.

1249 {
1250  switch (nodeTag(expr))
1251  {
1252  case T_Aggref:
1253  ((Aggref *) expr)->inputcollid = inputcollation;
1254  break;
1255  case T_WindowFunc:
1256  ((WindowFunc *) expr)->inputcollid = inputcollation;
1257  break;
1258  case T_FuncExpr:
1259  ((FuncExpr *) expr)->inputcollid = inputcollation;
1260  break;
1261  case T_OpExpr:
1262  ((OpExpr *) expr)->inputcollid = inputcollation;
1263  break;
1264  case T_DistinctExpr:
1265  ((DistinctExpr *) expr)->inputcollid = inputcollation;
1266  break;
1267  case T_NullIfExpr:
1268  ((NullIfExpr *) expr)->inputcollid = inputcollation;
1269  break;
1270  case T_ScalarArrayOpExpr:
1271  ((ScalarArrayOpExpr *) expr)->inputcollid = inputcollation;
1272  break;
1273  case T_MinMaxExpr:
1274  ((MinMaxExpr *) expr)->inputcollid = inputcollation;
1275  break;
1276  default:
1277  break;
1278  }
1279 }

References nodeTag.

Referenced by assign_collations_walker().

◆ exprType()

Oid exprType ( const Node expr)

Definition at line 43 of file nodeFuncs.c.

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

References arg, ARRAY_SUBLINK, Assert(), elog(), ereport, errcode(), errmsg(), ERROR, 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, SubLink::subLinkType, SubPlan::subLinkType, AlternativeSubPlan::subplans, SubLink::subselect, Query::targetList, and type.

Referenced by add_row_identity_var(), addRangeTableEntryForFunction(), addRangeTableEntryForSubquery(), addTargetToGroupList(), addTargetToSortList(), agg_args_support_sendreceive(), analyzeCTE(), analyzeCTETargetList(), appendAggOrderBy(), appendOrderByClause(), applyRelabelType(), array_subscript_transform(), assign_collations_walker(), assign_hypothetical_collations(), assign_param_for_placeholdervar(), ATExecAlterColumnType(), ATPrepAlterColumnType(), build_coercion_expression(), build_column_default(), build_subplan(), can_minmax_aggs(), canonicalize_ec_expression(), check_functions_in_node(), check_hashjoinable(), check_memoizable(), check_mergejoinable(), check_simple_rowfilter_expr_walker(), check_sql_fn_retval(), checkRuleResultList(), coerce_fn_result_column(), coerce_record_to_complex(), coerce_to_boolean(), coerce_to_common_type(), coerce_to_specific_type_typmod(), 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(), ExecMakeTableFunctionResult(), ExecTypeFromExprList(), ExecTypeFromTLInternal(), ExecWindowAgg(), expandRecordVariable(), expandRTE(), exprTypmod(), find_expr_references_walker(), find_placeholder_info(), fix_indexqual_operand(), foreign_expr_walker(), generate_append_tlist(), generate_join_implied_equalities_normal(), generate_setop_tlist(), generate_subquery_params(), generateClonedIndexStmt(), get_call_expr_argtype(), get_expr_result_tupdesc(), get_expr_result_type(), get_expr_width(), get_first_col_type(), get_fn_expr_rettype(), get_func_expr(), get_oper_expr(), get_rule_expr(), get_rule_expr_funccall(), get_rule_orderby(), get_simple_binary_op_name(), get_sublink_expr(), get_windowfunc_expr_helper(), GetIndexInputType(), hash_ok_operator(), hstore_subscript_transform(), initialize_peragg(), inline_function(), internal_get_result_type(), jsonb_exec_setup(), jsonb_subscript_transform(), 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_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(), transformJsonConstructorOutput(), transformJsonParseArg(), transformJsonScalarExpr(), transformJsonValueExpr(), transformMultiAssignRef(), transformPartitionBoundValue(), transformPLAssignStmt(), transformSetOperationTree(), transformSubLink(), transformTypeCast(), unknown_attribute(), verify_common_type(), and xmlelement().

◆ exprTypmod()

int32 exprTypmod ( const Node expr)

Definition at line 282 of file nodeFuncs.c.

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

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

Referenced by add_row_identity_var(), addRangeTableEntryForFunction(), addRangeTableEntryForSubquery(), analyzeCTE(), analyzeCTETargetList(), applyRelabelType(), assign_hypothetical_collations(), build_coercion_expression(), build_subplan(), canonicalize_ec_expression(), checkRuleResultList(), coerce_type_typmod(), ConstructTupleDescriptor(), convert_EXISTS_to_ANY(), create_ctas_nodata(), DefineVirtualRelation(), eval_const_expressions_mutator(), examine_attribute(), examine_expression(), examine_variable(), exec_save_simple_expr(), ExecTypeFromExprList(), ExecTypeFromTLInternal(), expandRecordVariable(), expandRTE(), find_placeholder_info(), generate_append_tlist(), generate_setop_tlist(), generate_subquery_params(), get_expr_result_type(), get_expr_width(), get_first_col_type(), get_rule_expr(), get_rule_expr_funccall(), interval_support(), 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(), transformMultiAssignRef(), transformPLAssignStmt(), transformSubLink(), varbit_support(), and varchar_support().

◆ fix_opfuncids()

void fix_opfuncids ( Node node)

Definition at line 1748 of file nodeFuncs.c.

1749 {
1750  /* This tree walk requires no special setup, so away we go... */
1751  fix_opfuncids_walker(node, NULL);
1752 }
static bool fix_opfuncids_walker(Node *node, void *context)
Definition: nodeFuncs.c:1755

References fix_opfuncids_walker().

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

◆ get_leftop()

◆ get_notclausearg()

◆ get_rightop()

◆ is_andclause()

◆ is_funcclause()

static bool is_funcclause ( const void *  clause)
inlinestatic

◆ is_notclause()

◆ is_opclause()

◆ is_orclause()

◆ planstate_tree_walker_impl()

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

Definition at line 4449 of file nodeFuncs.c.

4452 {
4453  Plan *plan = planstate->plan;
4454  ListCell *lc;
4455 
4456  /* We don't need implicit coercions to Node here */
4457 #define PSWALK(n) walker(n, context)
4458 
4459  /* Guard against stack overflow due to overly complex plan trees */
4461 
4462  /* initPlan-s */
4463  if (planstate_walk_subplans(planstate->initPlan, walker, context))
4464  return true;
4465 
4466  /* lefttree */
4467  if (outerPlanState(planstate))
4468  {
4469  if (PSWALK(outerPlanState(planstate)))
4470  return true;
4471  }
4472 
4473  /* righttree */
4474  if (innerPlanState(planstate))
4475  {
4476  if (PSWALK(innerPlanState(planstate)))
4477  return true;
4478  }
4479 
4480  /* special child plans */
4481  switch (nodeTag(plan))
4482  {
4483  case T_Append:
4484  if (planstate_walk_members(((AppendState *) planstate)->appendplans,
4485  ((AppendState *) planstate)->as_nplans,
4486  walker, context))
4487  return true;
4488  break;
4489  case T_MergeAppend:
4490  if (planstate_walk_members(((MergeAppendState *) planstate)->mergeplans,
4491  ((MergeAppendState *) planstate)->ms_nplans,
4492  walker, context))
4493  return true;
4494  break;
4495  case T_BitmapAnd:
4496  if (planstate_walk_members(((BitmapAndState *) planstate)->bitmapplans,
4497  ((BitmapAndState *) planstate)->nplans,
4498  walker, context))
4499  return true;
4500  break;
4501  case T_BitmapOr:
4502  if (planstate_walk_members(((BitmapOrState *) planstate)->bitmapplans,
4503  ((BitmapOrState *) planstate)->nplans,
4504  walker, context))
4505  return true;
4506  break;
4507  case T_SubqueryScan:
4508  if (PSWALK(((SubqueryScanState *) planstate)->subplan))
4509  return true;
4510  break;
4511  case T_CustomScan:
4512  foreach(lc, ((CustomScanState *) planstate)->custom_ps)
4513  {
4514  if (PSWALK(lfirst(lc)))
4515  return true;
4516  }
4517  break;
4518  default:
4519  break;
4520  }
4521 
4522  /* subPlan-s */
4523  if (planstate_walk_subplans(planstate->subPlan, walker, context))
4524  return true;
4525 
4526  return false;
4527 }
#define outerPlanState(node)
Definition: execnodes.h:1132
#define innerPlanState(node)
Definition: execnodes.h:1131
static bool planstate_walk_subplans(List *plans, planstate_tree_walker_callback walker, void *context)
Definition: nodeFuncs.c:4533
#define PSWALK(n)
static bool planstate_walk_members(PlanState **planstates, int nplans, planstate_tree_walker_callback walker, void *context)
Definition: nodeFuncs.c:4555
#define plan(x)
Definition: pg_regress.c:162
Plan * plan
Definition: execnodes.h:1036
List * initPlan
Definition: execnodes.h:1061

References check_stack_depth(), 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 3769 of file nodeFuncs.c.

3773 {
3774  if (node && IsA(node, Query))
3775  return (Node *) query_tree_mutator((Query *) node,
3776  mutator,
3777  context,
3778  flags);
3779  else
3780  return mutator(node, context);
3781 }
#define query_tree_mutator(q, m, c, f)
Definition: nodeFuncs.h:158

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

3750 {
3751  if (node && IsA(node, Query))
3752  return query_tree_walker((Query *) node,
3753  walker,
3754  context,
3755  flags);
3756  else
3757  return WALK(node);
3758 }
#define query_tree_walker(q, w, c, f)
Definition: nodeFuncs.h:156

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

3591 {
3592  Assert(query != NULL && IsA(query, Query));
3593 
3594  if (!(flags & QTW_DONT_COPY_QUERY))
3595  {
3596  Query *newquery;
3597 
3598  FLATCOPY(newquery, query, Query);
3599  query = newquery;
3600  }
3601 
3602  MUTATE(query->targetList, query->targetList, List *);
3603  MUTATE(query->withCheckOptions, query->withCheckOptions, List *);
3604  MUTATE(query->onConflict, query->onConflict, OnConflictExpr *);
3605  MUTATE(query->mergeActionList, query->mergeActionList, List *);
3606  MUTATE(query->returningList, query->returningList, List *);
3607  MUTATE(query->jointree, query->jointree, FromExpr *);
3608  MUTATE(query->setOperations, query->setOperations, Node *);
3609  MUTATE(query->havingQual, query->havingQual, Node *);
3610  MUTATE(query->limitOffset, query->limitOffset, Node *);
3611  MUTATE(query->limitCount, query->limitCount, Node *);
3612 
3613  /*
3614  * Most callers aren't interested in SortGroupClause nodes since those
3615  * don't contain actual expressions. However they do contain OIDs, which
3616  * may be of interest to some mutators.
3617  */
3618 
3619  if ((flags & QTW_EXAMINE_SORTGROUP))
3620  {
3621  MUTATE(query->groupClause, query->groupClause, List *);
3622  MUTATE(query->windowClause, query->windowClause, List *);
3623  MUTATE(query->sortClause, query->sortClause, List *);
3624  MUTATE(query->distinctClause, query->distinctClause, List *);
3625  }
3626  else
3627  {
3628  /*
3629  * But we need to mutate the expressions under WindowClause nodes even
3630  * if we're not interested in SortGroupClause nodes.
3631  */
3632  List *resultlist;
3633  ListCell *temp;
3634 
3635  resultlist = NIL;
3636  foreach(temp, query->windowClause)
3637  {
3638  WindowClause *wc = lfirst_node(WindowClause, temp);
3639  WindowClause *newnode;
3640 
3641  FLATCOPY(newnode, wc, WindowClause);
3642  MUTATE(newnode->startOffset, wc->startOffset, Node *);
3643  MUTATE(newnode->endOffset, wc->endOffset, Node *);
3644 
3645  resultlist = lappend(resultlist, (Node *) newnode);
3646  }
3647  query->windowClause = resultlist;
3648  }
3649 
3650  /*
3651  * groupingSets and rowMarks are not mutated:
3652  *
3653  * groupingSets contain only ressortgroup refs (integers) which are
3654  * meaningless without the groupClause or tlist. Accordingly, any mutator
3655  * that needs to care about them needs to handle them itself in its Query
3656  * processing.
3657  *
3658  * rowMarks contains only rangetable indexes (and flags etc.) and
3659  * therefore should be handled at Query level similarly.
3660  */
3661 
3662  if (!(flags & QTW_IGNORE_CTE_SUBQUERIES))
3663  MUTATE(query->cteList, query->cteList, List *);
3664  else /* else copy CTE list as-is */
3665  query->cteList = copyObject(query->cteList);
3666  query->rtable = range_table_mutator(query->rtable,
3667  mutator, context, flags);
3668  return query;
3669 }
#define QTW_DONT_COPY_QUERY
Definition: nodeFuncs.h:29
#define QTW_IGNORE_CTE_SUBQUERIES
Definition: nodeFuncs.h:23
#define QTW_EXAMINE_SORTGROUP
Definition: nodeFuncs.h:30
#define range_table_mutator(rt, m, c, f)
Definition: nodeFuncs.h:163
Node * limitCount
Definition: parsenodes.h:204
FromExpr * jointree
Definition: parsenodes.h:174
List * returningList
Definition: parsenodes.h:188
Node * setOperations
Definition: parsenodes.h:209
List * cteList
Definition: parsenodes.h:165
OnConflictExpr * onConflict
Definition: parsenodes.h:186
List * groupClause
Definition: parsenodes.h:190
Node * havingQual
Definition: parsenodes.h:195
List * rtable
Definition: parsenodes.h:167
Node * limitOffset
Definition: parsenodes.h:203
List * mergeActionList
Definition: parsenodes.h:177
List * windowClause
Definition: parsenodes.h:197
List * distinctClause
Definition: parsenodes.h:199
List * sortClause
Definition: parsenodes.h:201

References Assert(), copyObject, Query::cteList, Query::distinctClause, WindowClause::endOffset, FLATCOPY, Query::groupClause, Query::havingQual, IsA, Query::jointree, lappend(), lfirst_node, Query::limitCount, Query::limitOffset, Query::mergeActionList, 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 2563 of file nodeFuncs.c.

2567 {
2568  Assert(query != NULL && IsA(query, Query));
2569 
2570  /*
2571  * We don't walk any utilityStmt here. However, we can't easily assert
2572  * that it is absent, since there are at least two code paths by which
2573  * action statements from CREATE RULE end up here, and NOTIFY is allowed
2574  * in a rule action.
2575  */
2576 
2577  if (WALK(query->targetList))
2578  return true;
2579  if (WALK(query->withCheckOptions))
2580  return true;
2581  if (WALK(query->onConflict))
2582  return true;
2583  if (WALK(query->mergeActionList))
2584  return true;
2585  if (WALK(query->returningList))
2586  return true;
2587  if (WALK(query->jointree))
2588  return true;
2589  if (WALK(query->setOperations))
2590  return true;
2591  if (WALK(query->havingQual))
2592  return true;
2593  if (WALK(query->limitOffset))
2594  return true;
2595  if (WALK(query->limitCount))
2596  return true;
2597 
2598  /*
2599  * Most callers aren't interested in SortGroupClause nodes since those
2600  * don't contain actual expressions. However they do contain OIDs which
2601  * may be needed by dependency walkers etc.
2602  */
2603  if ((flags & QTW_EXAMINE_SORTGROUP))
2604  {
2605  if (WALK(query->groupClause))
2606  return true;
2607  if (WALK(query->windowClause))
2608  return true;
2609  if (WALK(query->sortClause))
2610  return true;
2611  if (WALK(query->distinctClause))
2612  return true;
2613  }
2614  else
2615  {
2616  /*
2617  * But we need to walk the expressions under WindowClause nodes even
2618  * if we're not interested in SortGroupClause nodes.
2619  */
2620  ListCell *lc;
2621 
2622  foreach(lc, query->windowClause)
2623  {
2625 
2626  if (WALK(wc->startOffset))
2627  return true;
2628  if (WALK(wc->endOffset))
2629  return true;
2630  }
2631  }
2632 
2633  /*
2634  * groupingSets and rowMarks are not walked:
2635  *
2636  * groupingSets contain only ressortgrouprefs (integers) which are
2637  * meaningless without the corresponding groupClause or tlist.
2638  * Accordingly, any walker that needs to care about them needs to handle
2639  * them itself in its Query processing.
2640  *
2641  * rowMarks is not walked because it contains only rangetable indexes (and
2642  * flags etc.) and therefore should be handled at Query level similarly.
2643  */
2644 
2645  if (!(flags & QTW_IGNORE_CTE_SUBQUERIES))
2646  {
2647  if (WALK(query->cteList))
2648  return true;
2649  }
2650  if (!(flags & QTW_IGNORE_RANGE_TABLE))
2651  {
2652  if (range_table_walker(query->rtable, walker, context, flags))
2653  return true;
2654  }
2655  return false;
2656 }
#define range_table_walker(rt, w, c, f)
Definition: nodeFuncs.h:161
#define QTW_IGNORE_RANGE_TABLE
Definition: nodeFuncs.h:26

References Assert(), Query::cteList, Query::distinctClause, WindowClause::endOffset, Query::groupClause, Query::havingQual, IsA, Query::jointree, lfirst_node, Query::limitCount, Query::limitOffset, Query::mergeActionList, 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 2685 of file nodeFuncs.c.

2689 {
2690  /*
2691  * Walkers might need to examine the RTE node itself either before or
2692  * after visiting its contents (or, conceivably, both). Note that if you
2693  * specify neither flag, the walker won't be called on the RTE at all.
2694  */
2695  if (flags & QTW_EXAMINE_RTES_BEFORE)
2696  if (WALK(rte))
2697  return true;
2698 
2699  switch (rte->rtekind)
2700  {
2701  case RTE_RELATION:
2702  if (WALK(rte->tablesample))
2703  return true;
2704  break;
2705  case RTE_SUBQUERY:
2706  if (!(flags & QTW_IGNORE_RT_SUBQUERIES))
2707  if (WALK(rte->subquery))
2708  return true;
2709  break;
2710  case RTE_JOIN:
2711  if (!(flags & QTW_IGNORE_JOINALIASES))
2712  if (WALK(rte->joinaliasvars))
2713  return true;
2714  break;
2715  case RTE_FUNCTION:
2716  if (WALK(rte->functions))
2717  return true;
2718  break;
2719  case RTE_TABLEFUNC:
2720  if (WALK(rte->tablefunc))
2721  return true;
2722  break;
2723  case RTE_VALUES:
2724  if (WALK(rte->values_lists))
2725  return true;
2726  break;
2727  case RTE_CTE:
2728  case RTE_NAMEDTUPLESTORE:
2729  case RTE_RESULT:
2730  /* nothing to do */
2731  break;
2732  }
2733 
2734  if (WALK(rte->securityQuals))
2735  return true;
2736 
2737  if (flags & QTW_EXAMINE_RTES_AFTER)
2738  if (WALK(rte))
2739  return true;
2740 
2741  return false;
2742 }
#define QTW_IGNORE_RT_SUBQUERIES
Definition: nodeFuncs.h:22
#define QTW_EXAMINE_RTES_AFTER
Definition: nodeFuncs.h:28
#define QTW_EXAMINE_RTES_BEFORE
Definition: nodeFuncs.h:27
#define QTW_IGNORE_JOINALIASES
Definition: nodeFuncs.h:25
@ RTE_JOIN
Definition: parsenodes.h:1008
@ RTE_CTE
Definition: parsenodes.h:1012
@ RTE_NAMEDTUPLESTORE
Definition: parsenodes.h:1013
@ RTE_VALUES
Definition: parsenodes.h:1011
@ RTE_SUBQUERY
Definition: parsenodes.h:1007
@ RTE_RESULT
Definition: parsenodes.h:1014
@ RTE_FUNCTION
Definition: parsenodes.h:1009
@ RTE_TABLEFUNC
Definition: parsenodes.h:1010
@ RTE_RELATION
Definition: parsenodes.h:1006
TableFunc * tablefunc
Definition: parsenodes.h:1146
struct TableSampleClause * tablesample
Definition: parsenodes.h:1067
List * securityQuals
Definition: parsenodes.h:1196
Query * subquery
Definition: parsenodes.h:1073
List * values_lists
Definition: parsenodes.h:1151
List * joinaliasvars
Definition: parsenodes.h:1121
List * functions
Definition: parsenodes.h:1140
RTEKind rtekind
Definition: parsenodes.h:1025

References RangeTblEntry::functions, RangeTblEntry::joinaliasvars, QTW_EXAMINE_RTES_AFTER, QTW_EXAMINE_RTES_BEFORE, QTW_IGNORE_JOINALIASES, QTW_IGNORE_RT_SUBQUERIES, RTE_CTE, RTE_FUNCTION, RTE_JOIN, RTE_NAMEDTUPLESTORE, RTE_RELATION, RTE_RESULT, RTE_SUBQUERY, RTE_TABLEFUNC, RTE_VALUES, RangeTblEntry::rtekind, RangeTblEntry::securityQuals, 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 3677 of file nodeFuncs.c.

3681 {
3682  List *newrt = NIL;
3683  ListCell *rt;
3684 
3685  foreach(rt, rtable)
3686  {
3687  RangeTblEntry *rte = (RangeTblEntry *) lfirst(rt);
3688  RangeTblEntry *newrte;
3689 
3690  FLATCOPY(newrte, rte, RangeTblEntry);
3691  switch (rte->rtekind)
3692  {
3693  case RTE_RELATION:
3694  MUTATE(newrte->tablesample, rte->tablesample,
3695  TableSampleClause *);
3696  /* we don't bother to copy eref, aliases, etc; OK? */
3697  break;
3698  case RTE_SUBQUERY:
3699  if (!(flags & QTW_IGNORE_RT_SUBQUERIES))
3700  MUTATE(newrte->subquery, rte->subquery, Query *);
3701  else
3702  {
3703  /* else, copy RT subqueries as-is */
3704  newrte->subquery = copyObject(rte->subquery);
3705  }
3706  break;
3707  case RTE_JOIN:
3708  if (!(flags & QTW_IGNORE_JOINALIASES))
3709  MUTATE(newrte->joinaliasvars, rte->joinaliasvars, List *);
3710  else
3711  {
3712  /* else, copy join aliases as-is */
3713  newrte->joinaliasvars = copyObject(rte->joinaliasvars);
3714  }
3715  break;
3716  case RTE_FUNCTION:
3717  MUTATE(newrte->functions, rte->functions, List *);
3718  break;
3719  case RTE_TABLEFUNC:
3720  MUTATE(newrte->tablefunc, rte->tablefunc, TableFunc *);
3721  break;
3722  case RTE_VALUES:
3723  MUTATE(newrte->values_lists, rte->values_lists, List *);
3724  break;
3725  case RTE_CTE:
3726  case RTE_NAMEDTUPLESTORE:
3727  case RTE_RESULT:
3728  /* nothing to do */
3729  break;
3730  }
3731  MUTATE(newrte->securityQuals, rte->securityQuals, List *);
3732  newrt = lappend(newrt, newrte);
3733  }
3734  return newrt;
3735 }

References copyObject, FLATCOPY, RangeTblEntry::functions, RangeTblEntry::joinaliasvars, lappend(), lfirst, MUTATE, NIL, QTW_IGNORE_JOINALIASES, QTW_IGNORE_RT_SUBQUERIES, RTE_CTE, RTE_FUNCTION, RTE_JOIN, RTE_NAMEDTUPLESTORE, RTE_RELATION, RTE_RESULT, RTE_SUBQUERY, RTE_TABLEFUNC, RTE_VALUES, RangeTblEntry::rtekind, RangeTblEntry::securityQuals, 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 2664 of file nodeFuncs.c.

2668 {
2669  ListCell *rt;
2670 
2671  foreach(rt, rtable)
2672  {
2674 
2675  if (range_table_entry_walker(rte, walker, context, flags))
2676  return true;
2677  }
2678  return false;
2679 }
#define range_table_entry_walker(r, w, c, f)
Definition: nodeFuncs.h:166

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

3803 {
3804  ListCell *temp;
3805 
3806  /*
3807  * The walker has already visited the current node, and so we need only
3808  * recurse into any sub-nodes it has.
3809  */
3810  if (node == NULL)
3811  return false;
3812 
3813  /* Guard against stack overflow due to overly complex expressions */
3815 
3816  switch (nodeTag(node))
3817  {
3818  case T_JsonFormat:
3819  case T_SetToDefault:
3820  case T_CurrentOfExpr:
3821  case T_SQLValueFunction:
3822  case T_Integer:
3823  case T_Float:
3824  case T_Boolean:
3825  case T_String:
3826  case T_BitString:
3827  case T_ParamRef:
3828  case T_A_Const:
3829  case T_A_Star:
3830  /* primitive node types with no subnodes */
3831  break;
3832  case T_Alias:
3833  /* we assume the colnames list isn't interesting */
3834  break;
3835  case T_RangeVar:
3836  return WALK(((RangeVar *) node)->alias);
3837  case T_GroupingFunc:
3838  return WALK(((GroupingFunc *) node)->args);
3839  case T_SubLink:
3840  {
3841  SubLink *sublink = (SubLink *) node;
3842 
3843  if (WALK(sublink->testexpr))
3844  return true;
3845  /* we assume the operName is not interesting */
3846  if (WALK(sublink->subselect))
3847  return true;
3848  }
3849  break;
3850  case T_CaseExpr:
3851  {
3852  CaseExpr *caseexpr = (CaseExpr *) node;
3853 
3854  if (WALK(caseexpr->arg))
3855  return true;
3856  /* we assume walker doesn't care about CaseWhens, either */
3857  foreach(temp, caseexpr->args)
3858  {
3859  CaseWhen *when = lfirst_node(CaseWhen, temp);
3860 
3861  if (WALK(when->expr))
3862  return true;
3863  if (WALK(when->result))
3864  return true;
3865  }
3866  if (WALK(caseexpr->defresult))
3867  return true;
3868  }
3869  break;
3870  case T_RowExpr:
3871  /* Assume colnames isn't interesting */
3872  return WALK(((RowExpr *) node)->args);
3873  case T_CoalesceExpr:
3874  return WALK(((CoalesceExpr *) node)->args);
3875  case T_MinMaxExpr:
3876  return WALK(((MinMaxExpr *) node)->args);
3877  case T_XmlExpr:
3878  {
3879  XmlExpr *xexpr = (XmlExpr *) node;
3880 
3881  if (WALK(xexpr->named_args))
3882  return true;
3883  /* we assume walker doesn't care about arg_names */
3884  if (WALK(xexpr->args))
3885  return true;
3886  }
3887  break;
3888  case T_JsonReturning:
3889  return WALK(((JsonReturning *) node)->format);
3890  case T_JsonValueExpr:
3891  {
3892  JsonValueExpr *jve = (JsonValueExpr *) node;
3893 
3894  if (WALK(jve->raw_expr))
3895  return true;
3896  if (WALK(jve->formatted_expr))
3897  return true;
3898  if (WALK(jve->format))
3899  return true;
3900  }
3901  break;
3902  case T_JsonParseExpr:
3903  {
3904  JsonParseExpr *jpe = (JsonParseExpr *) node;
3905 
3906  if (WALK(jpe->expr))
3907  return true;
3908  if (WALK(jpe->output))
3909  return true;
3910  }
3911  break;
3912  case T_JsonScalarExpr:
3913  {
3914  JsonScalarExpr *jse = (JsonScalarExpr *) node;
3915 
3916  if (WALK(jse->expr))
3917  return true;
3918  if (WALK(jse->output))
3919  return true;
3920  }
3921  break;
3922  case T_JsonSerializeExpr:
3923  {
3924  JsonSerializeExpr *jse = (JsonSerializeExpr *) node;
3925 
3926  if (WALK(jse->expr))
3927  return true;
3928  if (WALK(jse->output))
3929  return true;
3930  }
3931  break;
3932  case T_JsonConstructorExpr:
3933  {
3934  JsonConstructorExpr *ctor = (JsonConstructorExpr *) node;
3935 
3936  if (WALK(ctor->args))
3937  return true;
3938  if (WALK(ctor->func))
3939  return true;
3940  if (WALK(ctor->coercion))
3941  return true;
3942  if (WALK(ctor->returning))
3943  return true;
3944  }
3945  break;
3946  case T_JsonIsPredicate:
3947  return WALK(((JsonIsPredicate *) node)->expr);
3948  case T_NullTest:
3949  return WALK(((NullTest *) node)->arg);
3950  case T_BooleanTest:
3951  return WALK(((BooleanTest *) node)->arg);
3952  case T_JoinExpr:
3953  {
3954  JoinExpr *join = (JoinExpr *) node;
3955 
3956  if (WALK(join->larg))
3957  return true;
3958  if (WALK(join->rarg))
3959  return true;
3960  if (WALK(join->quals))
3961  return true;
3962  if (WALK(join->alias))
3963  return true;
3964  /* using list is deemed uninteresting */
3965  }
3966  break;
3967  case T_IntoClause:
3968  {
3969  IntoClause *into = (IntoClause *) node;
3970 
3971  if (WALK(into->rel))
3972  return true;
3973  /* colNames, options are deemed uninteresting */
3974  /* viewQuery should be null in raw parsetree, but check it */
3975  if (WALK(into->viewQuery))
3976  return true;
3977  }
3978  break;
3979  case T_List:
3980  foreach(temp, (List *) node)
3981  {
3982  if (WALK((Node *) lfirst(temp)))
3983  return true;
3984  }
3985  break;
3986  case T_InsertStmt:
3987  {
3988  InsertStmt *stmt = (InsertStmt *) node;
3989 
3990  if (WALK(stmt->relation))
3991  return true;
3992  if (WALK(stmt->cols))
3993  return true;
3994  if (WALK(stmt->selectStmt))
3995  return true;
3996  if (WALK(stmt->onConflictClause))
3997  return true;
3998  if (WALK(stmt->returningList))
3999  return true;
4000  if (WALK(stmt->withClause))
4001  return true;
4002  }
4003  break;
4004  case T_DeleteStmt:
4005  {
4006  DeleteStmt *stmt = (DeleteStmt *) node;
4007 
4008  if (WALK(stmt->relation))
4009  return true;
4010  if (WALK(stmt->usingClause))
4011  return true;
4012  if (WALK(stmt->whereClause))
4013  return true;
4014  if (WALK(stmt->returningList))
4015  return true;
4016  if (WALK(stmt->withClause))
4017  return true;
4018  }
4019  break;
4020  case T_UpdateStmt:
4021  {
4022  UpdateStmt *stmt = (UpdateStmt *) node;
4023 
4024  if (WALK(stmt->relation))
4025  return true;
4026  if (WALK(stmt->targetList))
4027  return true;
4028  if (WALK(stmt->whereClause))
4029  return true;
4030  if (WALK(stmt->fromClause))
4031  return true;
4032  if (WALK(stmt->returningList))
4033  return true;
4034  if (WALK(stmt->withClause))
4035  return true;
4036  }
4037  break;
4038  case T_MergeStmt:
4039  {
4040  MergeStmt *stmt = (MergeStmt *) node;
4041 
4042  if (WALK(stmt->relation))
4043  return true;
4044  if (WALK(stmt->sourceRelation))
4045  return true;
4046  if (WALK(stmt->joinCondition))
4047  return true;
4048  if (WALK(stmt->mergeWhenClauses))
4049  return true;
4050  if (WALK(stmt->withClause))
4051  return true;
4052  }
4053  break;
4054  case T_MergeWhenClause:
4055  {
4056  MergeWhenClause *mergeWhenClause = (MergeWhenClause *) node;
4057 
4058  if (WALK(mergeWhenClause->condition))
4059  return true;
4060  if (WALK(mergeWhenClause->targetList))
4061  return true;
4062  if (WALK(mergeWhenClause->values))
4063  return true;
4064  }
4065  break;
4066  case T_SelectStmt:
4067  {
4068  SelectStmt *stmt = (SelectStmt *) node;
4069 
4070  if (WALK(stmt->distinctClause))
4071  return true;
4072  if (WALK(stmt->intoClause))
4073  return true;
4074  if (WALK(stmt->targetList))
4075  return true;
4076  if (WALK(stmt->fromClause))
4077  return true;
4078  if (WALK(stmt->whereClause))
4079  return true;
4080  if (WALK(stmt->groupClause))
4081  return true;
4082  if (WALK(stmt->havingClause))
4083  return true;
4084  if (WALK(stmt->windowClause))
4085  return true;
4086  if (WALK(stmt->valuesLists))
4087  return true;
4088  if (WALK(stmt->sortClause))
4089  return true;
4090  if (WALK(stmt->limitOffset))
4091  return true;
4092  if (WALK(stmt->limitCount))
4093  return true;
4094  if (WALK(stmt->lockingClause))
4095  return true;
4096  if (WALK(stmt->withClause))
4097  return true;
4098  if (WALK(stmt->larg))
4099  return true;
4100  if (WALK(stmt->rarg))
4101  return true;
4102  }
4103  break;
4104  case T_PLAssignStmt:
4105  {
4106  PLAssignStmt *stmt = (PLAssignStmt *) node;
4107 
4108  if (WALK(stmt->indirection))
4109  return true;
4110  if (WALK(stmt->val))
4111  return true;
4112  }
4113  break;
4114  case T_A_Expr:
4115  {
4116  A_Expr *expr = (A_Expr *) node;
4117 
4118  if (WALK(expr->lexpr))
4119  return true;
4120  if (WALK(expr->rexpr))
4121  return true;
4122  /* operator name is deemed uninteresting */
4123  }
4124  break;
4125  case T_BoolExpr:
4126  {
4127  BoolExpr *expr = (BoolExpr *) node;
4128 
4129  if (WALK(expr->args))
4130  return true;
4131  }
4132  break;
4133  case T_ColumnRef:
4134  /* we assume the fields contain nothing interesting */
4135  break;
4136  case T_FuncCall:
4137  {
4138  FuncCall *fcall = (FuncCall *) node;
4139 
4140  if (WALK(fcall->args))
4141  return true;
4142  if (WALK(fcall->agg_order))
4143  return true;
4144  if (WALK(fcall->agg_filter))
4145  return true;
4146  if (WALK(fcall->over))
4147  return true;
4148  /* function name is deemed uninteresting */
4149  }
4150  break;
4151  case T_NamedArgExpr:
4152  return WALK(((NamedArgExpr *) node)->arg);
4153  case T_A_Indices:
4154  {
4155  A_Indices *indices = (A_Indices *) node;
4156 
4157  if (WALK(indices->lidx))
4158  return true;
4159  if (WALK(indices->uidx))
4160  return true;
4161  }
4162  break;
4163  case T_A_Indirection:
4164  {
4165  A_Indirection *indir = (A_Indirection *) node;
4166 
4167  if (WALK(indir->arg))
4168  return true;
4169  if (WALK(indir->indirection))
4170  return true;
4171  }
4172  break;
4173  case T_A_ArrayExpr:
4174  return WALK(((A_ArrayExpr *) node)->elements);
4175  case T_ResTarget:
4176  {
4177  ResTarget *rt = (ResTarget *) node;
4178 
4179  if (WALK(rt->indirection))
4180  return true;
4181  if (WALK(rt->val))
4182  return true;
4183  }
4184  break;
4185  case T_MultiAssignRef:
4186  return WALK(((MultiAssignRef *) node)->source);
4187  case T_TypeCast:
4188  {
4189  TypeCast *tc = (TypeCast *) node;
4190 
4191  if (WALK(tc->arg))
4192  return true;
4193  if (WALK(tc->typeName))
4194  return true;
4195  }
4196  break;
4197  case T_CollateClause:
4198  return WALK(((CollateClause *) node)->arg);
4199  case T_SortBy:
4200  return WALK(((SortBy *) node)->node);
4201  case T_WindowDef:
4202  {
4203  WindowDef *wd = (WindowDef *) node;
4204 
4205  if (WALK(wd->partitionClause))
4206  return true;
4207  if (WALK(wd->orderClause))
4208  return true;
4209  if (WALK(wd->startOffset))
4210  return true;
4211  if (WALK(wd->endOffset))
4212  return true;
4213  }
4214  break;
4215  case T_RangeSubselect:
4216  {
4217  RangeSubselect *rs = (RangeSubselect *) node;
4218 
4219  if (WALK(rs->subquery))
4220  return true;
4221  if (WALK(rs->alias))
4222  return true;
4223  }
4224  break;
4225  case T_RangeFunction:
4226  {
4227  RangeFunction *rf = (RangeFunction *) node;
4228 
4229  if (WALK(rf->functions))
4230  return true;
4231  if (WALK(rf->alias))
4232  return true;
4233  if (WALK(rf->coldeflist))
4234  return true;
4235  }
4236  break;
4237  case T_RangeTableSample:
4238  {
4239  RangeTableSample *rts = (RangeTableSample *) node;
4240 
4241  if (WALK(rts->relation))
4242  return true;
4243  /* method name is deemed uninteresting */
4244  if (WALK(rts->args))
4245  return true;
4246  if (WALK(rts->repeatable))
4247  return true;
4248  }
4249  break;
4250  case T_RangeTableFunc:
4251  {
4252  RangeTableFunc *rtf = (RangeTableFunc *) node;
4253 
4254  if (WALK(rtf->docexpr))
4255  return true;
4256  if (WALK(rtf->rowexpr))
4257  return true;
4258  if (WALK(rtf->namespaces))
4259  return true;
4260  if (WALK(rtf->columns))
4261  return true;
4262  if (WALK(rtf->alias))
4263  return true;
4264  }
4265  break;
4266  case T_RangeTableFuncCol:
4267  {
4268  RangeTableFuncCol *rtfc = (RangeTableFuncCol *) node;
4269 
4270  if (WALK(rtfc->colexpr))
4271  return true;
4272  if (WALK(rtfc->coldefexpr))
4273  return true;
4274  }
4275  break;
4276  case T_TypeName:
4277  {
4278  TypeName *tn = (TypeName *) node;
4279 
4280  if (WALK(tn->typmods))
4281  return true;
4282  if (WALK(tn->arrayBounds))
4283  return true;
4284  /* type name itself is deemed uninteresting */
4285  }
4286  break;
4287  case T_ColumnDef:
4288  {
4289  ColumnDef *coldef = (ColumnDef *) node;
4290 
4291  if (WALK(coldef->typeName))
4292  return true;
4293  if (WALK(coldef->raw_default))
4294  return true;
4295  if (WALK(coldef->collClause))
4296  return true;
4297  /* for now, constraints are ignored */
4298  }
4299  break;
4300  case T_IndexElem:
4301  {
4302  IndexElem *indelem = (IndexElem *) node;
4303 
4304  if (WALK(indelem->expr))
4305  return true;
4306  /* collation and opclass names are deemed uninteresting */
4307  }
4308  break;
4309  case T_GroupingSet:
4310  return WALK(((GroupingSet *) node)->content);
4311  case T_LockingClause:
4312  return WALK(((LockingClause *) node)->lockedRels);
4313  case T_XmlSerialize:
4314  {
4315  XmlSerialize *xs = (XmlSerialize *) node;
4316 
4317  if (WALK(xs->expr))
4318  return true;
4319  if (WALK(xs->typeName))
4320  return true;
4321  }
4322  break;
4323  case T_WithClause:
4324  return WALK(((WithClause *) node)->ctes);
4325  case T_InferClause:
4326  {
4327  InferClause *stmt = (InferClause *) node;
4328 
4329  if (WALK(stmt->indexElems))
4330  return true;
4331  if (WALK(stmt->whereClause))
4332  return true;
4333  }
4334  break;
4335  case T_OnConflictClause:
4336  {
4338 
4339  if (WALK(stmt->infer))
4340  return true;
4341  if (WALK(stmt->targetList))
4342  return true;
4343  if (WALK(stmt->whereClause))
4344  return true;
4345  }
4346  break;
4347  case T_CommonTableExpr:
4348  /* search_clause and cycle_clause are not interesting here */
4349  return WALK(((CommonTableExpr *) node)->ctequery);
4350  case T_JsonOutput:
4351  {
4352  JsonOutput *out = (JsonOutput *) node;
4353 
4354  if (WALK(out->typeName))
4355  return true;
4356  if (WALK(out->returning))
4357  return true;
4358  }
4359  break;
4360  case T_JsonKeyValue:
4361  {
4362  JsonKeyValue *jkv = (JsonKeyValue *) node;
4363 
4364  if (WALK(jkv->key))
4365  return true;
4366  if (WALK(jkv->value))
4367  return true;
4368  }
4369  break;
4370  case T_JsonObjectConstructor:
4371  {
4373 
4374  if (WALK(joc->output))
4375  return true;
4376  if (WALK(joc->exprs))
4377  return true;
4378  }
4379  break;
4380  case T_JsonArrayConstructor:
4381  {
4383 
4384  if (WALK(jac->output))
4385  return true;
4386  if (WALK(jac->exprs))
4387  return true;
4388  }
4389  break;
4390  case T_JsonAggConstructor:
4391  {
4392  JsonAggConstructor *ctor = (JsonAggConstructor *) node;
4393 
4394  if (WALK(ctor->output))
4395  return true;
4396  if (WALK(ctor->agg_order))
4397  return true;
4398  if (WALK(ctor->agg_filter))
4399  return true;
4400  if (WALK(ctor->over))
4401  return true;
4402  }
4403  break;
4404  case T_JsonObjectAgg:
4405  {
4406  JsonObjectAgg *joa = (JsonObjectAgg *) node;
4407 
4408  if (WALK(joa->constructor))
4409  return true;
4410  if (WALK(joa->arg))
4411  return true;
4412  }
4413  break;
4414  case T_JsonArrayAgg:
4415  {
4416  JsonArrayAgg *jaa = (JsonArrayAgg *) node;
4417 
4418  if (WALK(jaa->constructor))