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/makefuncs.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 FLATCOPY(newnode, node, nodetype)
 
#define CHECKFLATCOPY(newnode, node, nodetype)
 
#define MUTATE(newfield, oldfield, fieldtype)    ( (newfield) = (fieldtype) mutator((Node *) (oldfield), 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, bool(*walker)(), void *context)
 
static bool planstate_walk_members (PlanState **planstates, int nplans, bool(*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 (Node *node, bool(*walker)(), void *context)
 
bool query_tree_walker (Query *query, bool(*walker)(), void *context, int flags)
 
bool range_table_walker (List *rtable, bool(*walker)(), void *context, int flags)
 
bool range_table_entry_walker (RangeTblEntry *rte, bool(*walker)(), void *context, int flags)
 
Nodeexpression_tree_mutator (Node *node, Node *(*mutator)(), void *context)
 
Queryquery_tree_mutator (Query *query, Node *(*mutator)(), void *context, int flags)
 
Listrange_table_mutator (List *rtable, Node *(*mutator)(), void *context, int flags)
 
bool query_or_expression_tree_walker (Node *node, bool(*walker)(), void *context, int flags)
 
Nodequery_or_expression_tree_mutator (Node *node, Node *(*mutator)(), void *context, int flags)
 
bool raw_expression_tree_walker (Node *node, bool(*walker)(), void *context)
 
bool planstate_tree_walker (PlanState *planstate, bool(*walker)(), void *context)
 

Macro Definition Documentation

◆ CHECKFLATCOPY

#define CHECKFLATCOPY (   newnode,
  node,
  nodetype 
)
Value:
( AssertMacro(IsA((node), nodetype)), \
(newnode) = (nodetype *) palloc(sizeof(nodetype)), \
memcpy((newnode), (node), sizeof(nodetype)) )
#define AssertMacro(condition)
Definition: c.h:805
void * palloc(Size size)
Definition: mcxt.c:1062
#define IsA(nodeptr, _type_)
Definition: nodes.h:590

◆ FLATCOPY

#define FLATCOPY (   newnode,
  node,
  nodetype 
)
Value:
( (newnode) = (nodetype *) palloc(sizeof(nodetype)), \
memcpy((newnode), (node), sizeof(nodetype)) )

◆ MUTATE

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

Function Documentation

◆ applyRelabelType()

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

Definition at line 582 of file nodeFuncs.c.

584 {
585  /*
586  * If we find stacked RelabelTypes (eg, from foo::int::oid) we can discard
587  * all but the top one, and must do so to ensure that semantically
588  * equivalent expressions are equal().
589  */
590  while (arg && IsA(arg, RelabelType))
591  arg = (Node *) ((RelabelType *) arg)->arg;
592 
593  if (arg && IsA(arg, Const))
594  {
595  /* Modify the Const directly to preserve const-flatness. */
596  Const *con = (Const *) arg;
597 
598  if (!overwrite_ok)
599  con = copyObject(con);
600  con->consttype = rtype;
601  con->consttypmod = rtypmod;
602  con->constcollid = rcollid;
603  /* We keep the Const's original location. */
604  return (Node *) con;
605  }
606  else if (exprType(arg) == rtype &&
607  exprTypmod(arg) == rtypmod &&
608  exprCollation(arg) == rcollid)
609  {
610  /* Sometimes we find a nest of relabels that net out to nothing. */
611  return arg;
612  }
613  else
614  {
615  /* Nope, gotta have a RelabelType. */
616  RelabelType *newrelabel = makeNode(RelabelType);
617 
618  newrelabel->arg = (Expr *) arg;
619  newrelabel->resulttype = rtype;
620  newrelabel->resulttypmod = rtypmod;
621  newrelabel->resultcollid = rcollid;
622  newrelabel->relabelformat = rformat;
623  newrelabel->location = rlocation;
624  return (Node *) newrelabel;
625  }
626 }
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:41
int32 exprTypmod(const Node *expr)
Definition: nodeFuncs.c:267
Oid exprCollation(const Node *expr)
Definition: nodeFuncs.c:759
#define copyObject(obj)
Definition: nodes.h:655
#define makeNode(_type_)
Definition: nodes.h:587
void * arg
Oid constcollid
Definition: primnodes.h:217
Oid consttype
Definition: primnodes.h:215
int32 consttypmod
Definition: primnodes.h:216
Definition: nodes.h:540
int location
Definition: primnodes.h:865
Oid resultcollid
Definition: primnodes.h:863
int32 resulttypmod
Definition: primnodes.h:862
CoercionForm relabelformat
Definition: primnodes.h:864
Oid resulttype
Definition: primnodes.h:861
Expr * arg
Definition: primnodes.h:860

References arg, RelabelType::arg, Const::constcollid, Const::consttype, Const::consttypmod, copyObject, exprCollation(), exprType(), exprTypmod(), IsA, RelabelType::location, makeNode, RelabelType::relabelformat, RelabelType::resultcollid, RelabelType::resulttype, and RelabelType::resulttypmod.

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

1723 {
1724  switch (nodeTag(node))
1725  {
1726  case T_Aggref:
1727  {
1728  Aggref *expr = (Aggref *) node;
1729 
1730  if (checker(expr->aggfnoid, context))
1731  return true;
1732  }
1733  break;
1734  case T_WindowFunc:
1735  {
1736  WindowFunc *expr = (WindowFunc *) node;
1737 
1738  if (checker(expr->winfnoid, context))
1739  return true;
1740  }
1741  break;
1742  case T_FuncExpr:
1743  {
1744  FuncExpr *expr = (FuncExpr *) node;
1745 
1746  if (checker(expr->funcid, context))
1747  return true;
1748  }
1749  break;
1750  case T_OpExpr:
1751  case T_DistinctExpr: /* struct-equivalent to OpExpr */
1752  case T_NullIfExpr: /* struct-equivalent to OpExpr */
1753  {
1754  OpExpr *expr = (OpExpr *) node;
1755 
1756  /* Set opfuncid if it wasn't set already */
1757  set_opfuncid(expr);
1758  if (checker(expr->opfuncid, context))
1759  return true;
1760  }
1761  break;
1762  case T_ScalarArrayOpExpr:
1763  {
1764  ScalarArrayOpExpr *expr = (ScalarArrayOpExpr *) node;
1765 
1766  set_sa_opfuncid(expr);
1767  if (checker(expr->opfuncid, context))
1768  return true;
1769  }
1770  break;
1771  case T_CoerceViaIO:
1772  {
1773  CoerceViaIO *expr = (CoerceViaIO *) node;
1774  Oid iofunc;
1775  Oid typioparam;
1776  bool typisvarlena;
1777 
1778  /* check the result type's input function */
1780  &iofunc, &typioparam);
1781  if (checker(iofunc, context))
1782  return true;
1783  /* check the input type's output function */
1784  getTypeOutputInfo(exprType((Node *) expr->arg),
1785  &iofunc, &typisvarlena);
1786  if (checker(iofunc, context))
1787  return true;
1788  }
1789  break;
1790  case T_RowCompareExpr:
1791  {
1792  RowCompareExpr *rcexpr = (RowCompareExpr *) node;
1793  ListCell *opid;
1794 
1795  foreach(opid, rcexpr->opnos)
1796  {
1797  Oid opfuncid = get_opcode(lfirst_oid(opid));
1798 
1799  if (checker(opfuncid, context))
1800  return true;
1801  }
1802  }
1803  break;
1804  default:
1805  break;
1806  }
1807  return false;
1808 }
void getTypeOutputInfo(Oid type, Oid *typOutput, bool *typIsVarlena)
Definition: lsyscache.c:2854
RegProcedure get_opcode(Oid opno)
Definition: lsyscache.c:1256
void getTypeInputInfo(Oid type, Oid *typInput, Oid *typIOParam)
Definition: lsyscache.c:2821
void set_sa_opfuncid(ScalarArrayOpExpr *opexpr)
Definition: nodeFuncs.c:1694
void set_opfuncid(OpExpr *opexpr)
Definition: nodeFuncs.c:1683
#define nodeTag(nodeptr)
Definition: nodes.h:544
@ T_WindowFunc
Definition: nodes.h:161
@ T_OpExpr
Definition: nodes.h:165
@ T_ScalarArrayOpExpr
Definition: nodes.h:168
@ T_Aggref
Definition: nodes.h:159
@ T_CoerceViaIO
Definition: nodes.h:176
@ T_DistinctExpr
Definition: nodes.h:166
@ T_FuncExpr
Definition: nodes.h:163
@ T_RowCompareExpr
Definition: nodes.h:185
@ T_NullIfExpr
Definition: nodes.h:167
#define lfirst_oid(lc)
Definition: pg_list.h:171
unsigned int Oid
Definition: postgres_ext.h:31
Oid aggfnoid
Definition: primnodes.h:323
Expr * arg
Definition: primnodes.h:880
Oid resulttype
Definition: primnodes.h:881
Oid funcid
Definition: primnodes.h:495
Oid opfuncid
Definition: primnodes.h:543
Oid winfnoid
Definition: primnodes.h:386

References Aggref::aggfnoid, CoerceViaIO::arg, exprType(), FuncExpr::funcid, get_opcode(), getTypeInputInfo(), getTypeOutputInfo(), lfirst_oid, nodeTag, OpExpr::opfuncid, ScalarArrayOpExpr::opfuncid, RowCompareExpr::opnos, CoerceViaIO::resulttype, set_opfuncid(), set_sa_opfuncid(), T_Aggref, T_CoerceViaIO, T_DistinctExpr, T_FuncExpr, T_NullIfExpr, T_OpExpr, T_RowCompareExpr, T_ScalarArrayOpExpr, T_WindowFunc, and WindowFunc::winfnoid.

Referenced by 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 759 of file nodeFuncs.c.

760 {
761  Oid coll;
762 
763  if (!expr)
764  return InvalidOid;
765 
766  switch (nodeTag(expr))
767  {
768  case T_Var:
769  coll = ((const Var *) expr)->varcollid;
770  break;
771  case T_Const:
772  coll = ((const Const *) expr)->constcollid;
773  break;
774  case T_Param:
775  coll = ((const Param *) expr)->paramcollid;
776  break;
777  case T_Aggref:
778  coll = ((const Aggref *) expr)->aggcollid;
779  break;
780  case T_GroupingFunc:
781  coll = InvalidOid;
782  break;
783  case T_WindowFunc:
784  coll = ((const WindowFunc *) expr)->wincollid;
785  break;
786  case T_SubscriptingRef:
787  coll = ((const SubscriptingRef *) expr)->refcollid;
788  break;
789  case T_FuncExpr:
790  coll = ((const FuncExpr *) expr)->funccollid;
791  break;
792  case T_NamedArgExpr:
793  coll = exprCollation((Node *) ((const NamedArgExpr *) expr)->arg);
794  break;
795  case T_OpExpr:
796  coll = ((const OpExpr *) expr)->opcollid;
797  break;
798  case T_DistinctExpr:
799  coll = ((const DistinctExpr *) expr)->opcollid;
800  break;
801  case T_NullIfExpr:
802  coll = ((const NullIfExpr *) expr)->opcollid;
803  break;
804  case T_ScalarArrayOpExpr:
805  /* ScalarArrayOpExpr's result is boolean ... */
806  coll = InvalidOid; /* ... so it has no collation */
807  break;
808  case T_BoolExpr:
809  /* BoolExpr's result is boolean ... */
810  coll = InvalidOid; /* ... so it has no collation */
811  break;
812  case T_SubLink:
813  {
814  const SubLink *sublink = (const SubLink *) expr;
815 
816  if (sublink->subLinkType == EXPR_SUBLINK ||
817  sublink->subLinkType == ARRAY_SUBLINK)
818  {
819  /* get the collation of subselect's first target column */
820  Query *qtree = (Query *) sublink->subselect;
821  TargetEntry *tent;
822 
823  if (!qtree || !IsA(qtree, Query))
824  elog(ERROR, "cannot get collation for untransformed sublink");
825  tent = linitial_node(TargetEntry, qtree->targetList);
826  Assert(!tent->resjunk);
827  coll = exprCollation((Node *) tent->expr);
828  /* collation doesn't change if it's converted to array */
829  }
830  else
831  {
832  /* otherwise, SubLink's result is RECORD or BOOLEAN */
833  coll = InvalidOid; /* ... so it has no collation */
834  }
835  }
836  break;
837  case T_SubPlan:
838  {
839  const SubPlan *subplan = (const SubPlan *) expr;
840 
841  if (subplan->subLinkType == EXPR_SUBLINK ||
842  subplan->subLinkType == ARRAY_SUBLINK)
843  {
844  /* get the collation of subselect's first target column */
845  coll = subplan->firstColCollation;
846  /* collation doesn't change if it's converted to array */
847  }
848  else
849  {
850  /* otherwise, SubPlan's result is RECORD or BOOLEAN */
851  coll = InvalidOid; /* ... so it has no collation */
852  }
853  }
854  break;
856  {
857  const AlternativeSubPlan *asplan = (const AlternativeSubPlan *) expr;
858 
859  /* subplans should all return the same thing */
860  coll = exprCollation((Node *) linitial(asplan->subplans));
861  }
862  break;
863  case T_FieldSelect:
864  coll = ((const FieldSelect *) expr)->resultcollid;
865  break;
866  case T_FieldStore:
867  /* FieldStore's result is composite ... */
868  coll = InvalidOid; /* ... so it has no collation */
869  break;
870  case T_RelabelType:
871  coll = ((const RelabelType *) expr)->resultcollid;
872  break;
873  case T_CoerceViaIO:
874  coll = ((const CoerceViaIO *) expr)->resultcollid;
875  break;
876  case T_ArrayCoerceExpr:
877  coll = ((const ArrayCoerceExpr *) expr)->resultcollid;
878  break;
880  /* ConvertRowtypeExpr's result is composite ... */
881  coll = InvalidOid; /* ... so it has no collation */
882  break;
883  case T_CollateExpr:
884  coll = ((const CollateExpr *) expr)->collOid;
885  break;
886  case T_CaseExpr:
887  coll = ((const CaseExpr *) expr)->casecollid;
888  break;
889  case T_CaseTestExpr:
890  coll = ((const CaseTestExpr *) expr)->collation;
891  break;
892  case T_ArrayExpr:
893  coll = ((const ArrayExpr *) expr)->array_collid;
894  break;
895  case T_RowExpr:
896  /* RowExpr's result is composite ... */
897  coll = InvalidOid; /* ... so it has no collation */
898  break;
899  case T_RowCompareExpr:
900  /* RowCompareExpr's result is boolean ... */
901  coll = InvalidOid; /* ... so it has no collation */
902  break;
903  case T_CoalesceExpr:
904  coll = ((const CoalesceExpr *) expr)->coalescecollid;
905  break;
906  case T_MinMaxExpr:
907  coll = ((const MinMaxExpr *) expr)->minmaxcollid;
908  break;
909  case T_SQLValueFunction:
910  /* Returns either NAME or a non-collatable type */
911  if (((const SQLValueFunction *) expr)->type == NAMEOID)
912  coll = C_COLLATION_OID;
913  else
914  coll = InvalidOid;
915  break;
916  case T_XmlExpr:
917 
918  /*
919  * XMLSERIALIZE returns text from non-collatable inputs, so its
920  * collation is always default. The other cases return boolean or
921  * XML, which are non-collatable.
922  */
923  if (((const XmlExpr *) expr)->op == IS_XMLSERIALIZE)
924  coll = DEFAULT_COLLATION_OID;
925  else
926  coll = InvalidOid;
927  break;
928  case T_NullTest:
929  /* NullTest's result is boolean ... */
930  coll = InvalidOid; /* ... so it has no collation */
931  break;
932  case T_BooleanTest:
933  /* BooleanTest's result is boolean ... */
934  coll = InvalidOid; /* ... so it has no collation */
935  break;
936  case T_CoerceToDomain:
937  coll = ((const CoerceToDomain *) expr)->resultcollid;
938  break;
940  coll = ((const CoerceToDomainValue *) expr)->collation;
941  break;
942  case T_SetToDefault:
943  coll = ((const SetToDefault *) expr)->collation;
944  break;
945  case T_CurrentOfExpr:
946  /* CurrentOfExpr's result is boolean ... */
947  coll = InvalidOid; /* ... so it has no collation */
948  break;
949  case T_NextValueExpr:
950  /* NextValueExpr's result is an integer type ... */
951  coll = InvalidOid; /* ... so it has no collation */
952  break;
953  case T_InferenceElem:
954  coll = exprCollation((Node *) ((const InferenceElem *) expr)->expr);
955  break;
956  case T_PlaceHolderVar:
957  coll = exprCollation((Node *) ((const PlaceHolderVar *) expr)->phexpr);
958  break;
959  default:
960  elog(ERROR, "unrecognized node type: %d", (int) nodeTag(expr));
961  coll = InvalidOid; /* keep compiler quiet */
962  break;
963  }
964  return coll;
965 }
#define ERROR
Definition: elog.h:33
#define elog(elevel,...)
Definition: elog.h:218
Assert(fmt[strlen(fmt) - 1] !='\n')
@ T_FieldStore
Definition: nodes.h:174
@ T_AlternativeSubPlan
Definition: nodes.h:172
@ T_CoalesceExpr
Definition: nodes.h:186
@ T_SubLink
Definition: nodes.h:170
@ T_InferenceElem
Definition: nodes.h:197
@ T_CoerceToDomainValue
Definition: nodes.h:193
@ T_FieldSelect
Definition: nodes.h:173
@ T_ArrayExpr
Definition: nodes.h:183
@ T_CollateExpr
Definition: nodes.h:179
@ T_BoolExpr
Definition: nodes.h:169
@ T_CaseExpr
Definition: nodes.h:180
@ T_RelabelType
Definition: nodes.h:175
@ T_XmlExpr
Definition: nodes.h:189
@ T_ConvertRowtypeExpr
Definition: nodes.h:178
@ T_RowExpr
Definition: nodes.h:184
@ T_ArrayCoerceExpr
Definition: nodes.h:177
@ T_MinMaxExpr
Definition: nodes.h:187
@ T_CurrentOfExpr
Definition: nodes.h:195
@ T_BooleanTest
Definition: nodes.h:191
@ T_SubPlan
Definition: nodes.h:171
@ T_SQLValueFunction
Definition: nodes.h:188
@ T_NamedArgExpr
Definition: nodes.h:164
@ T_Const
Definition: nodes.h:157
@ T_NextValueExpr
Definition: nodes.h:196
@ T_Param
Definition: nodes.h:158
@ T_CoerceToDomain
Definition: nodes.h:192
@ T_GroupingFunc
Definition: nodes.h:160
@ T_Var
Definition: nodes.h:156
@ T_CaseTestExpr
Definition: nodes.h:182
@ T_NullTest
Definition: nodes.h:190
@ T_SubscriptingRef
Definition: nodes.h:162
@ T_SetToDefault
Definition: nodes.h:194
@ T_PlaceHolderVar
Definition: nodes.h:272
#define linitial_node(type, l)
Definition: pg_list.h:177
#define linitial(l)
Definition: pg_list.h:174
#define InvalidOid
Definition: postgres_ext.h:36
@ ARRAY_SUBLINK
Definition: primnodes.h:689
@ EXPR_SUBLINK
Definition: primnodes.h:687
@ IS_XMLSERIALIZE
Definition: primnodes.h:1214
List * targetList
Definition: parsenodes.h:149
Oid firstColCollation
Definition: primnodes.h:758
SubLinkType subLinkType
Definition: primnodes.h:747
Definition: primnodes.h:187

References arg, ARRAY_SUBLINK, Assert(), elog, ERROR, EXPR_SUBLINK, SubPlan::firstColCollation, if(), InvalidOid, IS_XMLSERIALIZE, IsA, linitial, linitial_node, nodeTag, SubLink::subLinkType, SubPlan::subLinkType, AlternativeSubPlan::subplans, SubLink::subselect, T_Aggref, T_AlternativeSubPlan, T_ArrayCoerceExpr, T_ArrayExpr, T_BooleanTest, T_BoolExpr, T_CaseExpr, T_CaseTestExpr, T_CoalesceExpr, T_CoerceToDomain, T_CoerceToDomainValue, T_CoerceViaIO, T_CollateExpr, T_Const, T_ConvertRowtypeExpr, T_CurrentOfExpr, T_DistinctExpr, T_FieldSelect, T_FieldStore, T_FuncExpr, T_GroupingFunc, T_InferenceElem, T_MinMaxExpr, T_NamedArgExpr, T_NextValueExpr, T_NullIfExpr, T_NullTest, T_OpExpr, T_Param, T_PlaceHolderVar, T_RelabelType, T_RowCompareExpr, T_RowExpr, T_ScalarArrayOpExpr, T_SetToDefault, T_SQLValueFunction, T_SubLink, T_SubPlan, T_SubscriptingRef, T_Var, T_WindowFunc, T_XmlExpr, Query::targetList, and generate_unaccent_rules::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(), 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(), makeVarFromTargetEntry(), makeWholeRowVar(), mcv_match_expression(), ordered_set_startup(), pg_get_indexdef_worker(), pg_get_partkeydef_worker(), preprocess_minmax_aggregates(), relabel_to_typmod(), RelationBuildPartitionKey(), RelationGetDummyIndexExpressions(), remove_unused_subquery_outputs(), replace_nestloop_param_placeholdervar(), replace_outer_placeholdervar(), scalararraysel(), set_dummy_tlist_references(), set_joinrel_partition_key_exprs(), tlist_same_collations(), transformCaseExpr(), transformFromClauseItem(), transformMultiAssignRef(), transformPLAssignStmt(), transformSubLink(), and transformWindowDefinitions().

◆ expression_returns_set()

bool expression_returns_set ( Node clause)

◆ expression_returns_set_walker()

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

Definition at line 715 of file nodeFuncs.c.

716 {
717  if (node == NULL)
718  return false;
719  if (IsA(node, FuncExpr))
720  {
721  FuncExpr *expr = (FuncExpr *) node;
722 
723  if (expr->funcretset)
724  return true;
725  /* else fall through to check args */
726  }
727  if (IsA(node, OpExpr))
728  {
729  OpExpr *expr = (OpExpr *) node;
730 
731  if (expr->opretset)
732  return true;
733  /* else fall through to check args */
734  }
735 
736  /* Avoid recursion for some cases that parser checks not to return a set */
737  if (IsA(node, Aggref))
738  return false;
739  if (IsA(node, WindowFunc))
740  return false;
741 
743  context);
744 }
bool expression_tree_walker(Node *node, bool(*walker)(), void *context)
Definition: nodeFuncs.c:1904
bool funcretset
Definition: primnodes.h:497
bool opretset
Definition: primnodes.h:545

References expression_tree_walker(), FuncExpr::funcretset, IsA, and OpExpr::opretset.

Referenced by expression_returns_set().

◆ expression_tree_mutator()

Node* expression_tree_mutator ( Node node,
Node *(*)()  mutator,
void *  context 
)

Definition at line 2618 of file nodeFuncs.c.

2621 {
2622  /*
2623  * The mutator has already decided not to modify the current node, but we
2624  * must call the mutator for any sub-nodes.
2625  */
2626 
2627 #define FLATCOPY(newnode, node, nodetype) \
2628  ( (newnode) = (nodetype *) palloc(sizeof(nodetype)), \
2629  memcpy((newnode), (node), sizeof(nodetype)) )
2630 
2631 #define CHECKFLATCOPY(newnode, node, nodetype) \
2632  ( AssertMacro(IsA((node), nodetype)), \
2633  (newnode) = (nodetype *) palloc(sizeof(nodetype)), \
2634  memcpy((newnode), (node), sizeof(nodetype)) )
2635 
2636 #define MUTATE(newfield, oldfield, fieldtype) \
2637  ( (newfield) = (fieldtype) mutator((Node *) (oldfield), context) )
2638 
2639  if (node == NULL)
2640  return NULL;
2641 
2642  /* Guard against stack overflow due to overly complex expressions */
2644 
2645  switch (nodeTag(node))
2646  {
2647  /*
2648  * Primitive node types with no expression subnodes. Var and
2649  * Const are frequent enough to deserve special cases, the others
2650  * we just use copyObject for.
2651  */
2652  case T_Var:
2653  {
2654  Var *var = (Var *) node;
2655  Var *newnode;
2656 
2657  FLATCOPY(newnode, var, Var);
2658  return (Node *) newnode;
2659  }
2660  break;
2661  case T_Const:
2662  {
2663  Const *oldnode = (Const *) node;
2664  Const *newnode;
2665 
2666  FLATCOPY(newnode, oldnode, Const);
2667  /* XXX we don't bother with datumCopy; should we? */
2668  return (Node *) newnode;
2669  }
2670  break;
2671  case T_Param:
2672  case T_CaseTestExpr:
2673  case T_SQLValueFunction:
2674  case T_CoerceToDomainValue:
2675  case T_SetToDefault:
2676  case T_CurrentOfExpr:
2677  case T_NextValueExpr:
2678  case T_RangeTblRef:
2679  case T_SortGroupClause:
2680  case T_CTESearchClause:
2681  return (Node *) copyObject(node);
2682  case T_WithCheckOption:
2683  {
2684  WithCheckOption *wco = (WithCheckOption *) node;
2685  WithCheckOption *newnode;
2686 
2687  FLATCOPY(newnode, wco, WithCheckOption);
2688  MUTATE(newnode->qual, wco->qual, Node *);
2689  return (Node *) newnode;
2690  }
2691  case T_Aggref:
2692  {
2693  Aggref *aggref = (Aggref *) node;
2694  Aggref *newnode;
2695 
2696  FLATCOPY(newnode, aggref, Aggref);
2697  /* assume mutation doesn't change types of arguments */
2698  newnode->aggargtypes = list_copy(aggref->aggargtypes);
2699  MUTATE(newnode->aggdirectargs, aggref->aggdirectargs, List *);
2700  MUTATE(newnode->args, aggref->args, List *);
2701  MUTATE(newnode->aggorder, aggref->aggorder, List *);
2702  MUTATE(newnode->aggdistinct, aggref->aggdistinct, List *);
2703  MUTATE(newnode->aggfilter, aggref->aggfilter, Expr *);
2704  return (Node *) newnode;
2705  }
2706  break;
2707  case T_GroupingFunc:
2708  {
2709  GroupingFunc *grouping = (GroupingFunc *) node;
2710  GroupingFunc *newnode;
2711 
2712  FLATCOPY(newnode, grouping, GroupingFunc);
2713  MUTATE(newnode->args, grouping->args, List *);
2714 
2715  /*
2716  * We assume here that mutating the arguments does not change
2717  * the semantics, i.e. that the arguments are not mutated in a
2718  * way that makes them semantically different from their
2719  * previously matching expressions in the GROUP BY clause.
2720  *
2721  * If a mutator somehow wanted to do this, it would have to
2722  * handle the refs and cols lists itself as appropriate.
2723  */
2724  newnode->refs = list_copy(grouping->refs);
2725  newnode->cols = list_copy(grouping->cols);
2726 
2727  return (Node *) newnode;
2728  }
2729  break;
2730  case T_WindowFunc:
2731  {
2732  WindowFunc *wfunc = (WindowFunc *) node;
2733  WindowFunc *newnode;
2734 
2735  FLATCOPY(newnode, wfunc, WindowFunc);
2736  MUTATE(newnode->args, wfunc->args, List *);
2737  MUTATE(newnode->aggfilter, wfunc->aggfilter, Expr *);
2738  return (Node *) newnode;
2739  }
2740  break;
2741  case T_SubscriptingRef:
2742  {
2743  SubscriptingRef *sbsref = (SubscriptingRef *) node;
2744  SubscriptingRef *newnode;
2745 
2746  FLATCOPY(newnode, sbsref, SubscriptingRef);
2747  MUTATE(newnode->refupperindexpr, sbsref->refupperindexpr,
2748  List *);
2749  MUTATE(newnode->reflowerindexpr, sbsref->reflowerindexpr,
2750  List *);
2751  MUTATE(newnode->refexpr, sbsref->refexpr,
2752  Expr *);
2753  MUTATE(newnode->refassgnexpr, sbsref->refassgnexpr,
2754  Expr *);
2755 
2756  return (Node *) newnode;
2757  }
2758  break;
2759  case T_FuncExpr:
2760  {
2761  FuncExpr *expr = (FuncExpr *) node;
2762  FuncExpr *newnode;
2763 
2764  FLATCOPY(newnode, expr, FuncExpr);
2765  MUTATE(newnode->args, expr->args, List *);
2766  return (Node *) newnode;
2767  }
2768  break;
2769  case T_NamedArgExpr:
2770  {
2771  NamedArgExpr *nexpr = (NamedArgExpr *) node;
2772  NamedArgExpr *newnode;
2773 
2774  FLATCOPY(newnode, nexpr, NamedArgExpr);
2775  MUTATE(newnode->arg, nexpr->arg, Expr *);
2776  return (Node *) newnode;
2777  }
2778  break;
2779  case T_OpExpr:
2780  {
2781  OpExpr *expr = (OpExpr *) node;
2782  OpExpr *newnode;
2783 
2784  FLATCOPY(newnode, expr, OpExpr);
2785  MUTATE(newnode->args, expr->args, List *);
2786  return (Node *) newnode;
2787  }
2788  break;
2789  case T_DistinctExpr:
2790  {
2791  DistinctExpr *expr = (DistinctExpr *) node;
2792  DistinctExpr *newnode;
2793 
2794  FLATCOPY(newnode, expr, DistinctExpr);
2795  MUTATE(newnode->args, expr->args, List *);
2796  return (Node *) newnode;
2797  }
2798  break;
2799  case T_NullIfExpr:
2800  {
2801  NullIfExpr *expr = (NullIfExpr *) node;
2802  NullIfExpr *newnode;
2803 
2804  FLATCOPY(newnode, expr, NullIfExpr);
2805  MUTATE(newnode->args, expr->args, List *);
2806  return (Node *) newnode;
2807  }
2808  break;
2809  case T_ScalarArrayOpExpr:
2810  {
2811  ScalarArrayOpExpr *expr = (ScalarArrayOpExpr *) node;
2812  ScalarArrayOpExpr *newnode;
2813 
2814  FLATCOPY(newnode, expr, ScalarArrayOpExpr);
2815  MUTATE(newnode->args, expr->args, List *);
2816  return (Node *) newnode;
2817  }
2818  break;
2819  case T_BoolExpr:
2820  {
2821  BoolExpr *expr = (BoolExpr *) node;
2822  BoolExpr *newnode;
2823 
2824  FLATCOPY(newnode, expr, BoolExpr);
2825  MUTATE(newnode->args, expr->args, List *);
2826  return (Node *) newnode;
2827  }
2828  break;
2829  case T_SubLink:
2830  {
2831  SubLink *sublink = (SubLink *) node;
2832  SubLink *newnode;
2833 
2834  FLATCOPY(newnode, sublink, SubLink);
2835  MUTATE(newnode->testexpr, sublink->testexpr, Node *);
2836 
2837  /*
2838  * Also invoke the mutator on the sublink's Query node, so it
2839  * can recurse into the sub-query if it wants to.
2840  */
2841  MUTATE(newnode->subselect, sublink->subselect, Node *);
2842  return (Node *) newnode;
2843  }
2844  break;
2845  case T_SubPlan:
2846  {
2847  SubPlan *subplan = (SubPlan *) node;
2848  SubPlan *newnode;
2849 
2850  FLATCOPY(newnode, subplan, SubPlan);
2851  /* transform testexpr */
2852  MUTATE(newnode->testexpr, subplan->testexpr, Node *);
2853  /* transform args list (params to be passed to subplan) */
2854  MUTATE(newnode->args, subplan->args, List *);
2855  /* but not the sub-Plan itself, which is referenced as-is */
2856  return (Node *) newnode;
2857  }
2858  break;
2859  case T_AlternativeSubPlan:
2860  {
2861  AlternativeSubPlan *asplan = (AlternativeSubPlan *) node;
2862  AlternativeSubPlan *newnode;
2863 
2864  FLATCOPY(newnode, asplan, AlternativeSubPlan);
2865  MUTATE(newnode->subplans, asplan->subplans, List *);
2866  return (Node *) newnode;
2867  }
2868  break;
2869  case T_FieldSelect:
2870  {
2871  FieldSelect *fselect = (FieldSelect *) node;
2872  FieldSelect *newnode;
2873 
2874  FLATCOPY(newnode, fselect, FieldSelect);
2875  MUTATE(newnode->arg, fselect->arg, Expr *);
2876  return (Node *) newnode;
2877  }
2878  break;
2879  case T_FieldStore:
2880  {
2881  FieldStore *fstore = (FieldStore *) node;
2882  FieldStore *newnode;
2883 
2884  FLATCOPY(newnode, fstore, FieldStore);
2885  MUTATE(newnode->arg, fstore->arg, Expr *);
2886  MUTATE(newnode->newvals, fstore->newvals, List *);
2887  newnode->fieldnums = list_copy(fstore->fieldnums);
2888  return (Node *) newnode;
2889  }
2890  break;
2891  case T_RelabelType:
2892  {
2893  RelabelType *relabel = (RelabelType *) node;
2894  RelabelType *newnode;
2895 
2896  FLATCOPY(newnode, relabel, RelabelType);
2897  MUTATE(newnode->arg, relabel->arg, Expr *);
2898  return (Node *) newnode;
2899  }
2900  break;
2901  case T_CoerceViaIO:
2902  {
2903  CoerceViaIO *iocoerce = (CoerceViaIO *) node;
2904  CoerceViaIO *newnode;
2905 
2906  FLATCOPY(newnode, iocoerce, CoerceViaIO);
2907  MUTATE(newnode->arg, iocoerce->arg, Expr *);
2908  return (Node *) newnode;
2909  }
2910  break;
2911  case T_ArrayCoerceExpr:
2912  {
2913  ArrayCoerceExpr *acoerce = (ArrayCoerceExpr *) node;
2914  ArrayCoerceExpr *newnode;
2915 
2916  FLATCOPY(newnode, acoerce, ArrayCoerceExpr);
2917  MUTATE(newnode->arg, acoerce->arg, Expr *);
2918  MUTATE(newnode->elemexpr, acoerce->elemexpr, Expr *);
2919  return (Node *) newnode;
2920  }
2921  break;
2922  case T_ConvertRowtypeExpr:
2923  {
2924  ConvertRowtypeExpr *convexpr = (ConvertRowtypeExpr *) node;
2925  ConvertRowtypeExpr *newnode;
2926 
2927  FLATCOPY(newnode, convexpr, ConvertRowtypeExpr);
2928  MUTATE(newnode->arg, convexpr->arg, Expr *);
2929  return (Node *) newnode;
2930  }
2931  break;
2932  case T_CollateExpr:
2933  {
2934  CollateExpr *collate = (CollateExpr *) node;
2935  CollateExpr *newnode;
2936 
2937  FLATCOPY(newnode, collate, CollateExpr);
2938  MUTATE(newnode->arg, collate->arg, Expr *);
2939  return (Node *) newnode;
2940  }
2941  break;
2942  case T_CaseExpr:
2943  {
2944  CaseExpr *caseexpr = (CaseExpr *) node;
2945  CaseExpr *newnode;
2946 
2947  FLATCOPY(newnode, caseexpr, CaseExpr);
2948  MUTATE(newnode->arg, caseexpr->arg, Expr *);
2949  MUTATE(newnode->args, caseexpr->args, List *);
2950  MUTATE(newnode->defresult, caseexpr->defresult, Expr *);
2951  return (Node *) newnode;
2952  }
2953  break;
2954  case T_CaseWhen:
2955  {
2956  CaseWhen *casewhen = (CaseWhen *) node;
2957  CaseWhen *newnode;
2958 
2959  FLATCOPY(newnode, casewhen, CaseWhen);
2960  MUTATE(newnode->expr, casewhen->expr, Expr *);
2961  MUTATE(newnode->result, casewhen->result, Expr *);
2962  return (Node *) newnode;
2963  }
2964  break;
2965  case T_ArrayExpr:
2966  {
2967  ArrayExpr *arrayexpr = (ArrayExpr *) node;
2968  ArrayExpr *newnode;
2969 
2970  FLATCOPY(newnode, arrayexpr, ArrayExpr);
2971  MUTATE(newnode->elements, arrayexpr->elements, List *);
2972  return (Node *) newnode;
2973  }
2974  break;
2975  case T_RowExpr:
2976  {
2977  RowExpr *rowexpr = (RowExpr *) node;
2978  RowExpr *newnode;
2979 
2980  FLATCOPY(newnode, rowexpr, RowExpr);
2981  MUTATE(newnode->args, rowexpr->args, List *);
2982  /* Assume colnames needn't be duplicated */
2983  return (Node *) newnode;
2984  }
2985  break;
2986  case T_RowCompareExpr:
2987  {
2988  RowCompareExpr *rcexpr = (RowCompareExpr *) node;
2989  RowCompareExpr *newnode;
2990 
2991  FLATCOPY(newnode, rcexpr, RowCompareExpr);
2992  MUTATE(newnode->largs, rcexpr->largs, List *);
2993  MUTATE(newnode->rargs, rcexpr->rargs, List *);
2994  return (Node *) newnode;
2995  }
2996  break;
2997  case T_CoalesceExpr:
2998  {
2999  CoalesceExpr *coalesceexpr = (CoalesceExpr *) node;
3000  CoalesceExpr *newnode;
3001 
3002  FLATCOPY(newnode, coalesceexpr, CoalesceExpr);
3003  MUTATE(newnode->args, coalesceexpr->args, List *);
3004  return (Node *) newnode;
3005  }
3006  break;
3007  case T_MinMaxExpr:
3008  {
3009  MinMaxExpr *minmaxexpr = (MinMaxExpr *) node;
3010  MinMaxExpr *newnode;
3011 
3012  FLATCOPY(newnode, minmaxexpr, MinMaxExpr);
3013  MUTATE(newnode->args, minmaxexpr->args, List *);
3014  return (Node *) newnode;
3015  }
3016  break;
3017  case T_XmlExpr:
3018  {
3019  XmlExpr *xexpr = (XmlExpr *) node;
3020  XmlExpr *newnode;
3021 
3022  FLATCOPY(newnode, xexpr, XmlExpr);
3023  MUTATE(newnode->named_args, xexpr->named_args, List *);
3024  /* assume mutator does not care about arg_names */
3025  MUTATE(newnode->args, xexpr->args, List *);
3026  return (Node *) newnode;
3027  }
3028  break;
3029  case T_NullTest:
3030  {
3031  NullTest *ntest = (NullTest *) node;
3032  NullTest *newnode;
3033 
3034  FLATCOPY(newnode, ntest, NullTest);
3035  MUTATE(newnode->arg, ntest->arg, Expr *);
3036  return (Node *) newnode;
3037  }
3038  break;
3039  case T_BooleanTest:
3040  {
3041  BooleanTest *btest = (BooleanTest *) node;
3042  BooleanTest *newnode;
3043 
3044  FLATCOPY(newnode, btest, BooleanTest);
3045  MUTATE(newnode->arg, btest->arg, Expr *);
3046  return (Node *) newnode;
3047  }
3048  break;
3049  case T_CoerceToDomain:
3050  {
3051  CoerceToDomain *ctest = (CoerceToDomain *) node;
3052  CoerceToDomain *newnode;
3053 
3054  FLATCOPY(newnode, ctest, CoerceToDomain);
3055  MUTATE(newnode->arg, ctest->arg, Expr *);
3056  return (Node *) newnode;
3057  }
3058  break;
3059  case T_TargetEntry:
3060  {
3061  TargetEntry *targetentry = (TargetEntry *) node;
3062  TargetEntry *newnode;
3063 
3064  FLATCOPY(newnode, targetentry, TargetEntry);
3065  MUTATE(newnode->expr, targetentry->expr, Expr *);
3066  return (Node *) newnode;
3067  }
3068  break;
3069  case T_Query:
3070  /* Do nothing with a sub-Query, per discussion above */
3071  return node;
3072  case T_WindowClause:
3073  {
3074  WindowClause *wc = (WindowClause *) node;
3075  WindowClause *newnode;
3076 
3077  FLATCOPY(newnode, wc, WindowClause);
3078  MUTATE(newnode->partitionClause, wc->partitionClause, List *);
3079  MUTATE(newnode->orderClause, wc->orderClause, List *);
3080  MUTATE(newnode->startOffset, wc->startOffset, Node *);
3081  MUTATE(newnode->endOffset, wc->endOffset, Node *);
3082  return (Node *) newnode;
3083  }
3084  break;
3085  case T_CTECycleClause:
3086  {
3087  CTECycleClause *cc = (CTECycleClause *) node;
3088  CTECycleClause *newnode;
3089 
3090  FLATCOPY(newnode, cc, CTECycleClause);
3091  MUTATE(newnode->cycle_mark_value, cc->cycle_mark_value, Node *);
3093  return (Node *) newnode;
3094  }
3095  break;
3096  case T_CommonTableExpr:
3097  {
3098  CommonTableExpr *cte = (CommonTableExpr *) node;
3099  CommonTableExpr *newnode;
3100 
3101  FLATCOPY(newnode, cte, CommonTableExpr);
3102 
3103  /*
3104  * Also invoke the mutator on the CTE's Query node, so it can
3105  * recurse into the sub-query if it wants to.
3106  */
3107  MUTATE(newnode->ctequery, cte->ctequery, Node *);
3108 
3110  MUTATE(newnode->cycle_clause, cte->cycle_clause, CTECycleClause *);
3111 
3112  return (Node *) newnode;
3113  }
3114  break;
3115  case T_PartitionBoundSpec:
3116  {
3117  PartitionBoundSpec *pbs = (PartitionBoundSpec *) node;
3118  PartitionBoundSpec *newnode;
3119 
3120  FLATCOPY(newnode, pbs, PartitionBoundSpec);
3121  MUTATE(newnode->listdatums, pbs->listdatums, List *);
3122  MUTATE(newnode->lowerdatums, pbs->lowerdatums, List *);
3123  MUTATE(newnode->upperdatums, pbs->upperdatums, List *);
3124  return (Node *) newnode;
3125  }
3126  break;
3127  case T_PartitionRangeDatum:
3128  {
3129  PartitionRangeDatum *prd = (PartitionRangeDatum *) node;
3130  PartitionRangeDatum *newnode;
3131 
3132  FLATCOPY(newnode, prd, PartitionRangeDatum);
3133  MUTATE(newnode->value, prd->value, Node *);
3134  return (Node *) newnode;
3135  }
3136  break;
3137  case T_List:
3138  {
3139  /*
3140  * We assume the mutator isn't interested in the list nodes
3141  * per se, so just invoke it on each list element. NOTE: this
3142  * would fail badly on a list with integer elements!
3143  */
3144  List *resultlist;
3145  ListCell *temp;
3146 
3147  resultlist = NIL;
3148  foreach(temp, (List *) node)
3149  {
3150  resultlist = lappend(resultlist,
3151  mutator((Node *) lfirst(temp),
3152  context));
3153  }
3154  return (Node *) resultlist;
3155  }
3156  break;
3157  case T_FromExpr:
3158  {
3159  FromExpr *from = (FromExpr *) node;
3160  FromExpr *newnode;
3161 
3162  FLATCOPY(newnode, from, FromExpr);
3163  MUTATE(newnode->fromlist, from->fromlist, List *);
3164  MUTATE(newnode->quals, from->quals, Node *);
3165  return (Node *) newnode;
3166  }
3167  break;
3168  case T_OnConflictExpr:
3169  {
3170  OnConflictExpr *oc = (OnConflictExpr *) node;
3171  OnConflictExpr *newnode;
3172 
3173  FLATCOPY(newnode, oc, OnConflictExpr);
3174  MUTATE(newnode->arbiterElems, oc->arbiterElems, List *);
3175  MUTATE(newnode->arbiterWhere, oc->arbiterWhere, Node *);
3176  MUTATE(newnode->onConflictSet, oc->onConflictSet, List *);
3177  MUTATE(newnode->onConflictWhere, oc->onConflictWhere, Node *);
3178  MUTATE(newnode->exclRelTlist, oc->exclRelTlist, List *);
3179 
3180  return (Node *) newnode;
3181  }
3182  break;
3184  {
3185  PartitionPruneStepOp *opstep = (PartitionPruneStepOp *) node;
3186  PartitionPruneStepOp *newnode;
3187 
3188  FLATCOPY(newnode, opstep, PartitionPruneStepOp);
3189  MUTATE(newnode->exprs, opstep->exprs, List *);
3190 
3191  return (Node *) newnode;
3192  }
3193  break;
3195  /* no expression sub-nodes */
3196  return (Node *) copyObject(node);
3197  case T_JoinExpr:
3198  {
3199  JoinExpr *join = (JoinExpr *) node;
3200  JoinExpr *newnode;
3201 
3202  FLATCOPY(newnode, join, JoinExpr);
3203  MUTATE(newnode->larg, join->larg, Node *);
3204  MUTATE(newnode->rarg, join->rarg, Node *);
3205  MUTATE(newnode->quals, join->quals, Node *);
3206  /* We do not mutate alias or using by default */
3207  return (Node *) newnode;
3208  }
3209  break;
3210  case T_SetOperationStmt:
3211  {
3212  SetOperationStmt *setop = (SetOperationStmt *) node;
3213  SetOperationStmt *newnode;
3214 
3215  FLATCOPY(newnode, setop, SetOperationStmt);
3216  MUTATE(newnode->larg, setop->larg, Node *);
3217  MUTATE(newnode->rarg, setop->rarg, Node *);
3218  /* We do not mutate groupClauses by default */
3219  return (Node *) newnode;
3220  }
3221  break;
3222  case T_IndexClause:
3223  {
3224  IndexClause *iclause = (IndexClause *) node;
3225  IndexClause *newnode;
3226 
3227  FLATCOPY(newnode, iclause, IndexClause);
3228  MUTATE(newnode->rinfo, iclause->rinfo, RestrictInfo *);
3229  MUTATE(newnode->indexquals, iclause->indexquals, List *);
3230  return (Node *) newnode;
3231  }
3232  break;
3233  case T_PlaceHolderVar:
3234  {
3235  PlaceHolderVar *phv = (PlaceHolderVar *) node;
3236  PlaceHolderVar *newnode;
3237 
3238  FLATCOPY(newnode, phv, PlaceHolderVar);
3239  MUTATE(newnode->phexpr, phv->phexpr, Expr *);
3240  /* Assume we need not copy the relids bitmapset */
3241  return (Node *) newnode;
3242  }
3243  break;
3244  case T_InferenceElem:
3245  {
3246  InferenceElem *inferenceelemdexpr = (InferenceElem *) node;
3247  InferenceElem *newnode;
3248 
3249  FLATCOPY(newnode, inferenceelemdexpr, InferenceElem);
3250  MUTATE(newnode->expr, newnode->expr, Node *);
3251  return (Node *) newnode;
3252  }
3253  break;
3254  case T_AppendRelInfo:
3255  {
3256  AppendRelInfo *appinfo = (AppendRelInfo *) node;
3257  AppendRelInfo *newnode;
3258 
3259  FLATCOPY(newnode, appinfo, AppendRelInfo);
3260  MUTATE(newnode->translated_vars, appinfo->translated_vars, List *);
3261  /* Assume nothing need be done with parent_colnos[] */
3262  return (Node *) newnode;
3263  }
3264  break;
3265  case T_PlaceHolderInfo:
3266  {
3267  PlaceHolderInfo *phinfo = (PlaceHolderInfo *) node;
3268  PlaceHolderInfo *newnode;
3269 
3270  FLATCOPY(newnode, phinfo, PlaceHolderInfo);
3271  MUTATE(newnode->ph_var, phinfo->ph_var, PlaceHolderVar *);
3272  /* Assume we need not copy the relids bitmapsets */
3273  return (Node *) newnode;
3274  }
3275  break;
3276  case T_RangeTblFunction:
3277  {
3278  RangeTblFunction *rtfunc = (RangeTblFunction *) node;
3279  RangeTblFunction *newnode;
3280 
3281  FLATCOPY(newnode, rtfunc, RangeTblFunction);
3282  MUTATE(newnode->funcexpr, rtfunc->funcexpr, Node *);
3283  /* Assume we need not copy the coldef info lists */
3284  return (Node *) newnode;
3285  }
3286  break;
3287  case T_TableSampleClause:
3288  {
3289  TableSampleClause *tsc = (TableSampleClause *) node;
3290  TableSampleClause *newnode;
3291 
3292  FLATCOPY(newnode, tsc, TableSampleClause);
3293  MUTATE(newnode->args, tsc->args, List *);
3294  MUTATE(newnode->repeatable, tsc->repeatable, Expr *);
3295  return (Node *) newnode;
3296  }
3297  break;
3298  case T_TableFunc:
3299  {
3300  TableFunc *tf = (TableFunc *) node;
3301  TableFunc *newnode;
3302 
3303  FLATCOPY(newnode, tf, TableFunc);
3304  MUTATE(newnode->ns_uris, tf->ns_uris, List *);
3305  MUTATE(newnode->docexpr, tf->docexpr, Node *);
3306  MUTATE(newnode->rowexpr, tf->rowexpr, Node *);
3307  MUTATE(newnode->colexprs, tf->colexprs, List *);
3308  MUTATE(newnode->coldefexprs, tf->coldefexprs, List *);
3309  return (Node *) newnode;
3310  }
3311  break;
3312  default:
3313  elog(ERROR, "unrecognized node type: %d",
3314  (int) nodeTag(node));
3315  break;
3316  }
3317  /* can't get here, but keep compiler happy */
3318  return NULL;
3319 }
List * lappend(List *list, void *datum)
Definition: list.c:336
List * list_copy(const List *oldlist)
Definition: list.c:1532
#define FLATCOPY(newnode, node, nodetype)
#define MUTATE(newfield, oldfield, fieldtype)
@ T_WithCheckOption
Definition: nodes.h:465
@ T_List
Definition: nodes.h:302
@ T_CTESearchClause
Definition: nodes.h:480
@ T_OnConflictExpr
Definition: nodes.h:202
@ T_RangeTblRef
Definition: nodes.h:199
@ T_SortGroupClause
Definition: nodes.h:466
@ T_TableFunc
Definition: nodes.h:155
@ T_JoinExpr
Definition: nodes.h:200
@ T_PlaceHolderInfo
Definition: nodes.h:276
@ T_TableSampleClause
Definition: nodes.h:464
@ T_SetOperationStmt
Definition: nodes.h:326
@ T_CommonTableExpr
Definition: nodes.h:482
@ T_WindowClause
Definition: nodes.h:468
@ T_Query
Definition: nodes.h:315
@ T_FromExpr
Definition: nodes.h:201
@ T_TargetEntry
Definition: nodes.h:198
@ T_CTECycleClause
Definition: nodes.h:481
@ T_RangeTblFunction
Definition: nodes.h:463
@ T_AppendRelInfo
Definition: nodes.h:274
@ T_PartitionRangeDatum
Definition: nodes.h:488
@ T_PartitionBoundSpec
Definition: nodes.h:487
@ T_IndexClause
Definition: nodes.h:271
@ T_CaseWhen
Definition: nodes.h:181
@ T_PartitionPruneStepCombine
Definition: nodes.h:96
@ T_PartitionPruneStepOp
Definition: nodes.h:95
#define lfirst(lc)
Definition: pg_list.h:169
#define NIL
Definition: pg_list.h:65
void check_stack_depth(void)
Definition: postgres.c:3470
List * aggdistinct
Definition: primnodes.h:332
List * aggdirectargs
Definition: primnodes.h:329
List * args
Definition: primnodes.h:330
Expr * aggfilter
Definition: primnodes.h:333
List * aggargtypes
Definition: primnodes.h:328
List * aggorder
Definition: primnodes.h:331
List * translated_vars
Definition: pathnodes.h:2338
Expr * elemexpr
Definition: primnodes.h:905
List * elements
Definition: primnodes.h:1037
List * args
Definition: primnodes.h:626
Expr * arg
Definition: primnodes.h:1288
Node * cycle_mark_default
Definition: parsenodes.h:1499
Node * cycle_mark_value
Definition: parsenodes.h:1498
Expr * arg
Definition: primnodes.h:978
Expr * defresult
Definition: primnodes.h:980
List * args
Definition: primnodes.h:979
Expr * result
Definition: primnodes.h:991
Expr * expr
Definition: primnodes.h:990
List * args
Definition: primnodes.h:1132
Expr * arg
Definition: primnodes.h:946
CTECycleClause * cycle_clause
Definition: parsenodes.h:1518
CTESearchClause * search_clause
Definition: parsenodes.h:1517
Expr * arg
Definition: primnodes.h:808
List * newvals
Definition: primnodes.h:838
Expr * arg
Definition: primnodes.h:837
List * fieldnums
Definition: primnodes.h:839
Node * quals
Definition: primnodes.h:1565
List * fromlist
Definition: primnodes.h:1564
List * args
Definition: primnodes.h:503
List * args
Definition: primnodes.h:372
List * refs
Definition: primnodes.h:374
List * cols
Definition: primnodes.h:375
List * indexquals
Definition: pathnodes.h:1293
struct RestrictInfo * rinfo
Definition: pathnodes.h:1292
Node * quals
Definition: primnodes.h:1547
Node * larg
Definition: primnodes.h:1543
Node * rarg
Definition: primnodes.h:1544
Definition: pg_list.h:51
List * args
Definition: primnodes.h:1152
Expr * arg
Definition: primnodes.h:524
Expr * arg
Definition: primnodes.h:1265
List * arbiterElems
Definition: primnodes.h:1583
List * onConflictSet
Definition: primnodes.h:1589
List * exclRelTlist
Definition: primnodes.h:1592
Node * onConflictWhere
Definition: primnodes.h:1590
Node * arbiterWhere
Definition: primnodes.h:1585
List * args
Definition: primnodes.h:548
PlaceHolderVar * ph_var
Definition: pathnodes.h:2416
List * args
Definition: primnodes.h:1068
List * args
Definition: primnodes.h:773
Node * testexpr
Definition: primnodes.h:749
Expr * refassgnexpr
Definition: primnodes.h:451
List * refupperindexpr
Definition: primnodes.h:444
Expr * refexpr
Definition: primnodes.h:449
List * reflowerindexpr
Definition: primnodes.h:446
List * coldefexprs
Definition: primnodes.h:94
Node * docexpr
Definition: primnodes.h:87
List * ns_uris
Definition: primnodes.h:85
Node * rowexpr
Definition: primnodes.h:88
List * colexprs
Definition: primnodes.h:93
Expr * expr
Definition: primnodes.h:1455
Node * startOffset
Definition: parsenodes.h:1394
List * partitionClause
Definition: parsenodes.h:1391
Node * endOffset
Definition: parsenodes.h:1395
List * orderClause
Definition: parsenodes.h:1392
List * args
Definition: primnodes.h:390
Expr * aggfilter
Definition: primnodes.h:391
List * args
Definition: primnodes.h:1231
List * named_args
Definition: primnodes.h:1229

References Aggref::aggargtypes, Aggref::aggdirectargs, Aggref::aggdistinct, Aggref::aggfilter, WindowFunc::aggfilter, Aggref::aggorder, OnConflictExpr::arbiterElems, OnConflictExpr::arbiterWhere, NamedArgExpr::arg, FieldSelect::arg, FieldStore::arg, RelabelType::arg, CoerceViaIO::arg, ArrayCoerceExpr::arg, ConvertRowtypeExpr::arg, CollateExpr::arg, CaseExpr::arg, NullTest::arg, BooleanTest::arg, CoerceToDomain::arg, TableSampleClause::args, Aggref::args, GroupingFunc::args, WindowFunc::args, FuncExpr::args, OpExpr::args, ScalarArrayOpExpr::args, BoolExpr::args, SubPlan::args, CaseExpr::args, RowExpr::args, CoalesceExpr::args, MinMaxExpr::args, XmlExpr::args, check_stack_depth(), TableFunc::coldefexprs, TableFunc::colexprs, GroupingFunc::cols, copyObject, CommonTableExpr::ctequery, CommonTableExpr::cycle_clause, CTECycleClause::cycle_mark_default, CTECycleClause::cycle_mark_value, CaseExpr::defresult, TableFunc::docexpr, ArrayExpr::elements, ArrayCoerceExpr::elemexpr, elog, WindowClause::endOffset, ERROR, OnConflictExpr::exclRelTlist, CaseWhen::expr, InferenceElem::expr, TargetEntry::expr, PartitionPruneStepOp::exprs, FieldStore::fieldnums, FLATCOPY, FromExpr::fromlist, 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, TableFunc::ns_uris, OnConflictExpr::onConflictSet, OnConflictExpr::onConflictWhere, WindowClause::orderClause, WindowClause::partitionClause, PlaceHolderInfo::ph_var, PlaceHolderVar::phexpr, WithCheckOption::qual, JoinExpr::quals, FromExpr::quals, SetOperationStmt::rarg, JoinExpr::rarg, RowCompareExpr::rargs, SubscriptingRef::refassgnexpr, SubscriptingRef::refexpr, SubscriptingRef::reflowerindexpr, GroupingFunc::refs, SubscriptingRef::refupperindexpr, TableSampleClause::repeatable, CaseWhen::result, IndexClause::rinfo, TableFunc::rowexpr, CommonTableExpr::search_clause, WindowClause::startOffset, AlternativeSubPlan::subplans, SubLink::subselect, T_Aggref, T_AlternativeSubPlan, T_AppendRelInfo, T_ArrayCoerceExpr, T_ArrayExpr, T_BooleanTest, T_BoolExpr, T_CaseExpr, T_CaseTestExpr, T_CaseWhen, T_CoalesceExpr, T_CoerceToDomain, T_CoerceToDomainValue, T_CoerceViaIO, T_CollateExpr, T_CommonTableExpr, T_Const, T_ConvertRowtypeExpr, T_CTECycleClause, T_CTESearchClause, T_CurrentOfExpr, T_DistinctExpr, T_FieldSelect, T_FieldStore, T_FromExpr, T_FuncExpr, T_GroupingFunc, T_IndexClause, T_InferenceElem, T_JoinExpr, T_List, T_MinMaxExpr, T_NamedArgExpr, T_NextValueExpr, T_NullIfExpr, T_NullTest, T_OnConflictExpr, T_OpExpr, T_Param, T_PartitionBoundSpec, T_PartitionPruneStepCombine, T_PartitionPruneStepOp, T_PartitionRangeDatum, T_PlaceHolderInfo, T_PlaceHolderVar, T_Query, T_RangeTblFunction, T_RangeTblRef, T_RelabelType, T_RowCompareExpr, T_RowExpr, T_ScalarArrayOpExpr, T_SetOperationStmt, T_SetToDefault, T_SortGroupClause, T_SQLValueFunction, T_SubLink, T_SubPlan, T_SubscriptingRef, T_TableFunc, T_TableSampleClause, T_TargetEntry, T_Var, T_WindowClause, T_WindowFunc, T_WithCheckOption, T_XmlExpr, SubLink::testexpr, SubPlan::testexpr, AppendRelInfo::translated_vars, PartitionBoundSpec::upperdatums, and PartitionRangeDatum::value.

Referenced by adjust_appendrel_attrs_mutator(), convert_combining_aggrefs(), convert_testexpr_mutator(), eval_const_expressions_mutator(), fix_join_expr_mutator(), fix_scan_expr_mutator(), fix_upper_expr_mutator(), flatten_join_alias_vars_mutator(), map_variable_attnos_mutator(), process_sublinks_mutator(), replace_correlation_vars_mutator(), replace_nestloop_params_mutator(), replace_rte_variables_mutator(), simplify_function(), substitute_actual_parameters_mutator(), and substitute_actual_srf_parameters_mutator().

◆ expression_tree_walker()

bool expression_tree_walker ( Node node,
bool(*)()  walker,
void *  context 
)

Definition at line 1904 of file nodeFuncs.c.

1907 {
1908  ListCell *temp;
1909 
1910  /*
1911  * The walker has already visited the current node, and so we need only
1912  * recurse into any sub-nodes it has.
1913  *
1914  * We assume that the walker is not interested in List nodes per se, so
1915  * when we expect a List we just recurse directly to self without
1916  * bothering to call the walker.
1917  */
1918  if (node == NULL)
1919  return false;
1920 
1921  /* Guard against stack overflow due to overly complex expressions */
1923 
1924  switch (nodeTag(node))
1925  {
1926  case T_Var:
1927  case T_Const:
1928  case T_Param:
1929  case T_CaseTestExpr:
1930  case T_SQLValueFunction:
1931  case T_CoerceToDomainValue:
1932  case T_SetToDefault:
1933  case T_CurrentOfExpr:
1934  case T_NextValueExpr:
1935  case T_RangeTblRef:
1936  case T_SortGroupClause:
1937  case T_CTESearchClause:
1938  /* primitive node types with no expression subnodes */
1939  break;
1940  case T_WithCheckOption:
1941  return walker(((WithCheckOption *) node)->qual, context);
1942  case T_Aggref:
1943  {
1944  Aggref *expr = (Aggref *) node;
1945 
1946  /* recurse directly on List */
1948  walker, context))
1949  return true;
1950  if (expression_tree_walker((Node *) expr->args,
1951  walker, context))
1952  return true;
1953  if (expression_tree_walker((Node *) expr->aggorder,
1954  walker, context))
1955  return true;
1956  if (expression_tree_walker((Node *) expr->aggdistinct,
1957  walker, context))
1958  return true;
1959  if (walker((Node *) expr->aggfilter, context))
1960  return true;
1961  }
1962  break;
1963  case T_GroupingFunc:
1964  {
1965  GroupingFunc *grouping = (GroupingFunc *) node;
1966 
1967  if (expression_tree_walker((Node *) grouping->args,
1968  walker, context))
1969  return true;
1970  }
1971  break;
1972  case T_WindowFunc:
1973  {
1974  WindowFunc *expr = (WindowFunc *) node;
1975 
1976  /* recurse directly on List */
1977  if (expression_tree_walker((Node *) expr->args,
1978  walker, context))
1979  return true;
1980  if (walker((Node *) expr->aggfilter, context))
1981  return true;
1982  }
1983  break;
1984  case T_SubscriptingRef:
1985  {
1986  SubscriptingRef *sbsref = (SubscriptingRef *) node;
1987 
1988  /* recurse directly for upper/lower container index lists */
1990  walker, context))
1991  return true;
1993  walker, context))
1994  return true;
1995  /* walker must see the refexpr and refassgnexpr, however */
1996  if (walker(sbsref->refexpr, context))
1997  return true;
1998 
1999  if (walker(sbsref->refassgnexpr, context))
2000  return true;
2001  }
2002  break;
2003  case T_FuncExpr:
2004  {
2005  FuncExpr *expr = (FuncExpr *) node;
2006 
2007  if (expression_tree_walker((Node *) expr->args,
2008  walker, context))
2009  return true;
2010  }
2011  break;
2012  case T_NamedArgExpr:
2013  return walker(((NamedArgExpr *) node)->arg, context);
2014  case T_OpExpr:
2015  case T_DistinctExpr: /* struct-equivalent to OpExpr */
2016  case T_NullIfExpr: /* struct-equivalent to OpExpr */
2017  {
2018  OpExpr *expr = (OpExpr *) node;
2019 
2020  if (expression_tree_walker((Node *) expr->args,
2021  walker, context))
2022  return true;
2023  }
2024  break;
2025  case T_ScalarArrayOpExpr:
2026  {
2027  ScalarArrayOpExpr *expr = (ScalarArrayOpExpr *) node;
2028 
2029  if (expression_tree_walker((Node *) expr->args,
2030  walker, context))
2031  return true;
2032  }
2033  break;
2034  case T_BoolExpr:
2035  {
2036  BoolExpr *expr = (BoolExpr *) node;
2037 
2038  if (expression_tree_walker((Node *) expr->args,
2039  walker, context))
2040  return true;
2041  }
2042  break;
2043  case T_SubLink:
2044  {
2045  SubLink *sublink = (SubLink *) node;
2046 
2047  if (walker(sublink->testexpr, context))
2048  return true;
2049 
2050  /*
2051  * Also invoke the walker on the sublink's Query node, so it
2052  * can recurse into the sub-query if it wants to.
2053  */
2054  return walker(sublink->subselect, context);
2055  }
2056  break;
2057  case T_SubPlan:
2058  {
2059  SubPlan *subplan = (SubPlan *) node;
2060 
2061  /* recurse into the testexpr, but not into the Plan */
2062  if (walker(subplan->testexpr, context))
2063  return true;
2064  /* also examine args list */
2065  if (expression_tree_walker((Node *) subplan->args,
2066  walker, context))
2067  return true;
2068  }
2069  break;
2070  case T_AlternativeSubPlan:
2071  return walker(((AlternativeSubPlan *) node)->subplans, context);
2072  case T_FieldSelect:
2073  return walker(((FieldSelect *) node)->arg, context);
2074  case T_FieldStore:
2075  {
2076  FieldStore *fstore = (FieldStore *) node;
2077 
2078  if (walker(fstore->arg, context))
2079  return true;
2080  if (walker(fstore->newvals, context))
2081  return true;
2082  }
2083  break;
2084  case T_RelabelType:
2085  return walker(((RelabelType *) node)->arg, context);
2086  case T_CoerceViaIO:
2087  return walker(((CoerceViaIO *) node)->arg, context);
2088  case T_ArrayCoerceExpr:
2089  {
2090  ArrayCoerceExpr *acoerce = (ArrayCoerceExpr *) node;
2091 
2092  if (walker(acoerce->arg, context))
2093  return true;
2094  if (walker(acoerce->elemexpr, context))
2095  return true;
2096  }
2097  break;
2098  case T_ConvertRowtypeExpr:
2099  return walker(((ConvertRowtypeExpr *) node)->arg, context);
2100  case T_CollateExpr:
2101  return walker(((CollateExpr *) node)->arg, context);
2102  case T_CaseExpr:
2103  {
2104  CaseExpr *caseexpr = (CaseExpr *) node;
2105 
2106  if (walker(caseexpr->arg, context))
2107  return true;
2108  /* we assume walker doesn't care about CaseWhens, either */
2109  foreach(temp, caseexpr->args)
2110  {
2111  CaseWhen *when = lfirst_node(CaseWhen, temp);
2112 
2113  if (walker(when->expr, context))
2114  return true;
2115  if (walker(when->result, context))
2116  return true;
2117  }
2118  if (walker(caseexpr->defresult, context))
2119  return true;
2120  }
2121  break;
2122  case T_ArrayExpr:
2123  return walker(((ArrayExpr *) node)->elements, context);
2124  case T_RowExpr:
2125  /* Assume colnames isn't interesting */
2126  return walker(((RowExpr *) node)->args, context);
2127  case T_RowCompareExpr:
2128  {
2129  RowCompareExpr *rcexpr = (RowCompareExpr *) node;
2130 
2131  if (walker(rcexpr->largs, context))
2132  return true;
2133  if (walker(rcexpr->rargs, context))
2134  return true;
2135  }
2136  break;
2137  case T_CoalesceExpr:
2138  return walker(((CoalesceExpr *) node)->args, context);
2139  case T_MinMaxExpr:
2140  return walker(((MinMaxExpr *) node)->args, context);
2141  case T_XmlExpr:
2142  {
2143  XmlExpr *xexpr = (XmlExpr *) node;
2144 
2145  if (walker(xexpr->named_args, context))
2146  return true;
2147  /* we assume walker doesn't care about arg_names */
2148  if (walker(xexpr->args, context))
2149  return true;
2150  }
2151  break;
2152  case T_NullTest:
2153  return walker(((NullTest *) node)->arg, context);
2154  case T_BooleanTest:
2155  return walker(((BooleanTest *) node)->arg, context);
2156  case T_CoerceToDomain:
2157  return walker(((CoerceToDomain *) node)->arg, context);
2158  case T_TargetEntry:
2159  return walker(((TargetEntry *) node)->expr, context);
2160  case T_Query:
2161  /* Do nothing with a sub-Query, per discussion above */
2162  break;
2163  case T_WindowClause:
2164  {
2165  WindowClause *wc = (WindowClause *) node;
2166 
2167  if (walker(wc->partitionClause, context))
2168  return true;
2169  if (walker(wc->orderClause, context))
2170  return true;
2171  if (walker(wc->startOffset, context))
2172  return true;
2173  if (walker(wc->endOffset, context))
2174  return true;
2175  }
2176  break;
2177  case T_CTECycleClause:
2178  {
2179  CTECycleClause *cc = (CTECycleClause *) node;
2180 
2181  if (walker(cc->cycle_mark_value, context))
2182  return true;
2183  if (walker(cc->cycle_mark_default, context))
2184  return true;
2185  }
2186  break;
2187  case T_CommonTableExpr:
2188  {
2189  CommonTableExpr *cte = (CommonTableExpr *) node;
2190 
2191  /*
2192  * Invoke the walker on the CTE's Query node, so it can
2193  * recurse into the sub-query if it wants to.
2194  */
2195  if (walker(cte->ctequery, context))
2196  return true;
2197 
2198  if (walker(cte->search_clause, context))
2199  return true;
2200  if (walker(cte->cycle_clause, context))
2201  return true;
2202  }
2203  break;
2204  case T_PartitionBoundSpec:
2205  {
2206  PartitionBoundSpec *pbs = (PartitionBoundSpec *) node;
2207 
2208  if (walker(pbs->listdatums, context))
2209  return true;
2210  if (walker(pbs->lowerdatums, context))
2211  return true;
2212  if (walker(pbs->upperdatums, context))
2213  return true;
2214  }
2215  break;
2216  case T_PartitionRangeDatum:
2217  {
2218  PartitionRangeDatum *prd = (PartitionRangeDatum *) node;
2219 
2220  if (walker(prd->value, context))
2221  return true;
2222  }
2223  break;
2224  case T_List:
2225  foreach(temp, (List *) node)
2226  {
2227  if (walker((Node *) lfirst(temp), context))
2228  return true;
2229  }
2230  break;
2231  case T_FromExpr:
2232  {
2233  FromExpr *from = (FromExpr *) node;
2234 
2235  if (walker(from->fromlist, context))
2236  return true;
2237  if (walker(from->quals, context))
2238  return true;
2239  }
2240  break;
2241  case T_OnConflictExpr:
2242  {
2243  OnConflictExpr *onconflict = (OnConflictExpr *) node;
2244 
2245  if (walker((Node *) onconflict->arbiterElems, context))
2246  return true;
2247  if (walker(onconflict->arbiterWhere, context))
2248  return true;
2249  if (walker(onconflict->onConflictSet, context))
2250  return true;
2251  if (walker(onconflict->onConflictWhere, context))
2252  return true;
2253  if (walker(onconflict->exclRelTlist, context))
2254  return true;
2255  }
2256  break;
2258  {
2259  PartitionPruneStepOp *opstep = (PartitionPruneStepOp *) node;
2260 
2261  if (walker((Node *) opstep->exprs, context))
2262  return true;
2263  }
2264  break;
2266  /* no expression subnodes */
2267  break;
2268  case T_JoinExpr:
2269  {
2270  JoinExpr *join = (JoinExpr *) node;
2271 
2272  if (walker(join->larg, context))
2273  return true;
2274  if (walker(join->rarg, context))
2275  return true;
2276  if (walker(join->quals, context))
2277  return true;
2278 
2279  /*
2280  * alias clause, using list are deemed uninteresting.
2281  */
2282  }
2283  break;
2284  case T_SetOperationStmt:
2285  {
2286  SetOperationStmt *setop = (SetOperationStmt *) node;
2287 
2288  if (walker(setop->larg, context))
2289  return true;
2290  if (walker(setop->rarg, context))
2291  return true;
2292 
2293  /* groupClauses are deemed uninteresting */
2294  }
2295  break;
2296  case T_IndexClause:
2297  {
2298  IndexClause *iclause = (IndexClause *) node;
2299 
2300  if (walker(iclause->rinfo, context))
2301  return true;
2302  if (expression_tree_walker((Node *) iclause->indexquals,
2303  walker, context))
2304  return true;
2305  }
2306  break;
2307  case T_PlaceHolderVar:
2308  return walker(((PlaceHolderVar *) node)->phexpr, context);
2309  case T_InferenceElem:
2310  return walker(((InferenceElem *) node)->expr, context);
2311  case T_AppendRelInfo:
2312  {
2313  AppendRelInfo *appinfo = (AppendRelInfo *) node;
2314 
2315  if (expression_tree_walker((Node *) appinfo->translated_vars,
2316  walker, context))
2317  return true;
2318  }
2319  break;
2320  case T_PlaceHolderInfo:
2321  return walker(((PlaceHolderInfo *) node)->ph_var, context);
2322  case T_RangeTblFunction:
2323  return walker(((RangeTblFunction *) node)->funcexpr, context);
2324  case T_TableSampleClause:
2325  {
2326  TableSampleClause *tsc = (TableSampleClause *) node;
2327 
2328  if (expression_tree_walker((Node *) tsc->args,
2329  walker, context))
2330  return true;
2331  if (walker((Node *) tsc->repeatable, context))
2332  return true;
2333  }
2334  break;
2335  case T_TableFunc:
2336  {
2337  TableFunc *tf = (TableFunc *) node;
2338 
2339  if (walker(tf->ns_uris, context))
2340  return true;
2341  if (walker(tf->docexpr, context))
2342  return true;
2343  if (walker(tf->rowexpr, context))
2344  return true;
2345  if (walker(tf->colexprs, context))
2346  return true;
2347  if (walker(tf->coldefexprs, context))
2348  return true;
2349  }
2350  break;
2351  default:
2352  elog(ERROR, "unrecognized node type: %d",
2353  (int) nodeTag(node));
2354  break;
2355  }
2356  return false;
2357 }
#define lfirst_node(type, lc)
Definition: pg_list.h:172
Definition: type.h:83

References Aggref::aggdirectargs, Aggref::aggdistinct, Aggref::aggfilter, WindowFunc::aggfilter, Aggref::aggorder, OnConflictExpr::arbiterElems, OnConflictExpr::arbiterWhere, arg, FieldStore::arg, ArrayCoerceExpr::arg, CaseExpr::arg, generate_unaccent_rules::args, TableSampleClause::args, Aggref::args, GroupingFunc::args, WindowFunc::args, FuncExpr::args, OpExpr::args, ScalarArrayOpExpr::args, BoolExpr::args, SubPlan::args, CaseExpr::args, XmlExpr::args, check_stack_depth(), TableFunc::coldefexprs, TableFunc::colexprs, CommonTableExpr::ctequery, CommonTableExpr::cycle_clause, CTECycleClause::cycle_mark_default, CTECycleClause::cycle_mark_value, CaseExpr::defresult, TableFunc::docexpr, ArrayCoerceExpr::elemexpr, elog, WindowClause::endOffset, ERROR, OnConflictExpr::exclRelTlist, PartitionPruneStepOp::exprs, FromExpr::fromlist, IndexClause::indexquals, SetOperationStmt::larg, JoinExpr::larg, RowCompareExpr::largs, lfirst, lfirst_node, PartitionBoundSpec::listdatums, PartitionBoundSpec::lowerdatums, XmlExpr::named_args, FieldStore::newvals, nodeTag, TableFunc::ns_uris, OnConflictExpr::onConflictSet, OnConflictExpr::onConflictWhere, WindowClause::orderClause, WindowClause::partitionClause, JoinExpr::quals, FromExpr::quals, SetOperationStmt::rarg, JoinExpr::rarg, RowCompareExpr::rargs, SubscriptingRef::refassgnexpr, SubscriptingRef::refexpr, SubscriptingRef::reflowerindexpr, SubscriptingRef::refupperindexpr, TableSampleClause::repeatable, IndexClause::rinfo, TableFunc::rowexpr, CommonTableExpr::search_clause, WindowClause::startOffset, SubLink::subselect, T_Aggref, T_AlternativeSubPlan, T_AppendRelInfo, T_ArrayCoerceExpr, T_ArrayExpr, T_BooleanTest, T_BoolExpr, T_CaseExpr, T_CaseTestExpr, T_CoalesceExpr, T_CoerceToDomain, T_CoerceToDomainValue, T_CoerceViaIO, T_CollateExpr, T_CommonTableExpr, T_Const, T_ConvertRowtypeExpr, T_CTECycleClause, T_CTESearchClause, T_CurrentOfExpr, T_DistinctExpr, T_FieldSelect, T_FieldStore, T_FromExpr, T_FuncExpr, T_GroupingFunc, T_IndexClause, T_InferenceElem, T_JoinExpr, T_List, T_MinMaxExpr, T_NamedArgExpr, T_NextValueExpr, T_NullIfExpr, T_NullTest, T_OnConflictExpr, T_OpExpr, T_Param, T_PartitionBoundSpec, T_PartitionPruneStepCombine, T_PartitionPruneStepOp, T_PartitionRangeDatum, T_PlaceHolderInfo, T_PlaceHolderVar, T_Query, T_RangeTblFunction, T_RangeTblRef, T_RelabelType, T_RowCompareExpr, T_RowExpr, T_ScalarArrayOpExpr, T_SetOperationStmt, T_SetToDefault, T_SortGroupClause, T_SQLValueFunction, T_SubLink, T_SubPlan, T_SubscriptingRef, T_TableFunc, T_TableSampleClause, T_TargetEntry, T_Var, T_WindowClause, T_WindowFunc, T_WithCheckOption, T_XmlExpr, SubLink::testexpr, SubPlan::testexpr, AppendRelInfo::translated_vars, PartitionBoundSpec::upperdatums, and PartitionRangeDatum::value.

Referenced by acquireLocksOnSubLinks(), assign_collations_walker(), ChangeVarNodes_walker(), check_agg_arguments_walker(), check_nested_generated_walker(), check_parameter_resolution_walker(), check_ungrouped_columns_walker(), checkExprHasSubLink_walker(), contain_agg_clause_walker(), contain_aggs_of_level_walker(), contain_context_dependent_node_walker(), contain_dml_walker(), contain_exec_param_walker(), contain_leaked_vars_walker(), contain_mutable_functions_walker(), contain_non_const_walker(), contain_nonstrict_functions_walker(), contain_outer_selfref_walker(), contain_subplans_walker(), contain_var_clause_walker(), contain_vars_of_level_walker(), contain_volatile_functions_not_nextval_walker(), contain_volatile_functions_walker(), contain_windowfuncs_walker(), contains_multiexpr_param(), convert_saop_to_hashed_saop_walker(), cost_qual_eval_walker(), expression_returns_set_walker(), extract_query_dependencies_walker(), finalize_agg_primnode(), finalize_grouping_exprs_walker(), finalize_primnode(), find_cols_walker(), find_dependent_phvs_walker(), find_expr_references_walker(), find_window_functions_walker(), fireRIRonSubLink(), fireRIRrules(), fix_opfuncids_walker(), fix_scan_expr_walker(), flatten_rtes_walker(), get_last_attnums_walker(), IncrementVarSublevelsUp_walker(), index_expression_changed_walker(), inline_cte_walker(), isQueryUsingTempRelation_walker(), locate_agg_of_level_walker(), locate_var_of_level_walker(), locate_windowfunc_walker(), LockViewRecurse_walker(), max_parallel_hazard_walker(), OffsetVarNodes_walker(), preprocess_aggrefs_walker(), pull_exec_paramids_walker(), pull_paramids_walker(), pull_var_clause_walker(), pull_varattnos_walker(), pull_varnos_walker(), pull_vars_walker(), query_contains_extern_params_walker(), rangeTableEntry_used_walker(), ScanQueryWalker(), setRuleCheckAsUser_walker(), split_pathtarget_walker(), and substitute_phv_relids_walker().

◆ exprInputCollation()

Oid exprInputCollation ( const Node expr)

Definition at line 974 of file nodeFuncs.c.

975 {
976  Oid coll;
977 
978  if (!expr)
979  return InvalidOid;
980 
981  switch (nodeTag(expr))
982  {
983  case T_Aggref:
984  coll = ((const Aggref *) expr)->inputcollid;
985  break;
986  case T_WindowFunc:
987  coll = ((const WindowFunc *) expr)->inputcollid;
988  break;
989  case T_FuncExpr:
990  coll = ((const FuncExpr *) expr)->inputcollid;
991  break;
992  case T_OpExpr:
993  coll = ((const OpExpr *) expr)->inputcollid;
994  break;
995  case T_DistinctExpr:
996  coll = ((const DistinctExpr *) expr)->inputcollid;
997  break;
998  case T_NullIfExpr:
999  coll = ((const NullIfExpr *) expr)->inputcollid;
1000  break;
1001  case T_ScalarArrayOpExpr:
1002  coll = ((const ScalarArrayOpExpr *) expr)->inputcollid;
1003  break;
1004  case T_MinMaxExpr:
1005  coll = ((const MinMaxExpr *) expr)->inputcollid;
1006  break;
1007  default:
1008  coll = InvalidOid;
1009  break;
1010  }
1011  return coll;
1012 }

References InvalidOid, nodeTag, T_Aggref, T_DistinctExpr, T_FuncExpr, T_MinMaxExpr, T_NullIfExpr, T_OpExpr, T_ScalarArrayOpExpr, and T_WindowFunc.

Referenced by resolve_polymorphic_tupdesc().

◆ exprIsLengthCoercion()

bool exprIsLengthCoercion ( const Node expr,
int32 coercedTypmod 
)

Definition at line 503 of file nodeFuncs.c.

504 {
505  if (coercedTypmod != NULL)
506  *coercedTypmod = -1; /* default result on failure */
507 
508  /*
509  * Scalar-type length coercions are FuncExprs, array-type length coercions
510  * are ArrayCoerceExprs
511  */
512  if (expr && IsA(expr, FuncExpr))
513  {
514  const FuncExpr *func = (const FuncExpr *) expr;
515  int nargs;
516  Const *second_arg;
517 
518  /*
519  * If it didn't come from a coercion context, reject.
520  */
521  if (func->funcformat != COERCE_EXPLICIT_CAST &&
523  return false;
524 
525  /*
526  * If it's not a two-argument or three-argument function with the
527  * second argument being an int4 constant, it can't have been created
528  * from a length coercion (it must be a type coercion, instead).
529  */
530  nargs = list_length(func->args);
531  if (nargs < 2 || nargs > 3)
532  return false;
533 
534  second_arg = (Const *) lsecond(func->args);
535  if (!IsA(second_arg, Const) ||
536  second_arg->consttype != INT4OID ||
537  second_arg->constisnull)
538  return false;
539 
540  /*
541  * OK, it is indeed a length-coercion function.
542  */
543  if (coercedTypmod != NULL)
544  *coercedTypmod = DatumGetInt32(second_arg->constvalue);
545 
546  return true;
547  }
548 
549  if (expr && IsA(expr, ArrayCoerceExpr))
550  {
551  const ArrayCoerceExpr *acoerce = (const ArrayCoerceExpr *) expr;
552 
553  /* It's not a length coercion unless there's a nondefault typmod */
554  if (acoerce->resulttypmod < 0)
555  return false;
556 
557  /*
558  * OK, it is indeed a length-coercion expression.
559  */
560  if (coercedTypmod != NULL)
561  *coercedTypmod = acoerce->resulttypmod;
562 
563  return true;
564  }
565 
566  return false;
567 }
static int list_length(const List *l)
Definition: pg_list.h:149
#define lsecond(l)
Definition: pg_list.h:179
#define DatumGetInt32(X)
Definition: postgres.h:516
@ COERCE_IMPLICIT_CAST
Definition: primnodes.h:485
@ COERCE_EXPLICIT_CAST
Definition: primnodes.h:484
int32 resulttypmod
Definition: primnodes.h:907
Datum constvalue
Definition: primnodes.h:219
bool constisnull
Definition: primnodes.h:220
CoercionForm funcformat
Definition: primnodes.h:500

References FuncExpr::args, COERCE_EXPLICIT_CAST, COERCE_IMPLICIT_CAST, Const::constisnull, Const::consttype, Const::constvalue, DatumGetInt32, FuncExpr::funcformat, IsA, list_length(), lsecond, and ArrayCoerceExpr::resulttypmod.

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

◆ exprLocation()

int exprLocation ( const Node expr)

Definition at line 1250 of file nodeFuncs.c.

1251 {
1252  int loc;
1253 
1254  if (expr == NULL)
1255  return -1;
1256  switch (nodeTag(expr))
1257  {
1258  case T_RangeVar:
1259  loc = ((const RangeVar *) expr)->location;
1260  break;
1261  case T_TableFunc:
1262  loc = ((const TableFunc *) expr)->location;
1263  break;
1264  case T_Var:
1265  loc = ((const Var *) expr)->location;
1266  break;
1267  case T_Const:
1268  loc = ((const Const *) expr)->location;
1269  break;
1270  case T_Param:
1271  loc = ((const Param *) expr)->location;
1272  break;
1273  case T_Aggref:
1274  /* function name should always be the first thing */
1275  loc = ((const Aggref *) expr)->location;
1276  break;
1277  case T_GroupingFunc:
1278  loc = ((const GroupingFunc *) expr)->location;
1279  break;
1280  case T_WindowFunc:
1281  /* function name should always be the first thing */
1282  loc = ((const WindowFunc *) expr)->location;
1283  break;
1284  case T_SubscriptingRef:
1285  /* just use container argument's location */
1286  loc = exprLocation((Node *) ((const SubscriptingRef *) expr)->refexpr);
1287  break;
1288  case T_FuncExpr:
1289  {
1290  const FuncExpr *fexpr = (const FuncExpr *) expr;
1291 
1292  /* consider both function name and leftmost arg */
1293  loc = leftmostLoc(fexpr->location,
1294  exprLocation((Node *) fexpr->args));
1295  }
1296  break;
1297  case T_NamedArgExpr:
1298  {
1299  const NamedArgExpr *na = (const NamedArgExpr *) expr;
1300 
1301  /* consider both argument name and value */
1302  loc = leftmostLoc(na->location,
1303  exprLocation((Node *) na->arg));
1304  }
1305  break;
1306  case T_OpExpr:
1307  case T_DistinctExpr: /* struct-equivalent to OpExpr */
1308  case T_NullIfExpr: /* struct-equivalent to OpExpr */
1309  {
1310  const OpExpr *opexpr = (const OpExpr *) expr;
1311 
1312  /* consider both operator name and leftmost arg */
1313  loc = leftmostLoc(opexpr->location,
1314  exprLocation((Node *) opexpr->args));
1315  }
1316  break;
1317  case T_ScalarArrayOpExpr:
1318  {
1319  const ScalarArrayOpExpr *saopexpr = (const ScalarArrayOpExpr *) expr;
1320 
1321  /* consider both operator name and leftmost arg */
1322  loc = leftmostLoc(saopexpr->location,
1323  exprLocation((Node *) saopexpr->args));
1324  }
1325  break;
1326  case T_BoolExpr:
1327  {
1328  const BoolExpr *bexpr = (const BoolExpr *) expr;
1329 
1330  /*
1331  * Same as above, to handle either NOT or AND/OR. We can't
1332  * special-case NOT because of the way that it's used for
1333  * things like IS NOT BETWEEN.
1334  */
1335  loc = leftmostLoc(bexpr->location,
1336  exprLocation((Node *) bexpr->args));
1337  }
1338  break;
1339  case T_SubLink:
1340  {
1341  const SubLink *sublink = (const SubLink *) expr;
1342 
1343  /* check the testexpr, if any, and the operator/keyword */
1344  loc = leftmostLoc(exprLocation(sublink->testexpr),
1345  sublink->location);
1346  }
1347  break;
1348  case T_FieldSelect:
1349  /* just use argument's location */
1350  loc = exprLocation((Node *) ((const FieldSelect *) expr)->arg);
1351  break;
1352  case T_FieldStore:
1353  /* just use argument's location */
1354  loc = exprLocation((Node *) ((const FieldStore *) expr)->arg);
1355  break;
1356  case T_RelabelType:
1357  {
1358  const RelabelType *rexpr = (const RelabelType *) expr;
1359 
1360  /* Much as above */
1361  loc = leftmostLoc(rexpr->location,
1362  exprLocation((Node *) rexpr->arg));
1363  }
1364  break;
1365  case T_CoerceViaIO:
1366  {
1367  const CoerceViaIO *cexpr = (const CoerceViaIO *) expr;
1368 
1369  /* Much as above */
1370  loc = leftmostLoc(cexpr->location,
1371  exprLocation((Node *) cexpr->arg));
1372  }
1373  break;
1374  case T_ArrayCoerceExpr:
1375  {
1376  const ArrayCoerceExpr *cexpr = (const ArrayCoerceExpr *) expr;
1377 
1378  /* Much as above */
1379  loc = leftmostLoc(cexpr->location,
1380  exprLocation((Node *) cexpr->arg));
1381  }
1382  break;
1383  case T_ConvertRowtypeExpr:
1384  {
1385  const ConvertRowtypeExpr *cexpr = (const ConvertRowtypeExpr *) expr;
1386 
1387  /* Much as above */
1388  loc = leftmostLoc(cexpr->location,
1389  exprLocation((Node *) cexpr->arg));
1390  }
1391  break;
1392  case T_CollateExpr:
1393  /* just use argument's location */
1394  loc = exprLocation((Node *) ((const CollateExpr *) expr)->arg);
1395  break;
1396  case T_CaseExpr:
1397  /* CASE keyword should always be the first thing */
1398  loc = ((const CaseExpr *) expr)->location;
1399  break;
1400  case T_CaseWhen:
1401  /* WHEN keyword should always be the first thing */
1402  loc = ((const CaseWhen *) expr)->location;
1403  break;
1404  case T_ArrayExpr:
1405  /* the location points at ARRAY or [, which must be leftmost */
1406  loc = ((const ArrayExpr *) expr)->location;
1407  break;
1408  case T_RowExpr:
1409  /* the location points at ROW or (, which must be leftmost */
1410  loc = ((const RowExpr *) expr)->location;
1411  break;
1412  case T_RowCompareExpr:
1413  /* just use leftmost argument's location */
1414  loc = exprLocation((Node *) ((const RowCompareExpr *) expr)->largs);
1415  break;
1416  case T_CoalesceExpr:
1417  /* COALESCE keyword should always be the first thing */
1418  loc = ((const CoalesceExpr *) expr)->location;
1419  break;
1420  case T_MinMaxExpr:
1421  /* GREATEST/LEAST keyword should always be the first thing */
1422  loc = ((const MinMaxExpr *) expr)->location;
1423  break;
1424  case T_SQLValueFunction:
1425  /* function keyword should always be the first thing */
1426  loc = ((const SQLValueFunction *) expr)->location;
1427  break;
1428  case T_XmlExpr:
1429  {
1430  const XmlExpr *xexpr = (const XmlExpr *) expr;
1431 
1432  /* consider both function name and leftmost arg */
1433  loc = leftmostLoc(xexpr->location,
1434  exprLocation((Node *) xexpr->args));
1435  }
1436  break;
1437  case T_NullTest:
1438  {
1439  const NullTest *nexpr = (const NullTest *) expr;
1440 
1441  /* Much as above */
1442  loc = leftmostLoc(nexpr->location,
1443  exprLocation((Node *) nexpr->arg));
1444  }
1445  break;
1446  case T_BooleanTest:
1447  {
1448  const BooleanTest *bexpr = (const BooleanTest *) expr;
1449 
1450  /* Much as above */
1451  loc = leftmostLoc(bexpr->location,
1452  exprLocation((Node *) bexpr->arg));
1453  }
1454  break;
1455  case T_CoerceToDomain:
1456  {
1457  const CoerceToDomain *cexpr = (const CoerceToDomain *) expr;
1458 
1459  /* Much as above */
1460  loc = leftmostLoc(cexpr->location,
1461  exprLocation((Node *) cexpr->arg));
1462  }
1463  break;
1464  case T_CoerceToDomainValue:
1465  loc = ((const CoerceToDomainValue *) expr)->location;
1466  break;
1467  case T_SetToDefault:
1468  loc = ((const SetToDefault *) expr)->location;
1469  break;
1470  case T_TargetEntry:
1471  /* just use argument's location */
1472  loc = exprLocation((Node *) ((const TargetEntry *) expr)->expr);
1473  break;
1474  case T_IntoClause:
1475  /* use the contained RangeVar's location --- close enough */
1476  loc = exprLocation((Node *) ((const IntoClause *) expr)->rel);
1477  break;
1478  case T_List:
1479  {
1480  /* report location of first list member that has a location */
1481  ListCell *lc;
1482 
1483  loc = -1; /* just to suppress compiler warning */
1484  foreach(lc, (const List *) expr)
1485  {
1486  loc = exprLocation((Node *) lfirst(lc));
1487  if (loc >= 0)
1488  break;
1489  }
1490  }
1491  break;
1492  case T_A_Expr:
1493  {
1494  const A_Expr *aexpr = (const A_Expr *) expr;
1495 
1496  /* use leftmost of operator or left operand (if any) */
1497  /* we assume right operand can't be to left of operator */
1498  loc = leftmostLoc(aexpr->location,
1499  exprLocation(aexpr->lexpr));
1500  }
1501  break;
1502  case T_ColumnRef:
1503  loc = ((const ColumnRef *) expr)->location;
1504  break;
1505  case T_ParamRef:
1506  loc = ((const ParamRef *) expr)->location;
1507  break;
1508  case T_A_Const:
1509  loc = ((const A_Const *) expr)->location;
1510  break;
1511  case T_FuncCall:
1512  {
1513  const FuncCall *fc = (const FuncCall *) expr;
1514 
1515  /* consider both function name and leftmost arg */
1516  /* (we assume any ORDER BY nodes must be to right of name) */
1517  loc = leftmostLoc(fc->location,
1518  exprLocation((Node *) fc->args));
1519  }
1520  break;
1521  case T_A_ArrayExpr:
1522  /* the location points at ARRAY or [, which must be leftmost */
1523  loc = ((const A_ArrayExpr *) expr)->location;
1524  break;
1525  case T_ResTarget:
1526  /* we need not examine the contained expression (if any) */
1527  loc = ((const ResTarget *) expr)->location;
1528  break;
1529  case T_MultiAssignRef:
1530  loc = exprLocation(((const MultiAssignRef *) expr)->source);
1531  break;
1532  case T_TypeCast:
1533  {
1534  const TypeCast *tc = (const TypeCast *) expr;
1535 
1536  /*
1537  * This could represent CAST(), ::, or TypeName 'literal', so
1538  * any of the components might be leftmost.
1539  */
1540  loc = exprLocation(tc->arg);
1541  loc = leftmostLoc(loc, tc->typeName->location);
1542  loc = leftmostLoc(loc, tc->location);
1543  }
1544  break;
1545  case T_CollateClause:
1546  /* just use argument's location */
1547  loc = exprLocation(((const CollateClause *) expr)->arg);
1548  break;
1549  case T_SortBy:
1550  /* just use argument's location (ignore operator, if any) */
1551  loc = exprLocation(((const SortBy *) expr)->node);
1552  break;
1553  case T_WindowDef:
1554  loc = ((const WindowDef *) expr)->location;
1555  break;
1556  case T_RangeTableSample:
1557  loc = ((const RangeTableSample *) expr)->location;
1558  break;
1559  case T_TypeName:
1560  loc = ((const TypeName *) expr)->location;
1561  break;
1562  case T_ColumnDef:
1563  loc = ((const ColumnDef *) expr)->location;
1564  break;
1565  case T_Constraint:
1566  loc = ((const Constraint *) expr)->location;
1567  break;
1568  case T_FunctionParameter:
1569  /* just use typename's location */
1570  loc = exprLocation((Node *) ((const FunctionParameter *) expr)->argType);
1571  break;
1572  case T_XmlSerialize:
1573  /* XMLSERIALIZE keyword should always be the first thing */
1574  loc = ((const XmlSerialize *) expr)->location;
1575  break;
1576  case T_GroupingSet:
1577  loc = ((const GroupingSet *) expr)->location;
1578  break;
1579  case T_WithClause:
1580  loc = ((const WithClause *) expr)->location;
1581  break;
1582  case T_InferClause:
1583  loc = ((const InferClause *) expr)->location;
1584  break;
1585  case T_OnConflictClause:
1586  loc = ((const OnConflictClause *) expr)->location;
1587  break;
1588  case T_CTESearchClause:
1589  loc = ((const CTESearchClause *) expr)->location;
1590  break;
1591  case T_CTECycleClause:
1592  loc = ((const CTECycleClause *) expr)->location;
1593  break;
1594  case T_CommonTableExpr:
1595  loc = ((const CommonTableExpr *) expr)->location;
1596  break;
1597  case T_PlaceHolderVar:
1598  /* just use argument's location */
1599  loc = exprLocation((Node *) ((const PlaceHolderVar *) expr)->phexpr);
1600  break;
1601  case T_InferenceElem:
1602  /* just use nested expr's location */
1603  loc = exprLocation((Node *) ((const InferenceElem *) expr)->expr);
1604  break;
1605  case T_PartitionElem:
1606  loc = ((const PartitionElem *) expr)->location;
1607  break;
1608  case T_PartitionSpec:
1609  loc = ((const PartitionSpec *) expr)->location;
1610  break;
1611  case T_PartitionBoundSpec:
1612  loc = ((const PartitionBoundSpec *) expr)->location;
1613  break;
1614  case T_PartitionRangeDatum:
1615  loc = ((const PartitionRangeDatum *) expr)->location;
1616  break;
1617  default:
1618  /* for any other node type it's just unknown... */
1619  loc = -1;
1620  break;
1621  }
1622  return loc;
1623 }
static int leftmostLoc(int loc1, int loc2)
Definition: nodeFuncs.c:1631
int exprLocation(const Node *expr)
Definition: nodeFuncs.c:1250
@ T_RangeVar
Definition: nodes.h:154
@ T_Constraint
Definition: nodes.h:460
@ T_XmlSerialize
Definition: nodes.h:476
@ T_ColumnDef
Definition: nodes.h:457
@ T_PartitionElem
Definition: nodes.h:485
@ T_TypeName
Definition: nodes.h:456
@ T_GroupingSet
Definition: nodes.h:467
@ T_FunctionParameter
Definition: nodes.h:473
@ T_ResTarget
Definition: nodes.h:445
@ T_MultiAssignRef
Definition: nodes.h:446
@ T_A_ArrayExpr
Definition: nodes.h:444
@ T_FuncCall
Definition: nodes.h:440
@ T_A_Const
Definition: nodes.h:439
@ T_A_Expr
Definition: nodes.h:436
@ T_InferClause
Definition: nodes.h:478
@ T_SortBy
Definition: nodes.h:449
@ T_ParamRef
Definition: nodes.h:438
@ T_WithClause
Definition: nodes.h:477
@ T_WindowDef
Definition: nodes.h:450
@ T_PartitionSpec
Definition: nodes.h:486
@ T_CollateClause
Definition: nodes.h:448
@ T_RangeTableSample
Definition: nodes.h:453
@ T_ColumnRef
Definition: nodes.h:437
@ T_OnConflictClause
Definition: nodes.h:479
@ T_IntoClause
Definition: nodes.h:203
@ T_TypeCast
Definition: nodes.h:447
static rewind_source * source
Definition: pg_rewind.c:79
static int fc(const char *x)
Definition: preproc-init.c:99
int location
Definition: parsenodes.h:288
Node * lexpr
Definition: parsenodes.h:286
int location
Definition: primnodes.h:627
int location
Definition: primnodes.h:885
int location
Definition: primnodes.h:504
int location
Definition: primnodes.h:1268
int location
Definition: primnodes.h:549
TypeName * typeName
Definition: parsenodes.h:321
int location
Definition: parsenodes.h:322
Node * arg
Definition: parsenodes.h:320
int location
Definition: parsenodes.h:227
int location
Definition: primnodes.h:1235

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(), leftmostLoc(), A_Expr::lexpr, lfirst, TypeName::location, A_Expr::location, TypeCast::location, FuncExpr::location, NamedArgExpr::location, OpExpr::location, ScalarArrayOpExpr::location, BoolExpr::location, SubLink::location, RelabelType::location, CoerceViaIO::location, ArrayCoerceExpr::location, ConvertRowtypeExpr::location, XmlExpr::location, NullTest::location, BooleanTest::location, CoerceToDomain::location, nodeTag, source, T_A_ArrayExpr, T_A_Const, T_A_Expr, T_Aggref, T_ArrayCoerceExpr, T_ArrayExpr, T_BooleanTest, T_BoolExpr, T_CaseExpr, T_CaseWhen, T_CoalesceExpr, T_CoerceToDomain, T_CoerceToDomainValue, T_CoerceViaIO, T_CollateClause, T_CollateExpr, T_ColumnDef, T_ColumnRef, T_CommonTableExpr, T_Const, T_Constraint, T_ConvertRowtypeExpr, T_CTECycleClause, T_CTESearchClause, T_DistinctExpr, T_FieldSelect, T_FieldStore, T_FuncCall, T_FuncExpr, T_FunctionParameter, T_GroupingFunc, T_GroupingSet, T_InferClause, T_InferenceElem, T_IntoClause, T_List, T_MinMaxExpr, T_MultiAssignRef, T_NamedArgExpr, T_NullIfExpr, T_NullTest, T_OnConflictClause, T_OpExpr, T_Param, T_ParamRef, T_PartitionBoundSpec, T_PartitionElem, T_PartitionRangeDatum, T_PartitionSpec, T_PlaceHolderVar, T_RangeTableSample, T_RangeVar, T_RelabelType, T_ResTarget, T_RowCompareExpr, T_RowExpr, T_ScalarArrayOpExpr, T_SetToDefault, T_SortBy, T_SQLValueFunction, T_SubLink, T_SubscriptingRef, T_TableFunc, T_TargetEntry, T_TypeCast, T_TypeName, T_Var, T_WindowDef, T_WindowFunc, T_WithClause, T_XmlExpr, T_XmlSerialize, SubLink::testexpr, and TypeCast::typeName.

Referenced by addRangeTableEntryForFunction(), addTargetToSortList(), analyzeCTE(), array_subscript_transform(), assign_collations_walker(), check_agg_arguments_walker(), check_srf_call_placement(), checkWellFormedRecursion(), coerce_to_boolean(), coerce_to_common_type(), coerce_to_specific_type_typmod(), 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(), transformMultiAssignRef(), transformOnConflictArbiter(), transformPartitionBound(), transformPartitionBoundValue(), transformPartitionRangeBounds(), transformPLAssignStmt(), transformRangeFunction(), transformReturningList(), transformSelectStmt(), transformSetOperationStmt(), transformSetOperationTree(), transformValuesClause(), and validateInfiniteBounds().

◆ exprSetCollation()

void exprSetCollation ( Node expr,
Oid  collation 
)

Definition at line 1022 of file nodeFuncs.c.

1023 {
1024  switch (nodeTag(expr))
1025  {
1026  case T_Var:
1027  ((Var *) expr)->varcollid = collation;
1028  break;
1029  case T_Const:
1030  ((Const *) expr)->constcollid = collation;
1031  break;
1032  case T_Param:
1033  ((Param *) expr)->paramcollid = collation;
1034  break;
1035  case T_Aggref:
1036  ((Aggref *) expr)->aggcollid = collation;
1037  break;
1038  case T_GroupingFunc:
1039  Assert(!OidIsValid(collation));
1040  break;
1041  case T_WindowFunc:
1042  ((WindowFunc *) expr)->wincollid = collation;
1043  break;
1044  case T_SubscriptingRef:
1045  ((SubscriptingRef *) expr)->refcollid = collation;
1046  break;
1047  case T_FuncExpr:
1048  ((FuncExpr *) expr)->funccollid = collation;
1049  break;
1050  case T_NamedArgExpr:
1051  Assert(collation == exprCollation((Node *) ((NamedArgExpr *) expr)->arg));
1052  break;
1053  case T_OpExpr:
1054  ((OpExpr *) expr)->opcollid = collation;
1055  break;
1056  case T_DistinctExpr:
1057  ((DistinctExpr *) expr)->opcollid = collation;
1058  break;
1059  case T_NullIfExpr:
1060  ((NullIfExpr *) expr)->opcollid = collation;
1061  break;
1062  case T_ScalarArrayOpExpr:
1063  /* ScalarArrayOpExpr's result is boolean ... */
1064  Assert(!OidIsValid(collation)); /* ... so never set a collation */
1065  break;
1066  case T_BoolExpr:
1067  /* BoolExpr's result is boolean ... */
1068  Assert(!OidIsValid(collation)); /* ... so never set a collation */
1069  break;
1070  case T_SubLink:
1071 #ifdef USE_ASSERT_CHECKING
1072  {
1073  SubLink *sublink = (SubLink *) expr;
1074 
1075  if (sublink->subLinkType == EXPR_SUBLINK ||
1076  sublink->subLinkType == ARRAY_SUBLINK)
1077  {
1078  /* get the collation of subselect's first target column */
1079  Query *qtree = (Query *) sublink->subselect;
1080  TargetEntry *tent;
1081 
1082  if (!qtree || !IsA(qtree, Query))
1083  elog(ERROR, "cannot set collation for untransformed sublink");
1084  tent = linitial_node(TargetEntry, qtree->targetList);
1085  Assert(!tent->resjunk);
1086  Assert(collation == exprCollation((Node *) tent->expr));
1087  }
1088  else
1089  {
1090  /* otherwise, result is RECORD or BOOLEAN */
1091  Assert(!OidIsValid(collation));
1092  }
1093  }
1094 #endif /* USE_ASSERT_CHECKING */
1095  break;
1096  case T_FieldSelect:
1097  ((FieldSelect *) expr)->resultcollid = collation;
1098  break;
1099  case T_FieldStore:
1100  /* FieldStore's result is composite ... */
1101  Assert(!OidIsValid(collation)); /* ... so never set a collation */
1102  break;
1103  case T_RelabelType:
1104  ((RelabelType *) expr)->resultcollid = collation;
1105  break;
1106  case T_CoerceViaIO:
1107  ((CoerceViaIO *) expr)->resultcollid = collation;
1108  break;
1109  case T_ArrayCoerceExpr:
1110  ((ArrayCoerceExpr *) expr)->resultcollid = collation;
1111  break;
1112  case T_ConvertRowtypeExpr:
1113  /* ConvertRowtypeExpr's result is composite ... */
1114  Assert(!OidIsValid(collation)); /* ... so never set a collation */
1115  break;
1116  case T_CaseExpr:
1117  ((CaseExpr *) expr)->casecollid = collation;
1118  break;
1119  case T_ArrayExpr:
1120  ((ArrayExpr *) expr)->array_collid = collation;
1121  break;
1122  case T_RowExpr:
1123  /* RowExpr's result is composite ... */
1124  Assert(!OidIsValid(collation)); /* ... so never set a collation */
1125  break;
1126  case T_RowCompareExpr:
1127  /* RowCompareExpr's result is boolean ... */
1128  Assert(!OidIsValid(collation)); /* ... so never set a collation */
1129  break;
1130  case T_CoalesceExpr:
1131  ((CoalesceExpr *) expr)->coalescecollid = collation;
1132  break;
1133  case T_MinMaxExpr:
1134  ((MinMaxExpr *) expr)->minmaxcollid = collation;
1135  break;
1136  case T_SQLValueFunction:
1137  Assert((((SQLValueFunction *) expr)->type == NAMEOID) ?
1138  (collation == C_COLLATION_OID) :
1139  (collation == InvalidOid));
1140  break;
1141  case T_XmlExpr:
1142  Assert((((XmlExpr *) expr)->op == IS_XMLSERIALIZE) ?
1143  (collation == DEFAULT_COLLATION_OID) :
1144  (collation == InvalidOid));
1145  break;
1146  case T_NullTest:
1147  /* NullTest's result is boolean ... */
1148  Assert(!OidIsValid(collation)); /* ... so never set a collation */
1149  break;
1150  case T_BooleanTest:
1151  /* BooleanTest's result is boolean ... */
1152  Assert(!OidIsValid(collation)); /* ... so never set a collation */
1153  break;
1154  case T_CoerceToDomain:
1155  ((CoerceToDomain *) expr)->resultcollid = collation;
1156  break;
1157  case T_CoerceToDomainValue:
1158  ((CoerceToDomainValue *) expr)->collation = collation;
1159  break;
1160  case T_SetToDefault:
1161  ((SetToDefault *) expr)->collation = collation;
1162  break;
1163  case T_CurrentOfExpr:
1164  /* CurrentOfExpr's result is boolean ... */
1165  Assert(!OidIsValid(collation)); /* ... so never set a collation */
1166  break;
1167  case T_NextValueExpr:
1168  /* NextValueExpr's result is an integer type ... */
1169  Assert(!OidIsValid(collation)); /* ... so never set a collation */
1170  break;
1171  default:
1172  elog(ERROR, "unrecognized node type: %d", (int) nodeTag(expr));
1173  break;
1174  }
1175 }
#define OidIsValid(objectId)
Definition: c.h:710

References arg, ARRAY_SUBLINK, Assert(), elog, ERROR, EXPR_SUBLINK, exprCollation(), if(), InvalidOid, IS_XMLSERIALIZE, IsA, linitial_node, nodeTag, OidIsValid, SubLink::subLinkType, SubLink::subselect, T_Aggref, T_ArrayCoerceExpr, T_ArrayExpr, T_BooleanTest, T_BoolExpr, T_CaseExpr, T_CoalesceExpr, T_CoerceToDomain, T_CoerceToDomainValue, T_CoerceViaIO, T_Const, T_ConvertRowtypeExpr, T_CurrentOfExpr, T_DistinctExpr, T_FieldSelect, T_FieldStore, T_FuncExpr, T_GroupingFunc, T_MinMaxExpr, T_NamedArgExpr, T_NextValueExpr, T_NullIfExpr, T_NullTest, T_OpExpr, T_Param, T_RelabelType, T_RowCompareExpr, T_RowExpr, T_ScalarArrayOpExpr, T_SetToDefault, T_SQLValueFunction, T_SubLink, T_SubscriptingRef, T_Var, T_WindowFunc, T_XmlExpr, Query::targetList, and generate_unaccent_rules::type.

Referenced by assign_collations_walker().

◆ exprSetInputCollation()

void exprSetInputCollation ( Node expr,
Oid  inputcollation 
)

Definition at line 1186 of file nodeFuncs.c.

1187 {
1188  switch (nodeTag(expr))
1189  {
1190  case T_Aggref:
1191  ((Aggref *) expr)->inputcollid = inputcollation;
1192  break;
1193  case T_WindowFunc:
1194  ((WindowFunc *) expr)->inputcollid = inputcollation;
1195  break;
1196  case T_FuncExpr:
1197  ((FuncExpr *) expr)->inputcollid = inputcollation;
1198  break;
1199  case T_OpExpr:
1200  ((OpExpr *) expr)->inputcollid = inputcollation;
1201  break;
1202  case T_DistinctExpr:
1203  ((DistinctExpr *) expr)->inputcollid = inputcollation;
1204  break;
1205  case T_NullIfExpr:
1206  ((NullIfExpr *) expr)->inputcollid = inputcollation;
1207  break;
1208  case T_ScalarArrayOpExpr:
1209  ((ScalarArrayOpExpr *) expr)->inputcollid = inputcollation;
1210  break;
1211  case T_MinMaxExpr:
1212  ((MinMaxExpr *) expr)->inputcollid = inputcollation;
1213  break;
1214  default:
1215  break;
1216  }
1217 }

References nodeTag, T_Aggref, T_DistinctExpr, T_FuncExpr, T_MinMaxExpr, T_NullIfExpr, T_OpExpr, T_ScalarArrayOpExpr, and T_WindowFunc.

Referenced by assign_collations_walker().

◆ exprType()

Oid exprType ( const Node expr)

Definition at line 41 of file nodeFuncs.c.

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

References arg, ARRAY_SUBLINK, Assert(), elog, ereport, errcode(), errmsg(), ERROR, InferenceElem::expr, EXPR_SUBLINK, SubPlan::firstColType, format_type_be(), get_promoted_array_type(), if(), InvalidOid, IS_DOCUMENT, IS_XMLSERIALIZE, IsA, linitial, linitial_node, MULTIEXPR_SUBLINK, nodeTag, OidIsValid, SubLink::subLinkType, SubPlan::subLinkType, AlternativeSubPlan::subplans, SubLink::subselect, T_Aggref, T_AlternativeSubPlan, T_ArrayCoerceExpr, T_ArrayExpr, T_BooleanTest, T_BoolExpr, T_CaseExpr, T_CaseTestExpr, T_CoalesceExpr, T_CoerceToDomain, T_CoerceToDomainValue, T_CoerceViaIO, T_CollateExpr, T_Const, T_ConvertRowtypeExpr, T_CurrentOfExpr, T_DistinctExpr, T_FieldSelect, T_FieldStore, T_FuncExpr, T_GroupingFunc, T_InferenceElem, T_MinMaxExpr, T_NamedArgExpr, T_NextValueExpr, T_NullIfExpr, T_NullTest, T_OpExpr, T_Param, T_PlaceHolderVar, T_RelabelType, T_RowCompareExpr, T_RowExpr, T_ScalarArrayOpExpr, T_SetToDefault, T_SQLValueFunction, T_SubLink, T_SubPlan, T_SubscriptingRef, T_Var, T_WindowFunc, T_XmlExpr, Query::targetList, and generate_unaccent_rules::type.

Referenced by add_row_identity_var(), addRangeTableEntryForFunction(), addRangeTableEntryForSubquery(), addTargetToGroupList(), addTargetToSortList(), analyzeCTE(), analyzeCTETargetList(), appendAggOrderBy(), applyRelabelType(), array_subscript_transform(), assign_collations_walker(), assign_hypothetical_collations(), assign_param_for_placeholdervar(), ATExecAlterColumnType(), ATPrepAlterColumnType(), build_coercion_expression(), build_column_default(), build_subplan(), can_minmax_aggs(), canonicalize_ec_expression(), check_functions_in_node(), check_hashjoinable(), check_memoizable(), check_mergejoinable(), check_sql_fn_retval(), checkRuleResultList(), coerce_fn_result_column(), coerce_record_to_complex(), coerce_to_boolean(), coerce_to_common_type(), coerce_to_specific_type_typmod(), compare_tlist_datatypes(), compute_semijoin_info(), ComputeIndexAttrs(), ComputePartitionAttrs(), ConstructTupleDescriptor(), 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(), ExecEvalXmlExpr(), ExecInitExprRec(), ExecInitIndexScan(), ExecMakeTableFunctionResult(), ExecTypeFromExprList(), ExecTypeFromTLInternal(), ExecWindowAgg(), expandRecordVariable(), expandRTE(), exprTypmod(), find_expr_references_walker(), find_placeholder_info(), fix_indexqual_operand(), foreign_expr_walker(), generate_append_tlist(), generate_join_implied_equalities_normal(), generate_setop_tlist(), generate_subquery_params(), generateClonedIndexStmt(), get_call_expr_argtype(), get_expr_result_tupdesc(), get_expr_result_type(), get_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(), GetIndexInputType(), hash_ok_operator(), hstore_subscript_transform(), initialize_peragg(), inline_function(), internal_get_result_type(), jsonb_exec_setup(), jsonb_subscript_transform(), make_op(), make_scalar_array_op(), makeVarFromTargetEntry(), makeWholeRowVar(), match_pattern_prefix(), ordered_set_startup(), paraminfo_get_equal_hashops(), ParseFuncOrColumn(), pg_get_indexdef_worker(), pg_get_partkeydef_worker(), prepare_query_params(), preprocess_aggref(), preprocess_minmax_aggregates(), ProcedureCreate(), process_equivalence(), process_matched_tle(), recheck_cast_function_args(), relabel_to_typmod(), RelationBuildPartitionKey(), RelationGetDummyIndexExpressions(), remove_unused_subquery_outputs(), replace_nestloop_param_placeholdervar(), replace_outer_grouping(), replace_outer_placeholdervar(), resolveTargetListUnknowns(), scalararraysel(), select_common_type(), select_common_typmod(), set_append_rel_size(), set_dummy_tlist_references(), set_joinrel_partition_key_exprs(), set_pathtarget_cost_width(), set_rel_width(), show_sortorder_options(), tlist_same_datatypes(), transformAExprNullIf(), transformAggregateCall(), transformArrayExpr(), transformAssignedExpr(), transformAssignmentIndirection(), transformAssignmentSubscripts(), transformCaseExpr(), transformCollateClause(), transformExprRecurse(), transformFrameOffset(), transformFromClauseItem(), transformIndirection(), transformInsertStmt(), transformMultiAssignRef(), transformPartitionBoundValue(), transformPLAssignStmt(), transformSetOperationTree(), transformSubLink(), transformTypeCast(), unknown_attribute(), and xmlelement().

◆ exprTypmod()

int32 exprTypmod ( const Node expr)

Definition at line 267 of file nodeFuncs.c.

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

References arg, OpExpr::args, CaseExpr::args, CoalesceExpr::args, MinMaxExpr::args, ARRAY_SUBLINK, ArrayExpr::array_typeid, Assert(), CaseExpr::casetype, CoalesceExpr::coalescetype, CaseExpr::defresult, ArrayExpr::element_typeid, ArrayExpr::elements, elog, ERROR, EXPR_SUBLINK, exprIsLengthCoercion(), exprType(), SubPlan::firstColTypmod, for_each_from, if(), IsA, lfirst, lfirst_node, linitial, linitial_node, MinMaxExpr::minmaxtype, ArrayExpr::multidims, NIL, nodeTag, CaseWhen::result, SubLink::subLinkType, SubPlan::subLinkType, AlternativeSubPlan::subplans, SubLink::subselect, T_AlternativeSubPlan, T_ArrayCoerceExpr, T_ArrayExpr, T_CaseExpr, T_CaseTestExpr, T_CoalesceExpr, T_CoerceToDomain, T_CoerceToDomainValue, T_CollateExpr, T_Const, T_FieldSelect, T_FuncExpr, T_MinMaxExpr, T_NamedArgExpr, T_NullIfExpr, T_Param, T_PlaceHolderVar, T_RelabelType, T_SetToDefault, T_SQLValueFunction, T_SubLink, T_SubPlan, T_SubscriptingRef, T_Var, and Query::targetList.

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

◆ fix_opfuncids()

void fix_opfuncids ( Node node)

Definition at line 1652 of file nodeFuncs.c.

1653 {
1654  /* This tree walk requires no special setup, so away we go... */
1655  fix_opfuncids_walker(node, NULL);
1656 }
static bool fix_opfuncids_walker(Node *node, void *context)
Definition: nodeFuncs.c:1659

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

1660 {
1661  if (node == NULL)
1662  return false;
1663  if (IsA(node, OpExpr))
1664  set_opfuncid((OpExpr *) node);
1665  else if (IsA(node, DistinctExpr))
1666  set_opfuncid((OpExpr *) node); /* rely on struct equivalence */
1667  else if (IsA(node, NullIfExpr))
1668  set_opfuncid((OpExpr *) node); /* rely on struct equivalence */
1669  else if (IsA(node, ScalarArrayOpExpr))
1671  return expression_tree_walker(node, fix_opfuncids_walker, context);
1672 }

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

1632 {
1633  if (loc1 < 0)
1634  return loc2;
1635  else if (loc2 < 0)
1636  return loc1;
1637  else
1638  return Min(loc1, loc2);
1639 }
#define Min(x, y)
Definition: c.h:986

References Min.

Referenced by exprLocation().

◆ planstate_tree_walker()

bool planstate_tree_walker ( PlanState planstate,
bool(*)()  walker,
void *  context 
)

Definition at line 4035 of file nodeFuncs.c.

4038 {
4039  Plan *plan = planstate->plan;
4040  ListCell *lc;
4041 
4042  /* Guard against stack overflow due to overly complex plan trees */
4044 
4045  /* initPlan-s */
4046  if (planstate_walk_subplans(planstate->initPlan, walker, context))
4047  return true;
4048 
4049  /* lefttree */
4050  if (outerPlanState(planstate))
4051  {
4052  if (walker(outerPlanState(planstate), context))
4053  return true;
4054  }
4055 
4056  /* righttree */
4057  if (innerPlanState(planstate))
4058  {
4059  if (walker(innerPlanState(planstate), context))
4060  return true;
4061  }
4062 
4063  /* special child plans */
4064  switch (nodeTag(plan))
4065  {
4066  case T_Append:
4067  if (planstate_walk_members(((AppendState *) planstate)->appendplans,
4068  ((AppendState *) planstate)->as_nplans,
4069  walker, context))
4070  return true;
4071  break;
4072  case T_MergeAppend:
4073  if (planstate_walk_members(((MergeAppendState *) planstate)->mergeplans,
4074  ((MergeAppendState *) planstate)->ms_nplans,
4075  walker, context))
4076  return true;
4077  break;
4078  case T_BitmapAnd:
4079  if (planstate_walk_members(((BitmapAndState *) planstate)->bitmapplans,
4080  ((BitmapAndState *) planstate)->nplans,
4081  walker, context))
4082  return true;
4083  break;
4084  case T_BitmapOr:
4085  if (planstate_walk_members(((BitmapOrState *) planstate)->bitmapplans,
4086  ((BitmapOrState *) planstate)->nplans,
4087  walker, context))
4088  return true;
4089  break;
4090  case T_SubqueryScan:
4091  if (walker(((SubqueryScanState *) planstate)->subplan, context))
4092  return true;
4093  break;
4094  case T_CustomScan:
4095  foreach(lc, ((CustomScanState *) planstate)->custom_ps)
4096  {
4097  if (walker((PlanState *) lfirst(lc), context))
4098  return true;
4099  }
4100  break;
4101  default:
4102  break;
4103  }
4104 
4105  /* subPlan-s */
4106  if (planstate_walk_subplans(planstate->subPlan, walker, context))
4107  return true;
4108 
4109  return false;
4110 }
#define outerPlanState(node)
Definition: execnodes.h:1067
#define innerPlanState(node)
Definition: execnodes.h:1066
static bool planstate_walk_subplans(List *plans, bool(*walker)(), void *context)
Definition: nodeFuncs.c:4116
static bool planstate_walk_members(PlanState **planstates, int nplans, bool(*walker)(), void *context)
Definition: nodeFuncs.c:4138
@ T_BitmapOr
Definition: nodes.h:53
@ T_Append
Definition: nodes.h:49
@ T_BitmapAnd
Definition: nodes.h:52
@ T_MergeAppend
Definition: nodes.h:50
@ T_CustomScan
Definition: nodes.h:71
@ T_SubqueryScan
Definition: nodes.h:63
Plan * plan
Definition: execnodes.h:971
List * initPlan
Definition: execnodes.h:996

References check_stack_depth(), PlanState::initPlan, innerPlanState, lfirst, nodeTag, outerPlanState, PlanState::plan, planstate_walk_members(), planstate_walk_subplans(), PlanState::subPlan, T_Append, T_BitmapAnd, T_BitmapOr, T_CustomScan, T_MergeAppend, and T_SubqueryScan.

Referenced by ExecParallelEstimate(), ExecParallelInitializeDSM(), ExecParallelInitializeWorker(), ExecParallelReInitializeDSM(), ExecParallelReportInstrumentation(), ExecParallelRetrieveInstrumentation(), ExecShutdownNode(), and ExplainPreScanNode().

◆ planstate_walk_members()

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

Definition at line 4138 of file nodeFuncs.c.

4140 {
4141  int j;
4142 
4143  for (j = 0; j < nplans; j++)
4144  {
4145  if (walker(planstates[j], context))
4146  return true;
4147  }
4148 
4149  return false;
4150 }
int j
Definition: isn.c:74

References j.

Referenced by planstate_tree_walker().

◆ planstate_walk_subplans()

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

Definition at line 4116 of file nodeFuncs.c.

4119 {
4120  ListCell *lc;
4121 
4122  foreach(lc, plans)
4123  {
4125 
4126  if (walker(sps->planstate, context))
4127  return true;
4128  }
4129 
4130  return false;
4131 }
struct PlanState * planstate
Definition: execnodes.h:889

References lfirst_node, and SubPlanState::planstate.

Referenced by planstate_tree_walker().

◆ query_or_expression_tree_mutator()

Node* query_or_expression_tree_mutator ( Node node,
Node *(*)()  mutator,
void *  context,
int  flags 
)

Definition at line 3526 of file nodeFuncs.c.

3530 {
3531  if (node && IsA(node, Query))
3532  return (Node *) query_tree_mutator((Query *) node,
3533  mutator,
3534  context,
3535  flags);
3536  else
3537  return mutator(node, context);
3538 }
Query * query_tree_mutator(Query *query, Node *(*mutator)(), void *context, int flags)
Definition: nodeFuncs.c:3342

References IsA, and query_tree_mutator().

Referenced by map_variable_attnos(), and replace_rte_variables().

◆ query_or_expression_tree_walker()

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

Definition at line 3503 of file nodeFuncs.c.

3507 {
3508  if (node && IsA(node, Query))
3509  return query_tree_walker((Query *) node,
3510  walker,
3511  context,
3512  flags);
3513  else
3514  return walker(node, context);
3515 }
bool query_tree_walker(Query *query, bool(*walker)(), void *context, int flags)
Definition: nodeFuncs.c:2375

References IsA, and query_tree_walker().

Referenced by checkExprHasSubLink(), contain_aggs_of_level(), contain_vars_of_level(), contain_windowfuncs(), IncrementVarSublevelsUp(), locate_agg_of_level(), locate_var_of_level(), locate_windowfunc(), pull_varnos(), pull_varnos_of_level(), pull_vars_of_level(), rangeTableEntry_used(), and substitute_phv_relids().

◆ query_tree_mutator()

Query* query_tree_mutator ( Query query,
Node *(*)()  mutator,
void *  context,
int  flags 
)

Definition at line 3342 of file nodeFuncs.c.

3346 {
3347  Assert(query != NULL && IsA(query, Query));
3348 
3349  if (!(flags & QTW_DONT_COPY_QUERY))
3350  {
3351  Query *newquery;
3352 
3353  FLATCOPY(newquery, query, Query);
3354  query = newquery;
3355  }
3356 
3357  MUTATE(query->targetList, query->targetList, List *);
3358  MUTATE(query->withCheckOptions, query->withCheckOptions, List *);
3359  MUTATE(query->onConflict, query->onConflict, OnConflictExpr *);
3360  MUTATE(query->returningList, query->returningList, List *);
3361  MUTATE(query->jointree, query->jointree, FromExpr *);
3362  MUTATE(query->setOperations, query->setOperations, Node *);
3363  MUTATE(query->havingQual, query->havingQual, Node *);
3364  MUTATE(query->limitOffset, query->limitOffset, Node *);
3365  MUTATE(query->limitCount, query->limitCount, Node *);
3366 
3367  /*
3368  * Most callers aren't interested in SortGroupClause nodes since those
3369  * don't contain actual expressions. However they do contain OIDs, which
3370  * may be of interest to some mutators.
3371  */
3372 
3373  if ((flags & QTW_EXAMINE_SORTGROUP))
3374  {
3375  MUTATE(query->groupClause, query->groupClause, List *);
3376  MUTATE(query->windowClause, query->windowClause, List *);
3377  MUTATE(query->sortClause, query->sortClause, List *);
3378  MUTATE(query->distinctClause, query->distinctClause, List *);
3379  }
3380  else
3381  {
3382  /*
3383  * But we need to mutate the expressions under WindowClause nodes even
3384  * if we're not interested in SortGroupClause nodes.
3385  */
3386  List *resultlist;
3387  ListCell *temp;
3388 
3389  resultlist = NIL;
3390  foreach(temp, query->windowClause)
3391  {
3392  WindowClause *wc = lfirst_node(WindowClause, temp);
3393  WindowClause *newnode;
3394 
3395  FLATCOPY(newnode, wc, WindowClause);
3396  MUTATE(newnode->startOffset, wc->startOffset, Node *);
3397  MUTATE(newnode->endOffset, wc->endOffset, Node *);
3398 
3399  resultlist = lappend(resultlist, (Node *) newnode);
3400  }
3401  query->windowClause = resultlist;
3402  }
3403 
3404  /*
3405  * groupingSets and rowMarks are not mutated:
3406  *
3407  * groupingSets contain only ressortgroup refs (integers) which are
3408  * meaningless without the groupClause or tlist. Accordingly, any mutator
3409  * that needs to care about them needs to handle them itself in its Query
3410  * processing.
3411  *
3412  * rowMarks contains only rangetable indexes (and flags etc.) and
3413  * therefore should be handled at Query level similarly.
3414  */
3415 
3416  if (!(flags & QTW_IGNORE_CTE_SUBQUERIES))
3417  MUTATE(query->cteList, query->cteList, List *);
3418  else /* else copy CTE list as-is */
3419  query->cteList = copyObject(query->cteList);
3420  query->rtable = range_table_mutator(query->rtable,
3421  mutator, context, flags);
3422  return query;
3423 }
List * range_table_mutator(List *rtable, Node *(*mutator)(), void *context, int flags)
Definition: nodeFuncs.c:3431
#define QTW_DONT_COPY_QUERY
Definition: nodeFuncs.h:27
#define QTW_IGNORE_CTE_SUBQUERIES
Definition: nodeFuncs.h:21
#define QTW_EXAMINE_SORTGROUP
Definition: nodeFuncs.h:28
List * withCheckOptions
Definition: parsenodes.h:182
Node * limitCount
Definition: parsenodes.h:171
FromExpr * jointree
Definition: parsenodes.h:147
List * returningList
Definition: parsenodes.h:155
Node * setOperations
Definition: parsenodes.h:176
List * cteList
Definition: parsenodes.h:144
OnConflictExpr * onConflict
Definition: parsenodes.h:153
List * groupClause
Definition: parsenodes.h:157
Node * havingQual
Definition: parsenodes.h:162
List * rtable
Definition: parsenodes.h:146
Node * limitOffset
Definition: parsenodes.h:170
List * windowClause
Definition: parsenodes.h:164
List * distinctClause
Definition: parsenodes.h:166
List * sortClause
Definition: parsenodes.h:168

References Assert(), copyObject, Query::cteList, Query::distinctClause, WindowClause::endOffset, FLATCOPY, Query::groupClause, Query::havingQual, IsA, Query::jointree, lappend(), lfirst_node, Query::limitCount, Query::limitOffset, 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, Query::windowClause, and Query::withCheckOptions.

Referenced by flatten_join_alias_vars_mutator(), map_variable_attnos_mutator(), query_or_expression_tree_mutator(), replace_rte_variables_mutator(), substitute_actual_srf_parameters(), and substitute_actual_srf_parameters_mutator().

◆ query_tree_walker()

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

Definition at line 2375 of file nodeFuncs.c.

2379 {
2380  Assert(query != NULL && IsA(query, Query));
2381 
2382  /*
2383  * We don't walk any utilityStmt here. However, we can't easily assert
2384  * that it is absent, since there are at least two code paths by which
2385  * action statements from CREATE RULE end up here, and NOTIFY is allowed
2386  * in a rule action.
2387  */
2388 
2389  if (walker((Node *) query->targetList, context))
2390  return true;
2391  if (walker((Node *) query->withCheckOptions, context))
2392  return true;
2393  if (walker((Node *) query->onConflict, context))
2394  return true;
2395  if (walker((Node *) query->returningList, context))
2396  return true;
2397  if (walker((Node *) query->jointree, context))
2398  return true;
2399  if (walker(query->setOperations, context))
2400  return true;
2401  if (walker(query->havingQual, context))
2402  return true;
2403  if (walker(query->limitOffset, context))
2404  return true;
2405  if (walker(query->limitCount, context))
2406  return true;
2407 
2408  /*
2409  * Most callers aren't interested in SortGroupClause nodes since those
2410  * don't contain actual expressions. However they do contain OIDs which
2411  * may be needed by dependency walkers etc.
2412  */
2413  if ((flags & QTW_EXAMINE_SORTGROUP))
2414  {
2415  if (walker((Node *) query->groupClause, context))
2416  return true;
2417  if (walker((Node *) query->windowClause, context))
2418  return true;
2419  if (walker((Node *) query->sortClause, context))
2420  return true;
2421  if (walker((Node *) query->distinctClause, context))
2422  return true;
2423  }
2424  else
2425  {
2426  /*
2427  * But we need to walk the expressions under WindowClause nodes even
2428  * if we're not interested in SortGroupClause nodes.
2429  */
2430  ListCell *lc;
2431 
2432  foreach(lc, query->windowClause)
2433  {
2435 
2436  if (walker(wc->startOffset, context))
2437  return true;
2438  if (walker(wc->endOffset, context))
2439  return true;
2440  }
2441  }
2442 
2443  /*
2444  * groupingSets and rowMarks are not walked:
2445  *
2446  * groupingSets contain only ressortgrouprefs (integers) which are
2447  * meaningless without the corresponding groupClause or tlist.
2448  * Accordingly, any walker that needs to care about them needs to handle
2449  * them itself in its Query processing.
2450  *
2451  * rowMarks is not walked because it contains only rangetable indexes (and
2452  * flags etc.) and therefore should be handled at Query level similarly.
2453  */
2454 
2455  if (!(flags & QTW_IGNORE_CTE_SUBQUERIES))
2456  {
2457  if (walker((Node *) query->cteList, context))
2458  return true;
2459  }
2460  if (!(flags & QTW_IGNORE_RANGE_TABLE))
2461  {
2462  if (range_table_walker(query->rtable, walker, context, flags))
2463  return true;
2464  }
2465  return false;
2466 }
bool range_table_walker(List *rtable, bool(*walker)(), void *context, int flags)
Definition: nodeFuncs.c:2474
#define QTW_IGNORE_RANGE_TABLE
Definition: nodeFuncs.h:24

References Assert(), Query::cteList, Query::distinctClause, WindowClause::endOffset, Query::groupClause, Query::havingQual, IsA, Query::jointree, lfirst_node, Query::limitCount, Query::limitOffset, 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, Query::windowClause, and Query::withCheckOptions.

Referenced by AcquireRewriteLocks(), assign_query_collations(), ChangeVarNodes(), ChangeVarNodes_walker(), check_agg_arguments_walker(), check_parameter_resolution_walker(), check_ungrouped_columns_walker(), check_variable_parameters(), contain_aggs_of_level_walker(), contain_dml_walker(), contain_mutable_functions_walker(), contain_outer_selfref_walker(), contain_vars_of_level_walker(), contain_volatile_functions_not_nextval_walker(), contain_volatile_functions_walker(), extract_query_dependencies_walker(), finalize_grouping_exprs_walker(), find_dependent_phvs(), find_dependent_phvs_walker(), find_expr_references_walker(), fireRIRrules(), flatten_rtes_walker(), flatten_unplanned_rtes(), IncrementVarSublevelsUp_walker(), inline_cte_walker(), isQueryUsingTempRelation_walker(), locate_agg_of_level_walker(), locate_var_of_level_walker(), LockViewRecurse_walker(), max_parallel_hazard_walker(), OffsetVarNodes(), OffsetVarNodes_walker(), pull_varnos_walker(), pull_vars_walker(), query_contains_extern_params(), query_contains_extern_params_walker(), query_or_expression_tree_walker(), rangeTableEntry_used_walker(), rewriteTargetView(), ScanQueryForLocks(), setRuleCheckAsUser_Query(), and substitute_phv_relids_walker().

◆ range_table_entry_walker()

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

Definition at line 2495 of file nodeFuncs.c.

2499 {
2500  /*
2501  * Walkers might need to examine the RTE node itself either before or
2502  * after visiting its contents (or, conceivably, both). Note that if you
2503  * specify neither flag, the walker won't be called on the RTE at all.
2504  */
2505  if (flags & QTW_EXAMINE_RTES_BEFORE)
2506  if (walker(rte, context))
2507  return true;
2508 
2509  switch (rte->rtekind)
2510  {
2511  case RTE_RELATION:
2512  if (walker(rte->tablesample, context))
2513  return true;
2514  break;
2515  case RTE_SUBQUERY:
2516  if (!(flags & QTW_IGNORE_RT_SUBQUERIES))
2517  if (walker(rte->subquery, context))
2518  return true;
2519  break;
2520  case RTE_JOIN:
2521  if (!(flags & QTW_IGNORE_JOINALIASES))
2522  if (walker(rte->joinaliasvars, context))
2523  return true;
2524  break;
2525  case RTE_FUNCTION:
2526  if (walker(rte->functions, context))
2527  return true;
2528  break;
2529  case RTE_TABLEFUNC:
2530  if (walker(rte->tablefunc, context))
2531  return true;
2532  break;
2533  case RTE_VALUES:
2534  if (walker(rte->values_lists, context))
2535  return true;
2536  break;
2537  case RTE_CTE:
2538  case RTE_NAMEDTUPLESTORE:
2539  case RTE_RESULT:
2540  /* nothing to do */
2541  break;
2542  }
2543 
2544  if (walker(rte->securityQuals, context))
2545  return true;
2546 
2547  if (flags & QTW_EXAMINE_RTES_AFTER)
2548  if (walker(rte, context))
2549  return true;
2550 
2551  return false;
2552 }
#define QTW_IGNORE_RT_SUBQUERIES
Definition: nodeFuncs.h:20
#define QTW_EXAMINE_RTES_AFTER
Definition: nodeFuncs.h:26
#define QTW_EXAMINE_RTES_BEFORE
Definition: nodeFuncs.h:25
#define QTW_IGNORE_JOINALIASES
Definition: nodeFuncs.h:23
@ RTE_JOIN
Definition: parsenodes.h:992
@ RTE_CTE
Definition: parsenodes.h:996
@ RTE_NAMEDTUPLESTORE
Definition: parsenodes.h:997
@ RTE_VALUES
Definition: parsenodes.h:995
@ RTE_SUBQUERY
Definition: parsenodes.h:991
@ RTE_RESULT
Definition: parsenodes.h:998
@ RTE_FUNCTION
Definition: parsenodes.h:993
@ RTE_TABLEFUNC
Definition: parsenodes.h:994
@ RTE_RELATION
Definition: parsenodes.h:990
TableFunc * tablefunc
Definition: parsenodes.h:1107
struct TableSampleClause * tablesample
Definition: parsenodes.h:1037
List * securityQuals
Definition: parsenodes.h:1163
Query * subquery
Definition: parsenodes.h:1042
List * values_lists
Definition: parsenodes.h:1112
List * joinaliasvars
Definition: parsenodes.h:1082
List * functions
Definition: parsenodes.h:1101
RTEKind rtekind
Definition: parsenodes.h:1007

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

Referenced by find_dependent_phvs_in_jointree(), and range_table_walker().

◆ range_table_mutator()

List* range_table_mutator ( List rtable,
Node *(*)()  mutator,
void *  context,
int  flags 
)

Definition at line 3431 of file nodeFuncs.c.

3435 {
3436  List *newrt = NIL;
3437  ListCell *rt;
3438 
3439  foreach(rt, rtable)
3440  {
3441  RangeTblEntry *rte = (RangeTblEntry *) lfirst(rt);
3442  RangeTblEntry *newrte;
3443 
3444  FLATCOPY(newrte, rte, RangeTblEntry);
3445  switch (rte->rtekind)
3446  {
3447  case RTE_RELATION:
3448  MUTATE(newrte->tablesample, rte->tablesample,
3449  TableSampleClause *);
3450  /* we don't bother to copy eref, aliases, etc; OK? */
3451  break;
3452  case RTE_SUBQUERY:
3453  if (!(flags & QTW_IGNORE_RT_SUBQUERIES))
3454  {
3455  CHECKFLATCOPY(newrte->subquery, rte->subquery, Query);
3456  MUTATE(newrte->subquery, newrte->subquery, Query *);
3457  }
3458  else
3459  {
3460  /* else, copy RT subqueries as-is */
3461  newrte->subquery = copyObject(rte->subquery);
3462  }
3463  break;
3464  case RTE_JOIN:
3465  if (!(flags & QTW_IGNORE_JOINALIASES))
3466  MUTATE(newrte->joinaliasvars, rte->joinaliasvars, List *);
3467  else
3468  {
3469  /* else, copy join aliases as-is */
3470  newrte->joinaliasvars = copyObject(rte->joinaliasvars);
3471  }
3472  break;
3473  case RTE_FUNCTION:
3474  MUTATE(newrte->functions, rte->functions, List *);
3475  break;
3476  case RTE_TABLEFUNC:
3477  MUTATE(newrte->tablefunc, rte->tablefunc, TableFunc *);
3478  break;
3479  case RTE_VALUES:
3480  MUTATE(newrte->values_lists, rte->values_lists, List *);
3481  break;
3482  case RTE_CTE:
3483  case RTE_NAMEDTUPLESTORE:
3484  case RTE_RESULT:
3485  /* nothing to do */
3486  break;
3487  }
3488  MUTATE(newrte->securityQuals, rte->securityQuals, List *);
3489  newrt = lappend(newrt, newrte);
3490  }
3491  return newrt;
3492 }
#define CHECKFLATCOPY(newnode, node, nodetype)

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

Referenced by query_tree_mutator().

◆ range_table_walker()

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

Definition at line 2474 of file nodeFuncs.c.

2478 {
2479  ListCell *rt;
2480 
2481  foreach(rt, rtable)
2482  {
2484 
2485  if (range_table_entry_walker(rte, walker, context, flags))
2486  return true;
2487  }
2488  return false;
2489 }
bool range_table_entry_walker(RangeTblEntry *rte, bool(*walker)(), void *context, int flags)
Definition: nodeFuncs.c:2495

References lfirst_node, and range_table_entry_walker().

Referenced by IncrementVarSublevelsUp_rtable(), and query_tree_walker().

◆ raw_expression_tree_walker()

bool raw_expression_tree_walker ( Node node,
bool(*)()  walker,
void *  context 
)

Definition at line 3557 of file nodeFuncs.c.

3560 {
3561  ListCell *temp;
3562 
3563  /*
3564  * The walker has already visited the current node, and so we need only
3565  * recurse into any sub-nodes it has.
3566  */
3567  if (node == NULL)
3568  return false;
3569 
3570  /* Guard against stack overflow due to overly complex expressions */
3572 
3573  switch (nodeTag(node))
3574  {
3575  case T_SetToDefault:
3576  case T_CurrentOfExpr:
3577  case T_SQLValueFunction:
3578  case T_Integer:
3579  case T_Float:
3580  case T_Boolean:
3581  case T_String:
3582  case T_BitString:
3583  case T_ParamRef:
3584  case T_A_Const:
3585  case T_A_Star:
3586  /* primitive node types with no subnodes */
3587  break;
3588  case T_Alias:
3589  /* we assume the colnames list isn't interesting */
3590  break;
3591  case T_RangeVar:
3592  return walker(((RangeVar *) node)->alias, context);
3593  case T_GroupingFunc:
3594  return walker(((GroupingFunc *) node)->args, context);
3595  case T_SubLink:
3596  {
3597  SubLink *sublink = (SubLink *) node;
3598 
3599  if (walker(sublink->testexpr, context))
3600  return true;
3601  /* we assume the operName is not interesting */
3602  if (walker(sublink->subselect, context))
3603  return true;
3604  }
3605  break;
3606  case T_CaseExpr:
3607  {
3608  CaseExpr *caseexpr = (CaseExpr *) node;
3609 
3610  if (walker(caseexpr->arg, context))
3611  return true;
3612  /* we assume walker doesn't care about CaseWhens, either */
3613  foreach(temp, caseexpr->args)
3614  {
3615  CaseWhen *when = lfirst_node(CaseWhen, temp);
3616 
3617  if (walker(when->expr, context))
3618  return true;
3619  if (walker(when->result, context))
3620  return true;
3621  }
3622  if (walker(caseexpr->defresult, context))
3623  return true;
3624  }
3625  break;
3626  case T_RowExpr:
3627  /* Assume colnames isn't interesting */
3628  return walker(((RowExpr *) node)->args, context);
3629  case T_CoalesceExpr:
3630  return walker(((CoalesceExpr *) node)->args, context);
3631  case T_MinMaxExpr:
3632  return walker(((MinMaxExpr *) node)->args, context);
3633  case T_XmlExpr:
3634  {
3635  XmlExpr *xexpr = (XmlExpr *) node;
3636 
3637  if (walker(xexpr->named_args, context))
3638  return true;
3639  /* we assume walker doesn't care about arg_names */
3640  if (walker(xexpr->args, context))
3641  return true;
3642  }
3643  break;
3644  case T_NullTest:
3645  return walker(((NullTest *) node)->arg, context);
3646  case T_BooleanTest:
3647  return walker(((BooleanTest *) node)->arg, context);
3648  case T_JoinExpr:
3649  {
3650  JoinExpr *join = (JoinExpr *) node;
3651 
3652  if (walker(join->larg, context))
3653  return true;
3654  if (walker(join->rarg, context))
3655  return true;
3656  if (walker(join->quals, context))
3657  return true;
3658  if (walker(join->alias, context))
3659  return true;
3660  /* using list is deemed uninteresting */
3661  }
3662  break;
3663  case T_IntoClause:
3664  {
3665  IntoClause *into = (IntoClause *) node;
3666 
3667  if (walker(into->rel, context))
3668  return true;
3669  /* colNames, options are deemed uninteresting */
3670  /* viewQuery should be null in raw parsetree, but check it */
3671  if (walker(into->viewQuery, context))
3672  return true;
3673  }
3674  break;
3675  case T_List:
3676  foreach(temp, (List *) node)
3677  {
3678  if (walker((Node *) lfirst(temp), context))
3679  return true;
3680  }
3681  break;
3682  case T_InsertStmt:
3683  {
3684  InsertStmt *stmt = (InsertStmt *) node;
3685 
3686  if (walker(stmt->relation, context))
3687  return true;
3688  if (walker(stmt->cols, context))
3689  return true;
3690  if (walker(stmt->selectStmt, context))
3691  return true;
3692  if (walker(stmt->onConflictClause, context))
3693  return true;
3694  if (walker(stmt->returningList, context))
3695  return true;
3696  if (walker(stmt->withClause, context))
3697  return true;
3698  }
3699  break;
3700  case T_DeleteStmt:
3701  {
3702  DeleteStmt *stmt = (DeleteStmt *) node;
3703 
3704  if (walker(stmt->relation, context))
3705  return true;
3706  if (walker(stmt->usingClause, context))
3707  return true;
3708  if (walker(stmt->whereClause, context))
3709  return true;
3710  if (walker(stmt->returningList, context))
3711  return true;
3712  if (walker(stmt->withClause, context))
3713  return true;
3714  }
3715  break;
3716  case T_UpdateStmt:
3717  {
3718  UpdateStmt *stmt = (UpdateStmt *) node;
3719 
3720  if (walker(stmt->relation, context))
3721  return true;
3722  if (walker(stmt->targetList, context))
3723  return true;
3724  if (walker(stmt->whereClause, context))
3725  return true;
3726  if (walker(stmt->fromClause, context))
3727  return true;
3728  if (walker(stmt->returningList, context))
3729  return true;
3730  if (walker(stmt->withClause, context))
3731  return true;
3732  }
3733  break;
3734  case T_SelectStmt:
3735  {
3736  SelectStmt *stmt = (SelectStmt *) node;
3737 
3738  if (walker(stmt->distinctClause, context))
3739  return true;
3740  if (walker(stmt->intoClause, context))
3741  return true;
3742  if (walker(stmt->targetList, context))
3743  return true;
3744  if (walker(stmt->fromClause, context))
3745  return true;
3746  if (walker(stmt->whereClause, context))
3747  return true;
3748  if (walker(stmt->groupClause, context))
3749  return true;
3750  if (walker(stmt->havingClause, context))
3751  return true;
3752  if (walker(stmt->windowClause, context))
3753  return true;
3754  if (walker(stmt->valuesLists, context))
3755  return true;
3756  if (walker(stmt->sortClause, context))
3757  return true;
3758  if (walker(stmt->limitOffset, context))
3759  return true;
3760  if (walker(stmt->limitCount, context))
3761  return true;
3762  if (walker(stmt->lockingClause, context))
3763  return true;
3764  if (walker(stmt->withClause, context))
3765  return true;
3766  if (walker(stmt->larg, context))
3767  return true;
3768  if (walker(stmt->rarg, context))
3769  return true;
3770  }
3771  break;
3772  case T_PLAssignStmt:
3773  {
3774  PLAssignStmt *stmt = (PLAssignStmt *) node;
3775 
3776  if (walker(stmt->indirection, context))
3777  return true;
3778  if (walker(stmt->val, context))
3779  return true;
3780  }
3781  break;
3782  case T_A_Expr:
3783  {
3784  A_Expr *expr = (A_Expr *) node;
3785 
3786  if (walker(expr->lexpr, context))
3787  return true;
3788  if (walker(expr->rexpr, context))
3789  return true;
3790  /* operator name is deemed uninteresting */
3791  }
3792  break;
3793  case T_BoolExpr:
3794  {
3795  BoolExpr *expr = (BoolExpr *) node;
3796 
3797  if (walker(expr->args, context))
3798  return true;
3799  }
3800  break;
3801  case T_ColumnRef:
3802  /* we assume the fields contain nothing interesting */
3803  break;
3804  case T_FuncCall:
3805  {
3806  FuncCall *fcall = (FuncCall *) node;
3807 
3808  if (walker(fcall->args, context))
3809  return true;
3810  if (walker(fcall->agg_order, context))
3811  return true;
3812  if (walker(fcall->agg_filter, context))
3813  return true;
3814  if (walker(fcall->over, context))
3815  return true;
3816  /* function name is deemed uninteresting */
3817  }
3818  break;
3819  case T_NamedArgExpr:
3820  return walker(((NamedArgExpr *) node)->arg, context);
3821  case T_A_Indices:
3822  {
3823  A_Indices *indices = (A_Indices *) node;
3824 
3825  if (walker(indices->lidx, context))
3826  return true;
3827  if (walker(indices->uidx, context))
3828  return true;
3829  }
3830  break;
3831  case T_A_Indirection:
3832  {
3833  A_Indirection *indir = (A_Indirection *) node;
3834 
3835  if (walker(indir->arg, context))
3836  return true;
3837  if (walker(indir->indirection, context))
3838  return true;
3839  }
3840  break;
3841  case T_A_ArrayExpr:
3842  return walker(((A_ArrayExpr *) node)->elements, context);
3843  case T_ResTarget:
3844  {
3845  ResTarget *rt = (ResTarget *) node;
3846 
3847  if (walker(rt->indirection, context))
3848  return true;
3849  if (walker(rt->val, context))
3850  return true;
3851  }
3852  break;
3853  case T_MultiAssignRef:
3854  return walker(((MultiAssignRef *) node)->source, context);
3855  case T_TypeCast:
3856  {
3857  TypeCast *tc = (TypeCast *) node;
3858 
3859  if (walker(tc->arg, context))
3860  return true;
3861  if (walker(tc->typeName, context))
3862  return true;
3863  }
3864  break;
3865  case T_CollateClause:
3866  return walker(((CollateClause *) node)->arg, context);
3867  case T_SortBy:
3868  return walker(((SortBy *) node)->node, context);
3869  case T_WindowDef:
3870  {
3871  WindowDef *wd = (WindowDef *) node;
3872 
3873  if (walker(wd->partitionClause, context))
3874  return true;
3875  if (walker(wd->orderClause, context))
3876  return true;
3877  if (walker(wd->startOffset, context))
3878  return true;
3879  if (walker(wd->endOffset, context))
3880  return true;
3881  }
3882  break;
3883  case T_RangeSubselect:
3884  {
3885  RangeSubselect *rs = (RangeSubselect *) node;
3886 
3887  if (walker(rs->subquery, context))
3888  return true;
3889  if (walker(rs->alias, context))
3890  return true;
3891  }
3892  break;
3893  case T_RangeFunction:
3894  {
3895  RangeFunction *rf = (RangeFunction *) node;
3896 
3897  if (walker(rf->functions, context))
3898  return true;
3899  if (walker(rf->alias, context))
3900  return true;
3901  if (walker(rf->coldeflist, context))
3902  return true;
3903  }
3904  break;
3905  case T_RangeTableSample:
3906  {
3907  RangeTableSample *rts = (RangeTableSample *) node;
3908 
3909  if (walker(rts->relation, context))
3910  return true;
3911  /* method name is deemed uninteresting */
3912  if (walker(rts->args, context))
3913  return true;
3914  if (walker(rts->repeatable, context))
3915  return true;
3916  }
3917  break;
3918  case T_RangeTableFunc:
3919  {
3920  RangeTableFunc *rtf = (RangeTableFunc *) node;
3921 
3922  if (walker(rtf->docexpr, context))
3923  return true;
3924  if (walker(rtf->rowexpr, context))
3925  return true;
3926  if (walker(rtf->namespaces, context))
3927  return true;
3928  if (walker(rtf->columns, context))
3929  return true;
3930  if (walker(rtf->alias, context))
3931  return true;
3932  }
3933  break;
3934  case T_RangeTableFuncCol:
3935  {
3936  RangeTableFuncCol *rtfc = (RangeTableFuncCol *) node;
3937 
3938  if (walker(rtfc->colexpr, context))
3939  return true;
3940  if (walker(rtfc->coldefexpr, context))
3941  return true;
3942  }
3943  break;
3944  case T_TypeName:
3945  {
3946  TypeName *tn = (TypeName *) node;
3947 
3948  if (walker(tn->typmods, context))
3949  return true;
3950  if (walker(tn->arrayBounds, context))
3951  return true;
3952  /* type name itself is deemed uninteresting */
3953  }
3954  break;
3955  case T_ColumnDef:
3956  {
3957  ColumnDef *coldef = (ColumnDef *) node;
3958 
3959  if (walker(coldef->typeName, context))
3960  return true;
3961  if (walker(coldef->compression, context))
3962  return true;
3963  if (walker(coldef->raw_default, context))
3964  return true;
3965  if (walker(coldef->collClause, context))
3966  return true;
3967  /* for now, constraints are ignored */
3968  }
3969  break;
3970  case T_IndexElem:
3971  {
3972  IndexElem *indelem = (IndexElem *) node;
3973 
3974  if (walker(indelem->expr, context))
3975  return true;
3976  /* collation and opclass names are deemed uninteresting */
3977  }
3978  break;
3979  case T_GroupingSet:
3980  return walker(((GroupingSet *) node)->content, context);
3981  case T_LockingClause:
3982  return walker(((LockingClause *) node)->lockedRels, context);
3983  case T_XmlSerialize:
3984  {
3985  XmlSerialize *xs = (XmlSerialize *) node;
3986 
3987  if (walker(xs->expr, context))
3988  return true;
3989  if (walker(xs->typeName, context))
3990  return true;
3991  }
3992  break;
3993  case T_WithClause:
3994  return walker(((WithClause *) node)->ctes, context);
3995  case T_InferClause:
3996  {
3997  InferClause *stmt = (InferClause *) node;
3998 
3999  if (walker(stmt->indexElems, context))
4000  return true;
4001  if (walker(stmt->whereClause, context))
4002  return true;
4003  }
4004  break;
4005  case T_OnConflictClause:
4006  {
4007  OnConflictClause *stmt = (OnConflictClause *) node;
4008 
4009  if (walker(stmt->infer, context))
4010  return true;
4011  if (walker(stmt->targetList, context))
4012  return true;
4013  if (walker(stmt->whereClause, context))
4014  return true;
4015  }
4016  break;
4017  case T_CommonTableExpr:
4018  /* search_clause and cycle_clause are not interesting here */
4019  return walker(((CommonTableExpr *) node)->ctequery, context);
4020  default:
4021  elog(ERROR, "unrecognized node type: %d",
4022  (int) nodeTag(node));
4023  break;
4024  }
4025  return false;
4026 }
@ T_LockingClause
Definition: nodes.h:474
@ T_BitString
Definition: nodes.h:297
@ T_RangeTableFunc
Definition: nodes.h:454
@ T_RangeFunction
Definition: nodes.h:452
@ T_DeleteStmt
Definition: nodes.h:318
@ T_Alias
Definition: nodes.h:153
@ T_UpdateStmt
Definition: nodes.h:319
@ T_A_Indices
Definition: nodes.h:442
@ T_Float
Definition: nodes.h:294
@ T_String
Definition: nodes.h:296
@ T_A_Indirection
Definition: nodes.h:443
@ T_Integer
Definition: nodes.h:293
@ T_A_Star
Definition: nodes.h:441
@ T_InsertStmt
Definition: nodes.h:317
@ T_PLAssignStmt
Definition: nodes.h:322
@ T_SelectStmt
Definition: nodes.h:320
@ T_RangeSubselect
Definition: nodes.h:451
@ T_IndexElem
Definition: nodes.h:458
@ T_RangeTableFuncCol
Definition: nodes.h:455
@ T_Boolean
Definition: nodes.h:295
Node * rexpr
Definition: parsenodes.h:287
Node * uidx
Definition: parsenodes.h:408
Node * lidx
Definition: parsenodes.h:407
List * indirection
Definition: parsenodes.h:430
CollateClause * collClause
Definition: parsenodes.h:684
TypeName * typeName
Definition: parsenodes.h:671
Node * raw_default
Definition: parsenodes.h:678