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 WALK(n)   walker((Node *) (n), context)
 
#define LIST_WALK(l)   expression_tree_walker_impl((Node *) (l), walker, context)
 
#define FLATCOPY(newnode, node, nodetype)
 
#define MUTATE(newfield, oldfield, fieldtype)    ( (newfield) = (fieldtype) mutator((Node *) (oldfield), context) )
 
#define PSWALK(n)   walker(n, context)
 

Functions

static bool expression_returns_set_walker (Node *node, void *context)
 
static int leftmostLoc (int loc1, int loc2)
 
static bool fix_opfuncids_walker (Node *node, void *context)
 
static bool planstate_walk_subplans (List *plans, planstate_tree_walker_callback walker, void *context)
 
static bool planstate_walk_members (PlanState **planstates, int nplans, planstate_tree_walker_callback walker, void *context)
 
Oid exprType (const Node *expr)
 
int32 exprTypmod (const Node *expr)
 
bool exprIsLengthCoercion (const Node *expr, int32 *coercedTypmod)
 
NodeapplyRelabelType (Node *arg, Oid rtype, int32 rtypmod, Oid rcollid, CoercionForm rformat, int rlocation, bool overwrite_ok)
 
Noderelabel_to_typmod (Node *expr, int32 typmod)
 
Nodestrip_implicit_coercions (Node *node)
 
bool expression_returns_set (Node *clause)
 
Oid exprCollation (const Node *expr)
 
Oid exprInputCollation (const Node *expr)
 
void exprSetCollation (Node *expr, Oid collation)
 
void exprSetInputCollation (Node *expr, Oid inputcollation)
 
int exprLocation (const Node *expr)
 
void fix_opfuncids (Node *node)
 
void set_opfuncid (OpExpr *opexpr)
 
void set_sa_opfuncid (ScalarArrayOpExpr *opexpr)
 
bool check_functions_in_node (Node *node, check_function_callback checker, void *context)
 
bool expression_tree_walker_impl (Node *node, tree_walker_callback walker, void *context)
 
bool query_tree_walker_impl (Query *query, tree_walker_callback walker, void *context, int flags)
 
bool range_table_walker_impl (List *rtable, tree_walker_callback walker, void *context, int flags)
 
bool range_table_entry_walker_impl (RangeTblEntry *rte, tree_walker_callback walker, void *context, int flags)
 
Nodeexpression_tree_mutator_impl (Node *node, tree_mutator_callback mutator, void *context)
 
Queryquery_tree_mutator_impl (Query *query, tree_mutator_callback mutator, void *context, int flags)
 
Listrange_table_mutator_impl (List *rtable, tree_mutator_callback mutator, void *context, int flags)
 
bool query_or_expression_tree_walker_impl (Node *node, tree_walker_callback walker, void *context, int flags)
 
Nodequery_or_expression_tree_mutator_impl (Node *node, tree_mutator_callback mutator, void *context, int flags)
 
bool raw_expression_tree_walker_impl (Node *node, tree_walker_callback walker, void *context)
 
bool planstate_tree_walker_impl (PlanState *planstate, planstate_tree_walker_callback walker, void *context)
 

Macro Definition Documentation

◆ FLATCOPY

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

◆ LIST_WALK

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

◆ MUTATE

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

◆ PSWALK

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

◆ WALK

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

Function Documentation

◆ applyRelabelType()

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

Definition at line 603 of file nodeFuncs.c.

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

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

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

◆ check_functions_in_node()

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

Definition at line 1819 of file nodeFuncs.c.

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

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

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

◆ exprCollation()

Oid exprCollation ( const Node expr)

Definition at line 788 of file nodeFuncs.c.

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

References arg, ARRAY_SUBLINK, Assert(), JsonConstructorExpr::coercion, elog(), ERROR, EXPR_SUBLINK, SubPlan::firstColCollation, if(), InvalidOid, IS_XMLSERIALIZE, IsA, linitial, linitial_node, nodeTag, SubLink::subLinkType, SubPlan::subLinkType, AlternativeSubPlan::subplans, SubLink::subselect, Query::targetList, and 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(), check_simple_rowfilter_expr_walker(), coerce_type_typmod(), ComputeIndexAttrs(), ComputePartitionAttrs(), convert_EXISTS_to_ANY(), create_ctas_nodata(), create_limit_plan(), create_memoize_plan(), create_unique_plan(), create_windowagg_plan(), DefineVirtualRelation(), eval_const_expressions_mutator(), examine_attribute(), examine_expression(), ExecInitFunctionScan(), ExecInitIndexScan(), ExecTypeFromExprList(), ExecTypeFromTLInternal(), expandRecordVariable(), expandRTE(), exprSetCollation(), extract_grouping_collations(), fix_indexqual_operand(), generate_setop_tlist(), generate_subquery_params(), get_expr_result_type(), get_first_col_type(), inline_function(), make_pathkey_from_sortop(), make_recursive_union(), make_setop(), make_sort_from_groupcols(), make_sort_from_sortclauses(), make_unique_from_sortclauses(), makeCaseTestExpr(), makeVarFromTargetEntry(), makeWholeRowVar(), mcv_match_expression(), ordered_set_startup(), pg_get_indexdef_worker(), pg_get_partkeydef_worker(), preprocess_minmax_aggregates(), relabel_to_typmod(), RelationBuildPartitionKey(), RelationGetDummyIndexExpressions(), remove_unused_subquery_outputs(), replace_nestloop_param_placeholdervar(), replace_outer_placeholdervar(), scalararraysel(), set_dummy_tlist_references(), set_joinrel_partition_key_exprs(), tlist_same_collations(), transformCaseExpr(), transformFromClauseItem(), transformMultiAssignRef(), transformPLAssignStmt(), transformSubLink(), and transformWindowDefinitions().

◆ expression_returns_set()

◆ expression_returns_set_walker()

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

Definition at line 736 of file nodeFuncs.c.

737 {
738  if (node == NULL)
739  return false;
740  if (IsA(node, FuncExpr))
741  {
742  FuncExpr *expr = (FuncExpr *) node;
743 
744  if (expr->funcretset)
745  return true;
746  /* else fall through to check args */
747  }
748  if (IsA(node, OpExpr))
749  {
750  OpExpr *expr = (OpExpr *) node;
751 
752  if (expr->opretset)
753  return true;
754  /* else fall through to check args */
755  }
756 
757  /*
758  * If you add any more cases that return sets, also fix
759  * expression_returns_set_rows() in clauses.c and IS_SRF_CALL() in
760  * tlist.c.
761  */
762 
763  /* Avoid recursion for some cases that parser checks not to return a set */
764  if (IsA(node, Aggref))
765  return false;
766  if (IsA(node, GroupingFunc))
767  return false;
768  if (IsA(node, WindowFunc))
769  return false;
770 
772  context);
773 }
#define expression_tree_walker(n, w, c)
Definition: nodeFuncs.h:151

References expression_tree_walker, and IsA.

Referenced by expression_returns_set().

◆ expression_tree_mutator_impl()

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

Definition at line 2810 of file nodeFuncs.c.

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

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

◆ expression_tree_walker_impl()

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

Definition at line 2002 of file nodeFuncs.c.

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

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

◆ exprInputCollation()

Oid exprInputCollation ( const Node expr)

Definition at line 1020 of file nodeFuncs.c.

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

References InvalidOid, and nodeTag.

Referenced by check_simple_rowfilter_expr_walker(), and resolve_polymorphic_tupdesc().

◆ exprIsLengthCoercion()

bool exprIsLengthCoercion ( const Node expr,
int32 coercedTypmod 
)

Definition at line 524 of file nodeFuncs.c.

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

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

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

◆ exprLocation()

int exprLocation ( const Node expr)

Definition at line 1314 of file nodeFuncs.c.

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

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

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

◆ exprSetCollation()

void exprSetCollation ( Node expr,
Oid  collation 
)

Definition at line 1068 of file nodeFuncs.c.

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

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

Referenced by assign_collations_walker().

◆ exprSetInputCollation()

void exprSetInputCollation ( Node expr,
Oid  inputcollation 
)

Definition at line 1250 of file nodeFuncs.c.

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

References nodeTag.

Referenced by assign_collations_walker().

◆ exprType()

Oid exprType ( const Node expr)

Definition at line 43 of file nodeFuncs.c.

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

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

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

◆ exprTypmod()

int32 exprTypmod ( const Node expr)

Definition at line 284 of file nodeFuncs.c.

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

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

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

◆ fix_opfuncids()

void fix_opfuncids ( Node node)

Definition at line 1750 of file nodeFuncs.c.

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

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

1758 {
1759  if (node == NULL)
1760  return false;
1761  if (IsA(node, OpExpr))
1762  set_opfuncid((OpExpr *) node);
1763  else if (IsA(node, DistinctExpr))
1764  set_opfuncid((OpExpr *) node); /* rely on struct equivalence */
1765  else if (IsA(node, NullIfExpr))
1766  set_opfuncid((OpExpr *) node); /* rely on struct equivalence */
1767  else if (IsA(node, ScalarArrayOpExpr))
1769  return expression_tree_walker(node, fix_opfuncids_walker, context);
1770 }

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

1730 {
1731  if (loc1 < 0)
1732  return loc2;
1733  else if (loc2 < 0)
1734  return loc1;
1735  else
1736  return Min(loc1, loc2);
1737 }
#define Min(x, y)
Definition: c.h:988

References Min.

Referenced by exprLocation().

◆ planstate_tree_walker_impl()

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

Definition at line 4423 of file nodeFuncs.c.

4426 {
4427  Plan *plan = planstate->plan;
4428  ListCell *lc;
4429 
4430  /* We don't need implicit coercions to Node here */
4431 #define PSWALK(n) walker(n, context)
4432 
4433  /* Guard against stack overflow due to overly complex plan trees */
4435 
4436  /* initPlan-s */
4437  if (planstate_walk_subplans(planstate->initPlan, walker, context))
4438  return true;
4439 
4440  /* lefttree */
4441  if (outerPlanState(planstate))
4442  {
4443  if (PSWALK(outerPlanState(planstate)))
4444  return true;
4445  }
4446 
4447  /* righttree */
4448  if (innerPlanState(planstate))
4449  {
4450  if (PSWALK(innerPlanState(planstate)))
4451  return true;
4452  }
4453 
4454  /* special child plans */
4455  switch (nodeTag(plan))
4456  {
4457  case T_Append:
4458  if (planstate_walk_members(((AppendState *) planstate)->appendplans,
4459  ((AppendState *) planstate)->as_nplans,
4460  walker, context))
4461  return true;
4462  break;
4463  case T_MergeAppend:
4464  if (planstate_walk_members(((MergeAppendState *) planstate)->mergeplans,
4465  ((MergeAppendState *) planstate)->ms_nplans,
4466  walker, context))
4467  return true;
4468  break;
4469  case T_BitmapAnd:
4470  if (planstate_walk_members(((BitmapAndState *) planstate)->bitmapplans,
4471  ((BitmapAndState *) planstate)->nplans,
4472  walker, context))
4473  return true;
4474  break;
4475  case T_BitmapOr:
4476  if (planstate_walk_members(((BitmapOrState *) planstate)->bitmapplans,
4477  ((BitmapOrState *) planstate)->nplans,
4478  walker, context))
4479  return true;
4480  break;
4481  case T_SubqueryScan:
4482  if (PSWALK(((SubqueryScanState *) planstate)->subplan))
4483  return true;
4484  break;
4485  case T_CustomScan:
4486  foreach(lc, ((CustomScanState *) planstate)->custom_ps)
4487  {
4488  if (PSWALK(lfirst(lc)))
4489  return true;
4490  }
4491  break;
4492  default:
4493  break;
4494  }
4495 
4496  /* subPlan-s */
4497  if (planstate_walk_subplans(planstate->subPlan, walker, context))
4498  return true;
4499 
4500  return false;
4501 }
#define outerPlanState(node)
Definition: execnodes.h:1133
#define innerPlanState(node)
Definition: execnodes.h:1132
static bool planstate_walk_subplans(List *plans, planstate_tree_walker_callback walker, void *context)
Definition: nodeFuncs.c:4507
#define PSWALK(n)
static bool planstate_walk_members(PlanState **planstates, int nplans, planstate_tree_walker_callback walker, void *context)
Definition: nodeFuncs.c:4529
#define plan(x)
Definition: pg_regress.c:154
Plan * plan
Definition: execnodes.h:1037
List * initPlan
Definition: execnodes.h:1062

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

◆ planstate_walk_members()

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

Definition at line 4529 of file nodeFuncs.c.

4532 {
4533  int j;
4534 
4535  for (j = 0; j < nplans; j++)
4536  {
4537  if (PSWALK(planstates[j]))
4538  return true;
4539  }
4540 
4541  return false;
4542 }
int j
Definition: isn.c:74

References j, and PSWALK.

Referenced by planstate_tree_walker_impl().

◆ planstate_walk_subplans()

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

Definition at line 4507 of file nodeFuncs.c.

4510 {
4511  ListCell *lc;
4512 
4513  foreach(lc, plans)
4514  {
4516 
4517  if (PSWALK(sps->planstate))
4518  return true;
4519  }
4520 
4521  return false;
4522 }
struct PlanState * planstate
Definition: execnodes.h:953

References lfirst_node, SubPlanState::planstate, and PSWALK.

Referenced by planstate_tree_walker_impl().

◆ query_or_expression_tree_mutator_impl()

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

Definition at line 3771 of file nodeFuncs.c.

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

References IsA, and query_tree_mutator.

◆ query_or_expression_tree_walker_impl()

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

Definition at line 3748 of file nodeFuncs.c.

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

References IsA, query_tree_walker, and WALK.

◆ query_tree_mutator_impl()

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

Definition at line 3589 of file nodeFuncs.c.

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

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

◆ query_tree_walker_impl()

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

Definition at line 2565 of file nodeFuncs.c.

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

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

◆ range_table_entry_walker_impl()

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

Definition at line 2687 of file nodeFuncs.c.

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

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

◆ range_table_mutator_impl()

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

Definition at line 3679 of file nodeFuncs.c.

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

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

◆ range_table_walker_impl()

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

Definition at line 2666 of file nodeFuncs.c.

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

References lfirst_node, and range_table_entry_walker.

◆ raw_expression_tree_walker_impl()

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

Definition at line 3802 of file nodeFuncs.c.

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

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

◆ relabel_to_typmod()

Node* relabel_to_typmod ( Node expr,
int32  typmod 
)

Definition at line 656 of file nodeFuncs.c.

657 {
658  return applyRelabelType(expr, exprType(expr), typmod, exprCollation(expr),
659  COERCE_EXPLICIT_CAST, -1, false);
660 }
Node * applyRelabelType(Node *arg, Oid rtype, int32 rtypmod, Oid rcollid, CoercionForm rformat, int rlocation, bool overwrite_ok)
Definition: nodeFuncs.c:603

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

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

◆ set_opfuncid()

◆ set_sa_opfuncid()

void set_sa_opfuncid ( ScalarArrayOpExpr opexpr)

Definition at line 1792 of file nodeFuncs.c.

1793 {
1794  if (opexpr->opfuncid == InvalidOid)
1795  opexpr->opfuncid = get_opcode(opexpr->opno);
1796 }

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

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

◆ strip_implicit_coercions()

Node* strip_implicit_coercions ( Node node)

Definition at line 672 of file nodeFuncs.c.

673 {
674  if (node == NULL)
675  return NULL;
676  if (IsA(node, FuncExpr))
677  {
678  FuncExpr *f = (FuncExpr *) node;
679 
680  if (f->funcformat == COERCE_IMPLICIT_CAST)
682  }
683  else if (IsA(node, RelabelType))
684  {
685