PostgreSQL Source Code  git master
nodeFuncs.c File Reference
#include "postgres.h"
#include "catalog/pg_collation.h"
#include "catalog/pg_type.h"
#include "miscadmin.h"
#include "nodes/execnodes.h"
#include "nodes/nodeFuncs.h"
#include "nodes/pathnodes.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
Include dependency graph for nodeFuncs.c:

Go to the source code of this file.

Macros

#define WALK(n)   walker((Node *) (n), context)
 
#define LIST_WALK(l)   expression_tree_walker_impl((Node *) (l), walker, context)
 
#define FLATCOPY(newnode, node, nodetype)
 
#define MUTATE(newfield, oldfield, fieldtype)    ( (newfield) = (fieldtype) mutator((Node *) (oldfield), context) )
 
#define PSWALK(n)   walker(n, context)
 

Functions

static bool expression_returns_set_walker (Node *node, void *context)
 
static int leftmostLoc (int loc1, int loc2)
 
static bool fix_opfuncids_walker (Node *node, void *context)
 
static bool planstate_walk_subplans (List *plans, planstate_tree_walker_callback walker, void *context)
 
static bool planstate_walk_members (PlanState **planstates, int nplans, planstate_tree_walker_callback walker, void *context)
 
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)
 
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)
 
bool query_tree_walker_impl (Query *query, tree_walker_callback walker, void *context, int flags)
 
bool range_table_walker_impl (List *rtable, tree_walker_callback walker, void *context, int flags)
 
bool range_table_entry_walker_impl (RangeTblEntry *rte, tree_walker_callback walker, void *context, int flags)
 
Nodeexpression_tree_mutator_impl (Node *node, tree_mutator_callback mutator, void *context)
 
Queryquery_tree_mutator_impl (Query *query, tree_mutator_callback mutator, void *context, int flags)
 
Listrange_table_mutator_impl (List *rtable, tree_mutator_callback mutator, 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 (PlanState *planstate, planstate_tree_walker_callback walker, void *context)
 

Macro Definition Documentation

◆ FLATCOPY

#define FLATCOPY (   newnode,
  node,
  nodetype 
)
Value:
( (newnode) = (nodetype *) palloc(sizeof(nodetype)), \
memcpy((newnode), (node), sizeof(nodetype)) )
void * palloc(Size size)
Definition: mcxt.c:1317

◆ LIST_WALK

#define LIST_WALK (   l)    expression_tree_walker_impl((Node *) (l), walker, context)

◆ MUTATE

#define MUTATE (   newfield,
  oldfield,
  fieldtype 
)     ( (newfield) = (fieldtype) mutator((Node *) (oldfield), context) )

◆ PSWALK

#define PSWALK (   n)    walker(n, context)

◆ WALK

#define WALK (   n)    walker((Node *) (n), context)

Function Documentation

◆ applyRelabelType()

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

Definition at line 631 of file nodeFuncs.c.

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

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

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

◆ check_functions_in_node()

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

Definition at line 1900 of file nodeFuncs.c.

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

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

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

◆ exprCollation()

Oid exprCollation ( const Node expr)

Definition at line 816 of file nodeFuncs.c.

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

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

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

◆ expression_returns_set()

◆ expression_returns_set_walker()

static bool expression_returns_set_walker ( Node node,
void *  context 
)
static

Definition at line 764 of file nodeFuncs.c.

765 {
766  if (node == NULL)
767  return false;
768  if (IsA(node, FuncExpr))
769  {
770  FuncExpr *expr = (FuncExpr *) node;
771 
772  if (expr->funcretset)
773  return true;
774  /* else fall through to check args */
775  }
776  if (IsA(node, OpExpr))
777  {
778  OpExpr *expr = (OpExpr *) node;
779 
780  if (expr->opretset)
781  return true;
782  /* else fall through to check args */
783  }
784 
785  /*
786  * If you add any more cases that return sets, also fix
787  * expression_returns_set_rows() in clauses.c and IS_SRF_CALL() in
788  * tlist.c.
789  */
790 
791  /* Avoid recursion for some cases that parser checks not to return a set */
792  if (IsA(node, Aggref))
793  return false;
794  if (IsA(node, GroupingFunc))
795  return false;
796  if (IsA(node, WindowFunc))
797  return false;
798 
800  context);
801 }
#define expression_tree_walker(n, w, c)
Definition: nodeFuncs.h:151

References context, expression_tree_walker, and IsA.

Referenced by expression_returns_set().

◆ expression_tree_mutator_impl()

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

Definition at line 2933 of file nodeFuncs.c.

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

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

◆ expression_tree_walker_impl()

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

Definition at line 2083 of file nodeFuncs.c.

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

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

◆ exprInputCollation()

Oid exprInputCollation ( const Node expr)

Definition at line 1068 of file nodeFuncs.c.

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

References InvalidOid, and nodeTag.

Referenced by check_simple_rowfilter_expr_walker(), and resolve_polymorphic_tupdesc().

◆ exprIsLengthCoercion()

bool exprIsLengthCoercion ( const Node expr,
int32 coercedTypmod 
)

Definition at line 552 of file nodeFuncs.c.

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

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

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

◆ exprLocation()

int exprLocation ( const Node expr)

Definition at line 1380 of file nodeFuncs.c.

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

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

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

◆ exprSetCollation()

void exprSetCollation ( Node expr,
Oid  collation 
)

Definition at line 1116 of file nodeFuncs.c.

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

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

Referenced by assign_collations_walker().

◆ exprSetInputCollation()

void exprSetInputCollation ( Node expr,
Oid  inputcollation 
)

Definition at line 1316 of file nodeFuncs.c.

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

References nodeTag.

Referenced by assign_collations_walker().

◆ exprType()

Oid exprType ( const Node expr)

Definition at line 42 of file nodeFuncs.c.

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

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

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

◆ exprTypmod()

int32 exprTypmod ( const Node expr)

Definition at line 298 of file nodeFuncs.c.

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

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

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

◆ fix_opfuncids()

void fix_opfuncids ( Node node)

Definition at line 1831 of file nodeFuncs.c.

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

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

◆ fix_opfuncids_walker()

static bool fix_opfuncids_walker ( Node node,
void *  context 
)
static

Definition at line 1838 of file nodeFuncs.c.

1839 {
1840  if (node == NULL)
1841  return false;
1842  if (IsA(node, OpExpr))
1843  set_opfuncid((OpExpr *) node);
1844  else if (IsA(node, DistinctExpr))
1845  set_opfuncid((OpExpr *) node); /* rely on struct equivalence */
1846  else if (IsA(node, NullIfExpr))
1847  set_opfuncid((OpExpr *) node); /* rely on struct equivalence */
1848  else if (IsA(node, ScalarArrayOpExpr))
1851 }

References context, expression_tree_walker, IsA, set_opfuncid(), and set_sa_opfuncid().

Referenced by fix_opfuncids().

◆ leftmostLoc()

static int leftmostLoc ( int  loc1,
int  loc2 
)
static

Definition at line 1810 of file nodeFuncs.c.

1811 {
1812  if (loc1 < 0)
1813  return loc2;
1814  else if (loc2 < 0)
1815  return loc1;
1816  else
1817  return Min(loc1, loc2);
1818 }
#define Min(x, y)
Definition: c.h:1004

References Min.

Referenced by exprLocation().

◆ planstate_tree_walker_impl()

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

Definition at line 4676 of file nodeFuncs.c.

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

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

◆ planstate_walk_members()

static bool planstate_walk_members ( PlanState **  planstates,
int  nplans,
planstate_tree_walker_callback  walker,
void *  context 
)
static

Definition at line 4782 of file nodeFuncs.c.

4785 {
4786  int j;
4787 
4788  for (j = 0; j < nplans; j++)
4789  {
4790  if (PSWALK(planstates[j]))
4791  return true;
4792  }
4793 
4794  return false;
4795 }
int j
Definition: isn.c:74

References j, and PSWALK.

Referenced by planstate_tree_walker_impl().

◆ planstate_walk_subplans()

static bool planstate_walk_subplans ( List plans,
planstate_tree_walker_callback  walker,
void *  context 
)
static

Definition at line 4760 of file nodeFuncs.c.

4763 {
4764  ListCell *lc;
4765 
4766  foreach(lc, plans)
4767  {
4769 
4770  if (PSWALK(sps->planstate))
4771  return true;
4772  }
4773 
4774  return false;
4775 }
struct PlanState * planstate
Definition: execnodes.h:961

References lfirst_node, SubPlanState::planstate, and PSWALK.

Referenced by planstate_tree_walker_impl().

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

3937 {
3938  if (node && IsA(node, Query))
3939  return (Node *) query_tree_mutator((Query *) node,
3940  mutator,
3941  context,
3942  flags);
3943  else
3944  return mutator(node, context);
3945 }
#define query_tree_mutator(q, m, c, f)
Definition: nodeFuncs.h:158

References context, IsA, and query_tree_mutator.

◆ query_or_expression_tree_walker_impl()

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

Definition at line 3910 of file nodeFuncs.c.

3914 {
3915  if (node && IsA(node, Query))
3916  return query_tree_walker((Query *) node,
3917  walker,
3918  context,
3919  flags);
3920  else
3921  return WALK(node);
3922 }
#define query_tree_walker(q, w, c, f)
Definition: nodeFuncs.h:156

References context, IsA, query_tree_walker, and WALK.

◆ query_tree_mutator_impl()

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

Definition at line 3750 of file nodeFuncs.c.

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

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

◆ query_tree_walker_impl()

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

Definition at line 2686 of file nodeFuncs.c.

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

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

◆ range_table_entry_walker_impl()

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

Definition at line 2810 of file nodeFuncs.c.

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

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

◆ range_table_mutator_impl()

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

Definition at line 3841 of file nodeFuncs.c.

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

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

◆ range_table_walker_impl()

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

Definition at line 2789 of file nodeFuncs.c.

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

References context, lfirst_node, and range_table_entry_walker.

◆ raw_expression_tree_walker_impl()

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

Definition at line 3964 of file nodeFuncs.c.

3967 {
3968  ListCell *temp;
3969 
3970  /*
3971  * The walker has already visited the current node, and so we need only
3972  * recurse into any sub-nodes it has.
3973  */
3974  if (node == NULL)
3975  return false;
3976 
3977  /* Guard against stack overflow due to overly complex expressions */
3979 
3980  switch (nodeTag(node))
3981  {
3982  case T_JsonFormat:
3983  case T_SetToDefault:
3984  case T_CurrentOfExpr:
3985  case T_SQLValueFunction:
3986  case T_Integer:
3987  case T_Float:
3988  case T_Boolean:
3989  case T_String:
3990  case T_BitString:
3991  case T_ParamRef:
3992  case T_A_Const:
3993  case T_A_Star:
3994  case T_MergeSupportFunc:
3995  /* primitive node types with no subnodes */
3996  break;
3997  case T_Alias:
3998  /* we assume the colnames list isn't interesting */
3999  break;
4000  case T_RangeVar:
4001  return WALK(((RangeVar *) node)->alias);
4002  case T_GroupingFunc:
4003  return WALK(((GroupingFunc *) node)->args);
4004  case T_SubLink:
4005  {
4006  SubLink *sublink = (SubLink *) node;
4007 
4008  if (WALK(sublink->testexpr))
4009  return true;
4010  /* we assume the operName is not interesting */
4011  if (WALK(sublink->subselect))
4012  return true;
4013  }
4014  break;
4015  case T_CaseExpr:
4016  {
4017  CaseExpr *caseexpr = (CaseExpr *) node;
4018 
4019  if (WALK(caseexpr->arg))
4020  return true;
4021  /* we assume walker doesn't care about CaseWhens, either */
4022  foreach(temp, caseexpr->args)
4023  {
4024  CaseWhen *when = lfirst_node(CaseWhen, temp);
4025 
4026  if (WALK(when->expr))
4027  return true;
4028  if (WALK(when->result))
4029  return true;
4030  }
4031  if (WALK(caseexpr->defresult))
4032  return true;
4033  }
4034  break;
4035  case T_RowExpr:
4036  /* Assume colnames isn't interesting */
4037  return WALK(((RowExpr *) node)->args);
4038  case T_CoalesceExpr:
4039  return WALK(((CoalesceExpr *) node)->args);
4040  case T_MinMaxExpr:
4041  return WALK(((MinMaxExpr *) node)->args);
4042  case T_XmlExpr:
4043  {
4044  XmlExpr *xexpr = (XmlExpr *) node;
4045 
4046  if (WALK(xexpr->named_args))
4047  return true;
4048  /* we assume walker doesn't care about arg_names */
4049  if (WALK(xexpr->args))
4050  return true;
4051  }
4052  break;
4053  case T_JsonReturning:
4054  return WALK(((JsonReturning *) node)->format);
4055  case T_JsonValueExpr:
4056  {
4057  JsonValueExpr *jve = (JsonValueExpr *) node;
4058 
4059  if (WALK(jve->raw_expr))
4060  return true;
4061  if (WALK(jve->formatted_expr))
4062  return true;
4063  if (WALK(jve->format))
4064  return true;
4065  }
4066  break;
4067  case T_JsonParseExpr:
4068  {
4069  JsonParseExpr *jpe = (JsonParseExpr *) node;
4070 
4071  if (WALK(jpe->expr))
4072  return true;
4073  if (WALK(jpe->output))
4074  return true;
4075  }
4076  break;
4077  case T_JsonScalarExpr:
4078  {
4079  JsonScalarExpr *jse = (JsonScalarExpr *) node;
4080 
4081  if (WALK(jse->expr))
4082  return true;
4083  if (WALK(jse->output))
4084  return true;
4085  }
4086  break;
4087  case T_JsonSerializeExpr:
4088  {
4089  JsonSerializeExpr *jse = (JsonSerializeExpr *) node;
4090 
4091  if (WALK(jse->expr))
4092  return true;
4093  if (WALK(jse->output))
4094  return true;
4095  }
4096  break;
4097  case T_JsonConstructorExpr:
4098  {
4099  JsonConstructorExpr *ctor = (JsonConstructorExpr *) node;
4100 
4101  if (WALK(ctor->args))
4102  return true;
4103  if (WALK(ctor->func))
4104  return true;
4105  if (WALK(ctor->coercion))
4106  return true;
4107  if (WALK(ctor->returning))
4108  return true;
4109  }
4110  break;
4111  case T_JsonIsPredicate:
4112  return WALK(((JsonIsPredicate *) node)->expr);
4113  case T_JsonArgument:
4114  return WALK(((JsonArgument *) node)->val);
4115  case T_JsonFuncExpr:
4116  {
4117  JsonFuncExpr *jfe = (JsonFuncExpr *) node;
4118 
4119  if (WALK(jfe->context_item))
4120  return true;
4121  if (WALK(jfe->pathspec))
4122  return true;
4123  if (WALK(jfe->passing))
4124  return true;
4125  if (WALK(jfe->output))
4126  return true;
4127  if (WALK(jfe->on_empty))
4128  return true;
4129  if (WALK(jfe->on_error))
4130  return true;
4131  }
4132  break;
4133  case T_JsonBehavior:
4134  {
4135  JsonBehavior *jb = (JsonBehavior *) node;
4136 
4137  if (WALK(jb->expr))
4138  return true;
4139  }
4140  break;
4141  case T_JsonTable:
4142  {
4143  JsonTable *jt = (JsonTable *) node;
4144 
4145  if (WALK(jt->context_item))
4146  return true;
4147  if (WALK(jt->pathspec))
4148  return true;
4149  if (WALK(jt->passing))
4150  return true;
4151  if (WALK(jt->columns))
4152  return true;
4153  if (WALK(jt->on_error))
4154  return true;
4155  }
4156  break;
4157  case T_JsonTableColumn:
4158  {
4159  JsonTableColumn *jtc = (JsonTableColumn *) node;
4160 
4161  if (WALK(jtc->typeName))
4162  return true;
4163  if (WALK(jtc->on_empty))
4164  return true;
4165  if (WALK(jtc->on_error))
4166  return true;
4167  if (WALK(jtc->columns))
4168  return true;
4169  }
4170  break;
4171  case T_JsonTablePathSpec:
4172  return WALK(((JsonTablePathSpec *) node)->string);
4173  case T_NullTest:
4174  return WALK(((NullTest *) node)->arg);
4175  case T_BooleanTest:
4176  return WALK(((BooleanTest *) node)->arg);
4177  case T_JoinExpr:
4178  {
4179  JoinExpr *join = (JoinExpr *) node;
4180 
4181  if (WALK(join->larg))
4182  return true;
4183  if (WALK(join->rarg))
4184  return true;
4185  if (WALK(join->quals))
4186  return true;
4187  if (WALK(join->alias))
4188  return true;
4189  /* using list is deemed uninteresting */
4190  }
4191  break;
4192  case T_IntoClause:
4193  {
4194  IntoClause *into = (IntoClause *) node;
4195 
4196  if (WALK(into->rel))
4197  return true;
4198  /* colNames, options are deemed uninteresting */
4199  /* viewQuery should be null in raw parsetree, but check it */
4200  if (WALK(into->viewQuery))
4201  return true;
4202  }
4203  break;
4204  case T_List:
4205  foreach(temp, (List *) node)
4206  {
4207  if (WALK((Node *) lfirst(temp)))
4208  return true;
4209  }
4210  break;
4211  case T_InsertStmt:
4212  {
4213  InsertStmt *stmt = (InsertStmt *) node;
4214 
4215  if (WALK(stmt->relation))
4216  return true;
4217  if (WALK(stmt->cols))
4218  return true;
4219  if (WALK(stmt->selectStmt))
4220  return true;
4221  if (WALK(stmt->onConflictClause))
4222  return true;
4223  if (WALK(stmt->returningList))
4224  return true;
4225  if (WALK(stmt->withClause))
4226  return true;
4227  }
4228  break;
4229  case T_DeleteStmt:
4230  {
4231  DeleteStmt *stmt = (DeleteStmt *) node;
4232 
4233  if (WALK(stmt->relation))
4234  return true;
4235  if (WALK(stmt->usingClause))
4236  return true;
4237  if (WALK(stmt->whereClause))
4238  return true;
4239  if (WALK(stmt->returningList))
4240  return true;
4241  if (WALK(stmt->withClause))
4242  return true;
4243  }
4244  break;
4245  case T_UpdateStmt:
4246  {
4247  UpdateStmt *stmt = (UpdateStmt *) node;
4248 
4249  if (WALK(stmt->relation))
4250  return true;
4251  if (WALK(stmt->targetList))
4252  return true;
4253  if (WALK(stmt->whereClause))
4254  return true;
4255  if (WALK(stmt->fromClause))
4256  return true;
4257  if (WALK(stmt->returningList))
4258  return true;
4259  if (WALK(stmt->withClause))
4260  return true;
4261  }
4262  break;
4263  case T_MergeStmt:
4264  {
4265  MergeStmt *stmt = (MergeStmt *) node;
4266 
4267  if (WALK(stmt->relation))
4268  return true;
4269  if (WALK(stmt->sourceRelation))
4270  return true;
4271  if (WALK(stmt->joinCondition))
4272  return true;
4273  if (WALK(stmt->mergeWhenClauses))
4274  return true;
4275  if (WALK(stmt->returningList))
4276  return true;
4277  if (WALK(stmt->withClause))
4278  return true;
4279  }
4280  break;
4281  case T_MergeWhenClause:
4282  {
4283  MergeWhenClause *mergeWhenClause = (MergeWhenClause *) node;
4284 
4285  if (WALK(mergeWhenClause->condition))
4286  return true;
4287  if (WALK(mergeWhenClause->targetList))
4288  return true;
4289  if (WALK(mergeWhenClause->values))
4290  return true;
4291  }
4292  break;
4293  case T_SelectStmt:
4294  {
4295  SelectStmt *stmt = (SelectStmt *) node;
4296 
4297  if (WALK(stmt->distinctClause))
4298  return true;
4299  if (WALK(stmt->intoClause))
4300  return true;
4301  if (WALK(stmt->targetList))
4302  return true;
4303  if (WALK(stmt->fromClause))
4304  return true;
4305  if (WALK(stmt->whereClause))
4306  return true;
4307  if (WALK(stmt->groupClause))
4308  return true;
4309  if (WALK(stmt->havingClause))
4310  return true;
4311  if (WALK(stmt->windowClause))
4312  return true;
4313  if (WALK(stmt->valuesLists))
4314  return true;
4315  if (WALK(stmt->sortClause))
4316  return true;
4317  if (WALK(stmt->limitOffset))
4318  return true;
4319  if (WALK(stmt->limitCount))
4320  return true;
4321  if (WALK(stmt->lockingClause))
4322  return true;
4323  if (WALK(stmt->withClause))
4324  return true;
4325  if (WALK(stmt->larg))
4326  return true;
4327  if (WALK(stmt->rarg))
4328  return true;
4329  }
4330  break;
4331  case T_PLAssignStmt:
4332  {
4333  PLAssignStmt *stmt = (PLAssignStmt *) node;
4334 
4335  if (WALK(stmt->indirection))
4336  return true;
4337  if (WALK(stmt->val))
4338  return true;
4339  }
4340  break;
4341  case T_A_Expr:
4342  {
4343  A_Expr *expr = (A_Expr *) node;
4344 
4345  if (WALK(expr->lexpr))
4346  return true;
4347  if (WALK(expr->rexpr))
4348  return true;
4349  /* operator name is deemed uninteresting */
4350  }
4351  break;
4352  case T_BoolExpr:
4353  {
4354  BoolExpr *expr = (BoolExpr *) node;
4355 
4356  if (WALK(expr->args))
4357  return true;
4358  }
4359  break;
4360  case T_ColumnRef:
4361  /* we assume the fields contain nothing interesting */
4362  break;
4363  case T_FuncCall:
4364  {
4365  FuncCall *fcall = (FuncCall *) node;
4366 
4367  if (WALK(fcall->args))
4368  return true;
4369  if (WALK(fcall->agg_order))
4370  return true;
4371  if (WALK(fcall->agg_filter))
4372  return true;
4373  if (WALK(fcall->over))
4374  return true;
4375  /* function name is deemed uninteresting */
4376  }
4377  break;
4378  case T_NamedArgExpr:
4379  return WALK(((NamedArgExpr *) node)->arg);
4380  case T_A_Indices:
4381  {
4382  A_Indices *indices = (A_Indices *) node;
4383 
4384  if (WALK(indices->lidx))
4385  return true;
4386  if (WALK(indices->uidx))
4387  return true;
4388  }
4389  break;
4390  case T_A_Indirection:
4391  {
4392  A_Indirection *indir = (A_Indirection *) node;
4393 
4394  if (WALK(indir->arg))
4395  return true;
4396  if (WALK(indir->indirection))
4397  return true;
4398  }
4399  break;
4400  case T_A_ArrayExpr:
4401  return WALK(((A_ArrayExpr *) node)->elements);
4402  case T_ResTarget:
4403  {
4404  ResTarget *rt = (ResTarget *) node;
4405 
4406  if (WALK(rt->indirection))
4407  return true;
4408  if (WALK(rt->val))
4409  return true;
4410  }
4411  break;
4412  case T_MultiAssignRef:
4413  return WALK(((MultiAssignRef *) node)->source);
4414  case T_TypeCast:
4415  {
4416  TypeCast *tc = (TypeCast *) node;
4417 
4418  if (WALK(tc->arg))
4419  return true;
4420  if (WALK(tc->typeName))
4421  return true;
4422  }
4423  break;
4424  case T_CollateClause:
4425  return WALK(((CollateClause *) node)->arg);
4426  case T_SortBy:
4427  return WALK(((SortBy *) node)->node);
4428  case T_WindowDef:
4429  {
4430  WindowDef *wd = (WindowDef *) node;
4431 
4432  if (WALK(wd->partitionClause))
4433  return true;
4434  if (WALK(wd->orderClause))
4435  return true;
4436  if (WALK(wd->startOffset))
4437  return true;
4438  if (WALK(wd->endOffset))
4439  return true;
4440  }
4441  break;
4442  case T_RangeSubselect:
4443  {
4444  RangeSubselect *rs = (RangeSubselect *) node;
4445 
4446  if (WALK(rs->subquery))
4447  return true;
4448  if (WALK(rs->alias))
4449  return true;
4450  }
4451  break;
4452  case T_RangeFunction:
4453  {
4454  RangeFunction *rf = (RangeFunction *) node;
4455 
4456  if (WALK(rf->functions))
4457  return true;
4458  if (WALK(rf->alias))
4459  return true;
4460  if (WALK(rf->coldeflist))
4461  return true;
4462  }
4463  break;
4464  case T_RangeTableSample:
4465  {
4466  RangeTableSample *rts = (RangeTableSample *) node;
4467 
4468  if (WALK(rts->relation))
4469  return true;
4470  /* method name is deemed uninteresting */
4471  if (WALK(rts->args))
4472  return true;
4473  if (WALK(rts->repeatable))
4474  return true;
4475  }
4476  break;
4477  case T_RangeTableFunc:
4478  {
4479  RangeTableFunc *rtf = (RangeTableFunc *) node;
4480 
4481  if (WALK(rtf->docexpr))
4482  return true;
4483  if (WALK(rtf->rowexpr))
4484  return true;
4485  if (WALK(rtf->namespaces))
4486  return true;
4487  if (WALK(rtf->columns))
4488  return true;
4489  if (WALK(rtf->alias))
4490  return true;
4491  }
4492  break;
4493  case T_RangeTableFuncCol:
4494  {
4495  RangeTableFuncCol *rtfc = (RangeTableFuncCol *) node;
4496 
4497  if (WALK(rtfc->colexpr))
4498  return true;
4499  if (WALK(rtfc->coldefexpr))
4500  return true;
4501  }
4502  break;
4503  case T_TypeName:
4504  {
4505  TypeName *tn = (TypeName *) node;
4506 
4507  if (WALK(tn->typmods))
4508  return true;
4509  if (WALK(tn->arrayBounds))
4510  return true;
4511  /* type name itself is deemed uninteresting */
4512  }
4513  break;
4514  case T_ColumnDef:
4515  {
4516  ColumnDef *coldef = (ColumnDef *) node;
4517 
4518  if (WALK(coldef->typeName))
4519  return true;
4520  if (WALK(coldef->raw_default))
4521  return true;
4522  if (WALK(coldef->collClause))
4523  return true;
4524  /* for now, constraints are ignored */
4525  }
4526  break;
4527  case T_IndexElem:
4528  {
4529  IndexElem *indelem = (IndexElem *) node;
4530 
4531  if (WALK(indelem->expr))
4532  return true;
4533  /* collation and opclass names are deemed uninteresting */
4534  }
4535  break;
4536  case T_GroupingSet:
4537  return WALK(((GroupingSet *) node)->content);
4538  case T_LockingClause:
4539  return WALK(((LockingClause *) node)->lockedRels);
4540  case T_XmlSerialize:
4541  {
4542  XmlSerialize *xs = (XmlSerialize *) node;
4543 
4544  if (WALK(xs->expr))
4545  return true;
4546  if (WALK(xs->typeName))
4547  return true;
4548  }
4549  break;
4550  case T_WithClause:
4551  return WALK(((WithClause *) node)->ctes);
4552  case T_InferClause:
4553  {
4554  InferClause *stmt = (InferClause *) node;
4555 
4556  if (WALK(stmt->indexElems))
4557  return true;
4558  if (WALK(stmt->whereClause))
4559  return true;
4560  }
4561  break;
4562  case T_OnConflictClause:
4563  {
4565 
4566  if (WALK(stmt->infer))
4567  return true;
4568  if (WALK(stmt->targetList))
4569  return true;
4570  if (WALK(stmt->whereClause))
4571  return true;
4572  }
4573  break;
4574  case T_CommonTableExpr:
4575  /* search_clause and cycle_clause are not interesting here */
4576  return WALK(((CommonTableExpr *) node)->ctequery);
4577  case T_JsonOutput:
4578  {
4579  JsonOutput *out = (JsonOutput *) node;
4580 
4581  if (WALK(out->typeName))
4582  return true;
4583  if (WALK(out->returning))
4584  return true;
4585  }
4586  break;
4587  case T_JsonKeyValue:
4588  {
4589  JsonKeyValue *jkv = (JsonKeyValue *) node;
4590 
4591  if (WALK(jkv->key))
4592  return true;
4593  if (WALK(jkv->value))
4594  return true;
4595  }
4596  break;
4597  case T_JsonObjectConstructor:
4598  {
4600 
4601  if (WALK(joc->output))
4602  return true;
4603  if (WALK(joc->exprs))
4604  return true;
4605  }
4606  break;
4607  case T_JsonArrayConstructor:
4608  {
4610 
4611  if (WALK(jac->output))
4612  return true;
4613  if (WALK(jac->exprs))
4614  return true;
4615  }
4616  break;
4617  case T_JsonAggConstructor:
4618  {
4619  JsonAggConstructor *ctor = (JsonAggConstructor *) node;
4620 
4621  if (WALK(ctor->output))
4622  return true;
4623  if (WALK(ctor->agg_order))
4624  return true;
4625  if (WALK(ctor->agg_filter))
4626  return true;
4627  if (WALK(ctor->over))
4628  return true;
4629  }
4630  break;
4631  case T_JsonObjectAgg:
4632  {
4633  JsonObjectAgg *joa = (JsonObjectAgg *) node;
4634 
4635  if (WALK(joa->constructor))
4636  return true;
4637  if (WALK(joa->arg))
4638  return true;
4639  }
4640  break;
4641  case T_JsonArrayAgg:
4642  {
4643  JsonArrayAgg *jaa = (JsonArrayAgg *) node;
4644 
4645  if (WALK(jaa->constructor))
4646  return true;
4647  if (WALK(jaa->arg))
4648  return true;
4649  }
4650  break;
4651  case T_JsonArrayQueryConstructor:
4652  {
4654 
4655  if (WALK(jaqc->output))
4656  return true;
4657  if (WALK(jaqc->query))
4658  return true;
4659  }
4660  break;
4661  default:
4662  elog(ERROR, "unrecognized node type: %d",
4663  (int) nodeTag(node));
4664  break;
4665  }
4666  return false;
4667 }
#define stmt
Definition: indent_codes.h:59
long val
Definition: informix.c:670
static char format
Node * rexpr
Definition: parsenodes.h:337
Node * uidx
Definition: parsenodes.h:461
Node * lidx
Definition: parsenodes.h:460
List * indirection
Definition: parsenodes.h:483
CollateClause * collClause
Definition: parsenodes.h:741
TypeName * typeName
Definition: parsenodes.h:727
Node * raw_default
Definition: parsenodes.h:735
Node * agg_filter
Definition: parsenodes.h:429
List * agg_order
Definition: parsenodes.h:428
List * args
Definition: parsenodes.h:427
struct WindowDef * over
Definition: parsenodes.h:430
Node * expr
Definition: parsenodes.h:784
RangeVar * rel
Definition: primnodes.h:162
JsonOutput * output
Definition: parsenodes.h:1968
JsonOutput * output
Definition: parsenodes.h:1941
JsonOutput * output
Definition: parsenodes.h:1797
List * passing
Definition: parsenodes.h:1796
JsonBehavior * on_empty
Definition: parsenodes.h:1798
Node * pathspec
Definition: parsenodes.h:1795
JsonBehavior * on_error
Definition: parsenodes.h:1799
JsonValueExpr * context_item
Definition: parsenodes.h:1794
JsonOutput * output
Definition: parsenodes.h:1927
JsonReturning * returning
Definition: parsenodes.h:1758
TypeName * typeName
Definition: parsenodes.h:1757
JsonValueExpr * expr
Definition: parsenodes.h:1889
JsonOutput * output
Definition: parsenodes.h:1890
JsonOutput * output
Definition: parsenodes.h:1903
JsonOutput * output
Definition: parsenodes.h:1915
JsonValueExpr * expr
Definition: parsenodes.h:1914
JsonBehavior * on_empty
Definition: parsenodes.h:1865
JsonBehavior * on_error
Definition: parsenodes.h:1866
TypeName * typeName
Definition: parsenodes.h:1859
JsonBehavior * on_error
Definition: parsenodes.h:1831
List * columns
Definition: parsenodes.h:1830
JsonTablePathSpec * pathspec
Definition: parsenodes.h:1828
List * passing
Definition: parsenodes.h:1829
JsonValueExpr * context_item
Definition: parsenodes.h:1827
Alias * alias
Definition: parsenodes.h:644
List * coldeflist
Definition: parsenodes.h:645
List * functions
Definition: parsenodes.h:643
Node * subquery
Definition: parsenodes.h:619
Alias * alias
Definition: parsenodes.h:620
List * namespaces
Definition: parsenodes.h:661
Node * docexpr
Definition: parsenodes.h:659
Node * rowexpr
Definition: parsenodes.h:660
List * columns
Definition: parsenodes.h:662
Alias * alias
Definition: parsenodes.h:663
Node * val
Definition: parsenodes.h:519
List * indirection
Definition: parsenodes.h:518
List * arrayBounds
Definition: parsenodes.h:274
List * typmods
Definition: parsenodes.h:272
List * orderClause
Definition: parsenodes.h:567
List * partitionClause
Definition: parsenodes.h:566
Node * startOffset
Definition: parsenodes.h:569
Node * endOffset
Definition: parsenodes.h:570
TypeName * typeName
Definition: parsenodes.h:847
Node * expr
Definition: parsenodes.h:846

References FuncCall::agg_filter, JsonAggConstructor::agg_filter, FuncCall::agg_order, JsonAggConstructor::agg_order, RangeSubselect::alias, RangeFunction::alias, RangeTableFunc::alias, arg, TypeCast::arg, A_Indirection::arg, JsonObjectAgg::arg, JsonArrayAgg::arg, CaseExpr::arg, generate_unaccent_rules::args, FuncCall::args, RangeTableSample::args, BoolExpr::args, CaseExpr::args, XmlExpr::args, JsonConstructorExpr::args, TypeName::arrayBounds, check_stack_depth(), JsonConstructorExpr::coercion, RangeTableFuncCol::coldefexpr, RangeFunction::coldeflist, RangeTableFuncCol::colexpr, ColumnDef::collClause, RangeTableFunc::columns, JsonTable::columns, JsonTableColumn::columns, MergeWhenClause::condition, JsonObjectAgg::constructor, JsonArrayAgg::constructor, JsonFuncExpr::context_item, JsonTable::context_item, CaseExpr::defresult, RangeTableFunc::docexpr, elog, WindowDef::endOffset, ERROR, IndexElem::expr, XmlSerialize::expr, JsonParseExpr::expr, JsonScalarExpr::expr, JsonSerializeExpr::expr, JsonBehavior::expr, JsonObjectConstructor::exprs, JsonArrayConstructor::exprs, format, JsonValueExpr::format, JsonValueExpr::formatted_expr, JsonConstructorExpr::func, RangeFunction::functions, A_Indirection::indirection, ResTarget::indirection, JsonKeyValue::key, JoinExpr::larg, A_Expr::lexpr, lfirst, lfirst_node, A_Indices::lidx, XmlExpr::named_args, RangeTableFunc::namespaces, nodeTag, JsonFuncExpr::on_empty, JsonTableColumn::on_empty, JsonFuncExpr::on_error, JsonTable::on_error, JsonTableColumn::on_error, WindowDef::orderClause, JsonFuncExpr::output, JsonParseExpr::output, JsonScalarExpr::output, JsonSerializeExpr::output, JsonObjectConstructor::output, JsonArrayConstructor::output, JsonArrayQueryConstructor::output, JsonAggConstructor::output, FuncCall::over, JsonAggConstructor::over, WindowDef::partitionClause, JsonFuncExpr::passing, JsonTable::passing, JsonFuncExpr::pathspec, JsonTable::pathspec, JoinExpr::quals, JsonArrayQueryConstructor::query, JoinExpr::rarg, ColumnDef::raw_default, JsonValueExpr::raw_expr, IntoClause::rel, RangeTableSample::relation, RangeTableSample::repeatable, JsonOutput::returning, JsonConstructorExpr::returning, A_Expr::rexpr, RangeTableFunc::rowexpr, source, WindowDef::startOffset, stmt, RangeSubselect::subquery, SubLink::subselect, MergeWhenClause::targetList, SubLink::testexpr, TypeCast::typeName, ColumnDef::typeName, XmlSerialize::typeName, JsonOutput::typeName, JsonTableColumn::typeName, TypeName::typmods, A_Indices::uidx, ResTarget::val, val, JsonKeyValue::value, MergeWhenClause::values, and WALK.

◆ relabel_to_typmod()

Node* relabel_to_typmod ( Node expr,
int32  typmod 
)

Definition at line 684 of file nodeFuncs.c.

685 {
686  return applyRelabelType(expr, exprType(expr), typmod, exprCollation(expr),
687  COERCE_EXPLICIT_CAST, -1, false);
688 }
Node * applyRelabelType(Node *arg, Oid rtype, int32 rtypmod, Oid rcollid, CoercionForm rformat, int rlocation, bool overwrite_ok)
Definition: nodeFuncs.c:631

References applyRelabelType(), COERCE_EXPLICIT_CAST, exprCollation(), and exprType().

Referenced by interval_support(), numeric_support(), TemporalSimplify(), varbit_support(), and varchar_support().

◆ set_opfuncid()

◆ set_sa_opfuncid()

void set_sa_opfuncid ( ScalarArrayOpExpr opexpr)

Definition at line 1873 of file nodeFuncs.c.

1874 {
1875  if (opexpr->opfuncid == InvalidOid)
1876  opexpr->opfuncid = get_opcode(opexpr->opno);
1877 }

References get_opcode(), InvalidOid, and ScalarArrayOpExpr::opno.

Referenced by check_functions_in_node(), cost_qual_eval_walker(), eval_const_expressions_mutator(), fix_expr_common(), fix_opfuncids_walker(), and is_strict_saop().

◆ strip_implicit_coercions()

Node* strip_implicit_coercions ( Node node)

Definition at line 700 of file nodeFuncs.c.

701 {
702  if (node == NULL)
703  return NULL;
704  if (IsA(node, FuncExpr))
705  {
706  FuncExpr *f = (FuncExpr *) node;
707 
708  if (f->funcformat == COERCE_IMPLICIT_CAST)
710  }
711  else if (IsA(node, RelabelType))
712  {
713  RelabelType *r = (RelabelType *) node;
714 
715  if (r->relabelformat == COERCE_IMPLICIT_CAST)
716  return strip_implicit_coercions((Node *) r->arg);
717  }
718  else if (IsA(node, CoerceViaIO))
719  {
720  CoerceViaIO *c = (CoerceViaIO *) node;
721 
722  if (c->coerceformat == COERCE_IMPLICIT_CAST)
723  return strip_implicit_coercions((Node *) c->arg);
724  }
725  else if (IsA(node, ArrayCoerceExpr))
726  {
727  ArrayCoerceExpr *c = (ArrayCoerceExpr *) node;
728 
729  if (c->coerceformat == COERCE_IMPLICIT_CAST)
730  return strip_implicit_coercions((Node *) c->arg);
731  }
732  else if (IsA(node, ConvertRowtypeExpr))
733  {
735 
736  if (c->convertformat == COERCE_IMPLICIT_CAST)
737  return strip_implicit_coercions((Node *) c->arg);
738  }
739  else if (IsA(node, CoerceToDomain))
740  {
741  CoerceToDomain *c = (CoerceToDomain *) node;
742 
743  if (c->coercionformat == COERCE_IMPLICIT_CAST)
744  return strip_implicit_coercions((Node *) c->arg);
745  }
746  return node;
747 }
Node * strip_implicit_coercions(Node *node)
Definition: nodeFuncs.c:700
char * c

References RelabelType::arg, FuncExpr::args, COERCE_IMPLICIT_CAST, IsA, and linitial.

Referenced by AcquireRewriteLocks(), ATExecAlterColumnType(), findTargetlistEntrySQL99(), foreign_expr_walker(), get_rule_expr(), and get_update_query_targetlist_def().