PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
nodeFuncs.h File Reference
#include "nodes/parsenodes.h"
Include dependency graph for nodeFuncs.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define QTW_IGNORE_RT_SUBQUERIES   0x01 /* subqueries in rtable */
 
#define QTW_IGNORE_CTE_SUBQUERIES   0x02 /* subqueries in cteList */
 
#define QTW_IGNORE_RC_SUBQUERIES   0x03 /* both of above */
 
#define QTW_IGNORE_JOINALIASES   0x04 /* JOIN alias var lists */
 
#define QTW_IGNORE_RANGE_TABLE   0x08 /* skip rangetable entirely */
 
#define QTW_EXAMINE_RTES   0x10 /* examine RTEs */
 
#define QTW_DONT_COPY_QUERY   0x20 /* do not copy top Query */
 

Typedefs

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

Functions

Oid exprType (const Node *expr)
 
int32 exprTypmod (const Node *expr)
 
bool exprIsLengthCoercion (const Node *expr, int32 *coercedTypmod)
 
Noderelabel_to_typmod (Node *expr, int32 typmod)
 
Nodestrip_implicit_coercions (Node *node)
 
bool expression_returns_set (Node *clause)
 
Oid exprCollation (const Node *expr)
 
Oid exprInputCollation (const Node *expr)
 
void exprSetCollation (Node *expr, Oid collation)
 
void exprSetInputCollation (Node *expr, Oid inputcollation)
 
int exprLocation (const Node *expr)
 
void fix_opfuncids (Node *node)
 
void set_opfuncid (OpExpr *opexpr)
 
void set_sa_opfuncid (ScalarArrayOpExpr *opexpr)
 
bool check_functions_in_node (Node *node, check_function_callback checker, void *context)
 
bool expression_tree_walker (Node *node, bool(*walker)(), void *context)
 
Nodeexpression_tree_mutator (Node *node, Node *(*mutator)(), void *context)
 
bool query_tree_walker (Query *query, bool(*walker)(), void *context, int flags)
 
Queryquery_tree_mutator (Query *query, Node *(*mutator)(), void *context, int flags)
 
bool range_table_walker (List *rtable, bool(*walker)(), void *context, int flags)
 
Listrange_table_mutator (List *rtable, Node *(*mutator)(), void *context, int flags)
 
bool query_or_expression_tree_walker (Node *node, bool(*walker)(), void *context, int flags)
 
Nodequery_or_expression_tree_mutator (Node *node, Node *(*mutator)(), void *context, int flags)
 
bool raw_expression_tree_walker (Node *node, bool(*walker)(), void *context)
 
bool planstate_tree_walker (struct PlanState *planstate, bool(*walker)(), void *context)
 

Macro Definition Documentation

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

Definition at line 26 of file nodeFuncs.h.

Referenced by query_tree_mutator().

#define QTW_EXAMINE_RTES   0x10 /* examine RTEs */
#define QTW_IGNORE_CTE_SUBQUERIES   0x02 /* subqueries in cteList */

Definition at line 21 of file nodeFuncs.h.

Referenced by assign_query_collations(), query_tree_mutator(), and query_tree_walker().

#define QTW_IGNORE_JOINALIASES   0x04 /* JOIN alias var lists */
#define QTW_IGNORE_RANGE_TABLE   0x08 /* skip rangetable entirely */

Definition at line 24 of file nodeFuncs.h.

Referenced by assign_query_collations(), and query_tree_walker().

#define QTW_IGNORE_RC_SUBQUERIES   0x03 /* both of above */
#define QTW_IGNORE_RT_SUBQUERIES   0x01 /* subqueries in rtable */

Definition at line 20 of file nodeFuncs.h.

Referenced by range_table_mutator(), and range_table_walker().

Typedef Documentation

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

Definition at line 29 of file nodeFuncs.h.

Function Documentation

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

Definition at line 1673 of file nodeFuncs.c.

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

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

1675 {
1676  switch (nodeTag(node))
1677  {
1678  case T_Aggref:
1679  {
1680  Aggref *expr = (Aggref *) node;
1681 
1682  if (checker(expr->aggfnoid, context))
1683  return true;
1684  }
1685  break;
1686  case T_WindowFunc:
1687  {
1688  WindowFunc *expr = (WindowFunc *) node;
1689 
1690  if (checker(expr->winfnoid, context))
1691  return true;
1692  }
1693  break;
1694  case T_FuncExpr:
1695  {
1696  FuncExpr *expr = (FuncExpr *) node;
1697 
1698  if (checker(expr->funcid, context))
1699  return true;
1700  }
1701  break;
1702  case T_OpExpr:
1703  case T_DistinctExpr: /* struct-equivalent to OpExpr */
1704  case T_NullIfExpr: /* struct-equivalent to OpExpr */
1705  {
1706  OpExpr *expr = (OpExpr *) node;
1707 
1708  /* Set opfuncid if it wasn't set already */
1709  set_opfuncid(expr);
1710  if (checker(expr->opfuncid, context))
1711  return true;
1712  }
1713  break;
1714  case T_ScalarArrayOpExpr:
1715  {
1716  ScalarArrayOpExpr *expr = (ScalarArrayOpExpr *) node;
1717 
1718  set_sa_opfuncid(expr);
1719  if (checker(expr->opfuncid, context))
1720  return true;
1721  }
1722  break;
1723  case T_CoerceViaIO:
1724  {
1725  CoerceViaIO *expr = (CoerceViaIO *) node;
1726  Oid iofunc;
1727  Oid typioparam;
1728  bool typisvarlena;
1729 
1730  /* check the result type's input function */
1732  &iofunc, &typioparam);
1733  if (checker(iofunc, context))
1734  return true;
1735  /* check the input type's output function */
1736  getTypeOutputInfo(exprType((Node *) expr->arg),
1737  &iofunc, &typisvarlena);
1738  if (checker(iofunc, context))
1739  return true;
1740  }
1741  break;
1742  case T_ArrayCoerceExpr:
1743  {
1744  ArrayCoerceExpr *expr = (ArrayCoerceExpr *) node;
1745 
1746  if (OidIsValid(expr->elemfuncid) &&
1747  checker(expr->elemfuncid, context))
1748  return true;
1749  }
1750  break;
1751  case T_RowCompareExpr:
1752  {
1753  RowCompareExpr *rcexpr = (RowCompareExpr *) node;
1754  ListCell *opid;
1755 
1756  foreach(opid, rcexpr->opnos)
1757  {
1758  Oid opfuncid = get_opcode(lfirst_oid(opid));
1759 
1760  if (checker(opfuncid, context))
1761  return true;
1762  }
1763  }
1764  break;
1765  default:
1766  break;
1767  }
1768  return false;
1769 }
void getTypeOutputInfo(Oid type, Oid *typOutput, bool *typIsVarlena)
Definition: lsyscache.c:2632
Oid resulttype
Definition: primnodes.h:811
Definition: nodes.h:509
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:538
Oid funcid
Definition: primnodes.h:448
Oid winfnoid
Definition: primnodes.h:355
Expr * arg
Definition: primnodes.h:810
void getTypeInputInfo(Oid type, Oid *typInput, Oid *typIOParam)
Definition: lsyscache.c:2599
Oid opfuncid
Definition: primnodes.h:496
RegProcedure get_opcode(Oid opno)
Definition: lsyscache.c:1094
Oid aggfnoid
Definition: primnodes.h:294
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:42
#define nodeTag(nodeptr)
Definition: nodes.h:514
void set_opfuncid(OpExpr *opexpr)
Definition: nodeFuncs.c:1635
void set_sa_opfuncid(ScalarArrayOpExpr *opexpr)
Definition: nodeFuncs.c:1646
#define lfirst_oid(lc)
Definition: pg_list.h:108
Oid exprCollation ( const Node expr)

Definition at line 748 of file nodeFuncs.c.

References arg, ARRAY_SUBLINK, Assert, DEFAULT_COLLATION_OID, elog, ERROR, EXPR_SUBLINK, exprCollation(), SubPlan::firstColCollation, InvalidOid, IS_XMLSERIALIZE, IsA, linitial, linitial_node, nodeTag, SubLink::subLinkType, SubPlan::subLinkType, AlternativeSubPlan::subplans, SubLink::subselect, T_Aggref, T_AlternativeSubPlan, T_ArrayCoerceExpr, T_ArrayExpr, T_ArrayRef, T_BooleanTest, T_BoolExpr, T_CaseExpr, T_CaseTestExpr, T_CoalesceExpr, T_CoerceToDomain, T_CoerceToDomainValue, T_CoerceViaIO, T_CollateExpr, T_Const, T_ConvertRowtypeExpr, T_CurrentOfExpr, T_DistinctExpr, T_FieldSelect, T_FieldStore, T_FuncExpr, T_GroupingFunc, T_InferenceElem, T_MinMaxExpr, T_NamedArgExpr, T_NextValueExpr, T_NullIfExpr, T_NullTest, T_OpExpr, T_Param, T_PlaceHolderVar, T_RelabelType, T_RowCompareExpr, T_RowExpr, T_ScalarArrayOpExpr, T_SetToDefault, T_SQLValueFunction, T_SubLink, T_SubPlan, T_Var, T_WindowFunc, T_XmlExpr, and Query::targetList.

Referenced by analyzeCTE(), analyzeCTETargetList(), assign_collations_walker(), assign_hypothetical_collations(), assign_nestloop_param_placeholdervar(), build_expression_pathkey(), build_pertrans_for_aggref(), build_subplan(), canonicalize_ec_expression(), ComputeIndexAttrs(), ComputePartitionAttrs(), convert_EXISTS_to_ANY(), create_ctas_nodata(), DefineVirtualRelation(), eval_const_expressions_mutator(), ExecInitFunctionScan(), ExecInitIndexScan(), ExecTypeFromExprList(), ExecTypeFromTLInternal(), expandRecordVariable(), expandRTE(), exprCollation(), exprSetCollation(), fix_indexqual_operand(), generate_setop_tlist(), generate_subquery_params(), get_first_col_type(), get_rte_attribute_type(), inline_function(), make_pathkey_from_sortop(), make_sort_from_groupcols(), make_sort_from_sortclauses(), makeVarFromTargetEntry(), makeWholeRowVar(), ordered_set_startup(), pg_get_indexdef_worker(), pg_get_partkeydef_worker(), preprocess_minmax_aggregates(), relabel_to_typmod(), RelationBuildPartitionKey(), remove_unused_subquery_outputs(), replace_outer_placeholdervar(), scalararraysel(), set_dummy_tlist_references(), tlist_same_collations(), transformCaseExpr(), transformMultiAssignRef(), and transformSubLink().

749 {
750  Oid coll;
751 
752  if (!expr)
753  return InvalidOid;
754 
755  switch (nodeTag(expr))
756  {
757  case T_Var:
758  coll = ((const Var *) expr)->varcollid;
759  break;
760  case T_Const:
761  coll = ((const Const *) expr)->constcollid;
762  break;
763  case T_Param:
764  coll = ((const Param *) expr)->paramcollid;
765  break;
766  case T_Aggref:
767  coll = ((const Aggref *) expr)->aggcollid;
768  break;
769  case T_GroupingFunc:
770  coll = InvalidOid;
771  break;
772  case T_WindowFunc:
773  coll = ((const WindowFunc *) expr)->wincollid;
774  break;
775  case T_ArrayRef:
776  coll = ((const ArrayRef *) expr)->refcollid;
777  break;
778  case T_FuncExpr:
779  coll = ((const FuncExpr *) expr)->funccollid;
780  break;
781  case T_NamedArgExpr:
782  coll = exprCollation((Node *) ((const NamedArgExpr *) expr)->arg);
783  break;
784  case T_OpExpr:
785  coll = ((const OpExpr *) expr)->opcollid;
786  break;
787  case T_DistinctExpr:
788  coll = ((const DistinctExpr *) expr)->opcollid;
789  break;
790  case T_NullIfExpr:
791  coll = ((const NullIfExpr *) expr)->opcollid;
792  break;
793  case T_ScalarArrayOpExpr:
794  coll = InvalidOid; /* result is always boolean */
795  break;
796  case T_BoolExpr:
797  coll = InvalidOid; /* result is always boolean */
798  break;
799  case T_SubLink:
800  {
801  const SubLink *sublink = (const SubLink *) expr;
802 
803  if (sublink->subLinkType == EXPR_SUBLINK ||
804  sublink->subLinkType == ARRAY_SUBLINK)
805  {
806  /* get the collation of subselect's first target column */
807  Query *qtree = (Query *) sublink->subselect;
808  TargetEntry *tent;
809 
810  if (!qtree || !IsA(qtree, Query))
811  elog(ERROR, "cannot get collation for untransformed sublink");
812  tent = linitial_node(TargetEntry, qtree->targetList);
813  Assert(!tent->resjunk);
814  coll = exprCollation((Node *) tent->expr);
815  /* collation doesn't change if it's converted to array */
816  }
817  else
818  {
819  /* otherwise, result is RECORD or BOOLEAN */
820  coll = InvalidOid;
821  }
822  }
823  break;
824  case T_SubPlan:
825  {
826  const SubPlan *subplan = (const SubPlan *) expr;
827 
828  if (subplan->subLinkType == EXPR_SUBLINK ||
829  subplan->subLinkType == ARRAY_SUBLINK)
830  {
831  /* get the collation of subselect's first target column */
832  coll = subplan->firstColCollation;
833  /* collation doesn't change if it's converted to array */
834  }
835  else
836  {
837  /* otherwise, result is RECORD or BOOLEAN */
838  coll = InvalidOid;
839  }
840  }
841  break;
843  {
844  const AlternativeSubPlan *asplan = (const AlternativeSubPlan *) expr;
845 
846  /* subplans should all return the same thing */
847  coll = exprCollation((Node *) linitial(asplan->subplans));
848  }
849  break;
850  case T_FieldSelect:
851  coll = ((const FieldSelect *) expr)->resultcollid;
852  break;
853  case T_FieldStore:
854  coll = InvalidOid; /* result is always composite */
855  break;
856  case T_RelabelType:
857  coll = ((const RelabelType *) expr)->resultcollid;
858  break;
859  case T_CoerceViaIO:
860  coll = ((const CoerceViaIO *) expr)->resultcollid;
861  break;
862  case T_ArrayCoerceExpr:
863  coll = ((const ArrayCoerceExpr *) expr)->resultcollid;
864  break;
866  coll = InvalidOid; /* result is always composite */
867  break;
868  case T_CollateExpr:
869  coll = ((const CollateExpr *) expr)->collOid;
870  break;
871  case T_CaseExpr:
872  coll = ((const CaseExpr *) expr)->casecollid;
873  break;
874  case T_CaseTestExpr:
875  coll = ((const CaseTestExpr *) expr)->collation;
876  break;
877  case T_ArrayExpr:
878  coll = ((const ArrayExpr *) expr)->array_collid;
879  break;
880  case T_RowExpr:
881  coll = InvalidOid; /* result is always composite */
882  break;
883  case T_RowCompareExpr:
884  coll = InvalidOid; /* result is always boolean */
885  break;
886  case T_CoalesceExpr:
887  coll = ((const CoalesceExpr *) expr)->coalescecollid;
888  break;
889  case T_MinMaxExpr:
890  coll = ((const MinMaxExpr *) expr)->minmaxcollid;
891  break;
892  case T_SQLValueFunction:
893  coll = InvalidOid; /* all cases return non-collatable types */
894  break;
895  case T_XmlExpr:
896 
897  /*
898  * XMLSERIALIZE returns text from non-collatable inputs, so its
899  * collation is always default. The other cases return boolean or
900  * XML, which are non-collatable.
901  */
902  if (((const XmlExpr *) expr)->op == IS_XMLSERIALIZE)
903  coll = DEFAULT_COLLATION_OID;
904  else
905  coll = InvalidOid;
906  break;
907  case T_NullTest:
908  coll = InvalidOid; /* result is always boolean */
909  break;
910  case T_BooleanTest:
911  coll = InvalidOid; /* result is always boolean */
912  break;
913  case T_CoerceToDomain:
914  coll = ((const CoerceToDomain *) expr)->resultcollid;
915  break;
917  coll = ((const CoerceToDomainValue *) expr)->collation;
918  break;
919  case T_SetToDefault:
920  coll = ((const SetToDefault *) expr)->collation;
921  break;
922  case T_CurrentOfExpr:
923  coll = InvalidOid; /* result is always boolean */
924  break;
925  case T_NextValueExpr:
926  coll = InvalidOid; /* result is always an integer type */
927  break;
928  case T_InferenceElem:
929  coll = exprCollation((Node *) ((const InferenceElem *) expr)->expr);
930  break;
931  case T_PlaceHolderVar:
932  coll = exprCollation((Node *) ((const PlaceHolderVar *) expr)->phexpr);
933  break;
934  default:
935  elog(ERROR, "unrecognized node type: %d", (int) nodeTag(expr));
936  coll = InvalidOid; /* keep compiler quiet */
937  break;
938  }
939  return coll;
940 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:560
SubLinkType subLinkType
Definition: primnodes.h:683
Definition: nodes.h:509
unsigned int Oid
Definition: postgres_ext.h:31
Definition: primnodes.h:163
#define linitial_node(type, l)
Definition: pg_list.h:114
List * targetList
Definition: parsenodes.h:138
#define linitial(l)
Definition: pg_list.h:111
#define ERROR
Definition: elog.h:43
#define DEFAULT_COLLATION_OID
Definition: pg_collation.h:75
Definition: nodes.h:147
Definition: nodes.h:146
#define InvalidOid
Definition: postgres_ext.h:36
#define Assert(condition)
Definition: c.h:675
Oid exprCollation(const Node *expr)
Definition: nodeFuncs.c:748
#define nodeTag(nodeptr)
Definition: nodes.h:514
void * arg
Oid firstColCollation
Definition: primnodes.h:694
#define elog
Definition: elog.h:219
Definition: nodes.h:148
bool expression_returns_set ( Node clause)
Node* expression_tree_mutator ( Node node,
Node *(*)()  mutator,
void *  context 
)

Definition at line 2432 of file nodeFuncs.c.

References Aggref::aggargtypes, Aggref::aggdirectargs, Aggref::aggdistinct, Aggref::aggfilter, WindowFunc::aggfilter, Aggref::aggorder, OnConflictExpr::arbiterElems, OnConflictExpr::arbiterWhere, NamedArgExpr::arg, FieldSelect::arg, FieldStore::arg, RelabelType::arg, CoerceViaIO::arg, ArrayCoerceExpr::arg, ConvertRowtypeExpr::arg, CollateExpr::arg, CaseExpr::arg, NullTest::arg, BooleanTest::arg, CoerceToDomain::arg, Aggref::args, GroupingFunc::args, WindowFunc::args, FuncExpr::args, OpExpr::args, ScalarArrayOpExpr::args, BoolExpr::args, SubPlan::args, CaseExpr::args, RowExpr::args, CoalesceExpr::args, MinMaxExpr::args, TableSampleClause::args, XmlExpr::args, check_stack_depth(), TableFunc::coldefexprs, TableFunc::colexprs, GroupingFunc::cols, copyObject, CommonTableExpr::ctequery, CaseExpr::defresult, TableFunc::docexpr, ArrayExpr::elements, elog, WindowClause::endOffset, ERROR, OnConflictExpr::exclRelTlist, CaseWhen::expr, InferenceElem::expr, TargetEntry::expr, FieldStore::fieldnums, FLATCOPY, FromExpr::fromlist, RangeTblFunction::funcexpr, lappend(), JoinExpr::larg, SetOperationStmt::larg, RowCompareExpr::largs, lfirst, list_copy(), MUTATE, XmlExpr::named_args, FieldStore::newvals, NIL, nodeTag, TableFunc::ns_uris, NULL, OnConflictExpr::onConflictSet, OnConflictExpr::onConflictWhere, WindowClause::orderClause, WindowClause::partitionClause, PlaceHolderInfo::ph_var, PlaceHolderVar::phexpr, WithCheckOption::qual, JoinExpr::quals, FromExpr::quals, JoinExpr::rarg, SetOperationStmt::rarg, RowCompareExpr::rargs, ArrayRef::refassgnexpr, ArrayRef::refexpr, ArrayRef::reflowerindexpr, GroupingFunc::refs, ArrayRef::refupperindexpr, TableSampleClause::repeatable, CaseWhen::result, TableFunc::rowexpr, WindowClause::startOffset, AlternativeSubPlan::subplans, SubLink::subselect, T_Aggref, T_AlternativeSubPlan, T_AppendRelInfo, T_ArrayCoerceExpr, T_ArrayExpr, T_ArrayRef, T_BooleanTest, T_BoolExpr, T_CaseExpr, T_CaseTestExpr, T_CaseWhen, T_CoalesceExpr, T_CoerceToDomain, T_CoerceToDomainValue, T_CoerceViaIO, T_CollateExpr, T_CommonTableExpr, T_Const, T_ConvertRowtypeExpr, T_CurrentOfExpr, T_DistinctExpr, T_FieldSelect, T_FieldStore, T_FromExpr, T_FuncExpr, T_GroupingFunc, T_InferenceElem, T_JoinExpr, T_List, T_MinMaxExpr, T_NamedArgExpr, T_NextValueExpr, T_NullIfExpr, T_NullTest, T_OnConflictExpr, T_OpExpr, T_Param, T_PlaceHolderInfo, T_PlaceHolderVar, T_Query, T_RangeTblFunction, T_RangeTblRef, T_RelabelType, T_RowCompareExpr, T_RowExpr, T_ScalarArrayOpExpr, T_SetOperationStmt, T_SetToDefault, T_SortGroupClause, T_SQLValueFunction, T_SubLink, T_SubPlan, T_TableFunc, T_TableSampleClause, T_TargetEntry, T_Var, T_WindowClause, T_WindowFunc, T_WithCheckOption, T_XmlExpr, SubLink::testexpr, SubPlan::testexpr, and AppendRelInfo::translated_vars.

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

2435 {
2436  /*
2437  * The mutator has already decided not to modify the current node, but we
2438  * must call the mutator for any sub-nodes.
2439  */
2440 
2441 #define FLATCOPY(newnode, node, nodetype) \
2442  ( (newnode) = (nodetype *) palloc(sizeof(nodetype)), \
2443  memcpy((newnode), (node), sizeof(nodetype)) )
2444 
2445 #define CHECKFLATCOPY(newnode, node, nodetype) \
2446  ( AssertMacro(IsA((node), nodetype)), \
2447  (newnode) = (nodetype *) palloc(sizeof(nodetype)), \
2448  memcpy((newnode), (node), sizeof(nodetype)) )
2449 
2450 #define MUTATE(newfield, oldfield, fieldtype) \
2451  ( (newfield) = (fieldtype) mutator((Node *) (oldfield), context) )
2452 
2453  if (node == NULL)
2454  return NULL;
2455 
2456  /* Guard against stack overflow due to overly complex expressions */
2458 
2459  switch (nodeTag(node))
2460  {
2461  /*
2462  * Primitive node types with no expression subnodes. Var and
2463  * Const are frequent enough to deserve special cases, the others
2464  * we just use copyObject for.
2465  */
2466  case T_Var:
2467  {
2468  Var *var = (Var *) node;
2469  Var *newnode;
2470 
2471  FLATCOPY(newnode, var, Var);
2472  return (Node *) newnode;
2473  }
2474  break;
2475  case T_Const:
2476  {
2477  Const *oldnode = (Const *) node;
2478  Const *newnode;
2479 
2480  FLATCOPY(newnode, oldnode, Const);
2481  /* XXX we don't bother with datumCopy; should we? */
2482  return (Node *) newnode;
2483  }
2484  break;
2485  case T_Param:
2486  case T_CoerceToDomainValue:
2487  case T_CaseTestExpr:
2488  case T_SetToDefault:
2489  case T_CurrentOfExpr:
2490  case T_NextValueExpr:
2491  case T_SQLValueFunction:
2492  case T_RangeTblRef:
2493  case T_SortGroupClause:
2494  return (Node *) copyObject(node);
2495  case T_WithCheckOption:
2496  {
2497  WithCheckOption *wco = (WithCheckOption *) node;
2498  WithCheckOption *newnode;
2499 
2500  FLATCOPY(newnode, wco, WithCheckOption);
2501  MUTATE(newnode->qual, wco->qual, Node *);
2502  return (Node *) newnode;
2503  }
2504  case T_Aggref:
2505  {
2506  Aggref *aggref = (Aggref *) node;
2507  Aggref *newnode;
2508 
2509  FLATCOPY(newnode, aggref, Aggref);
2510  /* assume mutation doesn't change types of arguments */
2511  newnode->aggargtypes = list_copy(aggref->aggargtypes);
2512  MUTATE(newnode->aggdirectargs, aggref->aggdirectargs, List *);
2513  MUTATE(newnode->args, aggref->args, List *);
2514  MUTATE(newnode->aggorder, aggref->aggorder, List *);
2515  MUTATE(newnode->aggdistinct, aggref->aggdistinct, List *);
2516  MUTATE(newnode->aggfilter, aggref->aggfilter, Expr *);
2517  return (Node *) newnode;
2518  }
2519  break;
2520  case T_GroupingFunc:
2521  {
2522  GroupingFunc *grouping = (GroupingFunc *) node;
2523  GroupingFunc *newnode;
2524 
2525  FLATCOPY(newnode, grouping, GroupingFunc);
2526  MUTATE(newnode->args, grouping->args, List *);
2527 
2528  /*
2529  * We assume here that mutating the arguments does not change
2530  * the semantics, i.e. that the arguments are not mutated in a
2531  * way that makes them semantically different from their
2532  * previously matching expressions in the GROUP BY clause.
2533  *
2534  * If a mutator somehow wanted to do this, it would have to
2535  * handle the refs and cols lists itself as appropriate.
2536  */
2537  newnode->refs = list_copy(grouping->refs);
2538  newnode->cols = list_copy(grouping->cols);
2539 
2540  return (Node *) newnode;
2541  }
2542  break;
2543  case T_WindowFunc:
2544  {
2545  WindowFunc *wfunc = (WindowFunc *) node;
2546  WindowFunc *newnode;
2547 
2548  FLATCOPY(newnode, wfunc, WindowFunc);
2549  MUTATE(newnode->args, wfunc->args, List *);
2550  MUTATE(newnode->aggfilter, wfunc->aggfilter, Expr *);
2551  return (Node *) newnode;
2552  }
2553  break;
2554  case T_ArrayRef:
2555  {
2556  ArrayRef *arrayref = (ArrayRef *) node;
2557  ArrayRef *newnode;
2558 
2559  FLATCOPY(newnode, arrayref, ArrayRef);
2560  MUTATE(newnode->refupperindexpr, arrayref->refupperindexpr,
2561  List *);
2562  MUTATE(newnode->reflowerindexpr, arrayref->reflowerindexpr,
2563  List *);
2564  MUTATE(newnode->refexpr, arrayref->refexpr,
2565  Expr *);
2566  MUTATE(newnode->refassgnexpr, arrayref->refassgnexpr,
2567  Expr *);
2568  return (Node *) newnode;
2569  }
2570  break;
2571  case T_FuncExpr:
2572  {
2573  FuncExpr *expr = (FuncExpr *) node;
2574  FuncExpr *newnode;
2575 
2576  FLATCOPY(newnode, expr, FuncExpr);
2577  MUTATE(newnode->args, expr->args, List *);
2578  return (Node *) newnode;
2579  }
2580  break;
2581  case T_NamedArgExpr:
2582  {
2583  NamedArgExpr *nexpr = (NamedArgExpr *) node;
2584  NamedArgExpr *newnode;
2585 
2586  FLATCOPY(newnode, nexpr, NamedArgExpr);
2587  MUTATE(newnode->arg, nexpr->arg, Expr *);
2588  return (Node *) newnode;
2589  }
2590  break;
2591  case T_OpExpr:
2592  {
2593  OpExpr *expr = (OpExpr *) node;
2594  OpExpr *newnode;
2595 
2596  FLATCOPY(newnode, expr, OpExpr);
2597  MUTATE(newnode->args, expr->args, List *);
2598  return (Node *) newnode;
2599  }
2600  break;
2601  case T_DistinctExpr:
2602  {
2603  DistinctExpr *expr = (DistinctExpr *) node;
2604  DistinctExpr *newnode;
2605 
2606  FLATCOPY(newnode, expr, DistinctExpr);
2607  MUTATE(newnode->args, expr->args, List *);
2608  return (Node *) newnode;
2609  }
2610  break;
2611  case T_NullIfExpr:
2612  {
2613  NullIfExpr *expr = (NullIfExpr *) node;
2614  NullIfExpr *newnode;
2615 
2616  FLATCOPY(newnode, expr, NullIfExpr);
2617  MUTATE(newnode->args, expr->args, List *);
2618  return (Node *) newnode;
2619  }
2620  break;
2621  case T_ScalarArrayOpExpr:
2622  {
2623  ScalarArrayOpExpr *expr = (ScalarArrayOpExpr *) node;
2624  ScalarArrayOpExpr *newnode;
2625 
2626  FLATCOPY(newnode, expr, ScalarArrayOpExpr);
2627  MUTATE(newnode->args, expr->args, List *);
2628  return (Node *) newnode;
2629  }
2630  break;
2631  case T_BoolExpr:
2632  {
2633  BoolExpr *expr = (BoolExpr *) node;
2634  BoolExpr *newnode;
2635 
2636  FLATCOPY(newnode, expr, BoolExpr);
2637  MUTATE(newnode->args, expr->args, List *);
2638  return (Node *) newnode;
2639  }
2640  break;
2641  case T_SubLink:
2642  {
2643  SubLink *sublink = (SubLink *) node;
2644  SubLink *newnode;
2645 
2646  FLATCOPY(newnode, sublink, SubLink);
2647  MUTATE(newnode->testexpr, sublink->testexpr, Node *);
2648 
2649  /*
2650  * Also invoke the mutator on the sublink's Query node, so it
2651  * can recurse into the sub-query if it wants to.
2652  */
2653  MUTATE(newnode->subselect, sublink->subselect, Node *);
2654  return (Node *) newnode;
2655  }
2656  break;
2657  case T_SubPlan:
2658  {
2659  SubPlan *subplan = (SubPlan *) node;
2660  SubPlan *newnode;
2661 
2662  FLATCOPY(newnode, subplan, SubPlan);
2663  /* transform testexpr */
2664  MUTATE(newnode->testexpr, subplan->testexpr, Node *);
2665  /* transform args list (params to be passed to subplan) */
2666  MUTATE(newnode->args, subplan->args, List *);
2667  /* but not the sub-Plan itself, which is referenced as-is */
2668  return (Node *) newnode;
2669  }
2670  break;
2671  case T_AlternativeSubPlan:
2672  {
2673  AlternativeSubPlan *asplan = (AlternativeSubPlan *) node;
2674  AlternativeSubPlan *newnode;
2675 
2676  FLATCOPY(newnode, asplan, AlternativeSubPlan);
2677  MUTATE(newnode->subplans, asplan->subplans, List *);
2678  return (Node *) newnode;
2679  }
2680  break;
2681  case T_FieldSelect:
2682  {
2683  FieldSelect *fselect = (FieldSelect *) node;
2684  FieldSelect *newnode;
2685 
2686  FLATCOPY(newnode, fselect, FieldSelect);
2687  MUTATE(newnode->arg, fselect->arg, Expr *);
2688  return (Node *) newnode;
2689  }
2690  break;
2691  case T_FieldStore:
2692  {
2693  FieldStore *fstore = (FieldStore *) node;
2694  FieldStore *newnode;
2695 
2696  FLATCOPY(newnode, fstore, FieldStore);
2697  MUTATE(newnode->arg, fstore->arg, Expr *);
2698  MUTATE(newnode->newvals, fstore->newvals, List *);
2699  newnode->fieldnums = list_copy(fstore->fieldnums);
2700  return (Node *) newnode;
2701  }
2702  break;
2703  case T_RelabelType:
2704  {
2705  RelabelType *relabel = (RelabelType *) node;
2706  RelabelType *newnode;
2707 
2708  FLATCOPY(newnode, relabel, RelabelType);
2709  MUTATE(newnode->arg, relabel->arg, Expr *);
2710  return (Node *) newnode;
2711  }
2712  break;
2713  case T_CoerceViaIO:
2714  {
2715  CoerceViaIO *iocoerce = (CoerceViaIO *) node;
2716  CoerceViaIO *newnode;
2717 
2718  FLATCOPY(newnode, iocoerce, CoerceViaIO);
2719  MUTATE(newnode->arg, iocoerce->arg, Expr *);
2720  return (Node *) newnode;
2721  }
2722  break;
2723  case T_ArrayCoerceExpr:
2724  {
2725  ArrayCoerceExpr *acoerce = (ArrayCoerceExpr *) node;
2726  ArrayCoerceExpr *newnode;
2727 
2728  FLATCOPY(newnode, acoerce, ArrayCoerceExpr);
2729  MUTATE(newnode->arg, acoerce->arg, Expr *);
2730  return (Node *) newnode;
2731  }
2732  break;
2733  case T_ConvertRowtypeExpr:
2734  {
2735  ConvertRowtypeExpr *convexpr = (ConvertRowtypeExpr *) node;
2736  ConvertRowtypeExpr *newnode;
2737 
2738  FLATCOPY(newnode, convexpr, ConvertRowtypeExpr);
2739  MUTATE(newnode->arg, convexpr->arg, Expr *);
2740  return (Node *) newnode;
2741  }
2742  break;
2743  case T_CollateExpr:
2744  {
2745  CollateExpr *collate = (CollateExpr *) node;
2746  CollateExpr *newnode;
2747 
2748  FLATCOPY(newnode, collate, CollateExpr);
2749  MUTATE(newnode->arg, collate->arg, Expr *);
2750  return (Node *) newnode;
2751  }
2752  break;
2753  case T_CaseExpr:
2754  {
2755  CaseExpr *caseexpr = (CaseExpr *) node;
2756  CaseExpr *newnode;
2757 
2758  FLATCOPY(newnode, caseexpr, CaseExpr);
2759  MUTATE(newnode->arg, caseexpr->arg, Expr *);
2760  MUTATE(newnode->args, caseexpr->args, List *);
2761  MUTATE(newnode->defresult, caseexpr->defresult, Expr *);
2762  return (Node *) newnode;
2763  }
2764  break;
2765  case T_CaseWhen:
2766  {
2767  CaseWhen *casewhen = (CaseWhen *) node;
2768  CaseWhen *newnode;
2769 
2770  FLATCOPY(newnode, casewhen, CaseWhen);
2771  MUTATE(newnode->expr, casewhen->expr, Expr *);
2772  MUTATE(newnode->result, casewhen->result, Expr *);
2773  return (Node *) newnode;
2774  }
2775  break;
2776  case T_ArrayExpr:
2777  {
2778  ArrayExpr *arrayexpr = (ArrayExpr *) node;
2779  ArrayExpr *newnode;
2780 
2781  FLATCOPY(newnode, arrayexpr, ArrayExpr);
2782  MUTATE(newnode->elements, arrayexpr->elements, List *);
2783  return (Node *) newnode;
2784  }
2785  break;
2786  case T_RowExpr:
2787  {
2788  RowExpr *rowexpr = (RowExpr *) node;
2789  RowExpr *newnode;
2790 
2791  FLATCOPY(newnode, rowexpr, RowExpr);
2792  MUTATE(newnode->args, rowexpr->args, List *);
2793  /* Assume colnames needn't be duplicated */
2794  return (Node *) newnode;
2795  }
2796  break;
2797  case T_RowCompareExpr:
2798  {
2799  RowCompareExpr *rcexpr = (RowCompareExpr *) node;
2800  RowCompareExpr *newnode;
2801 
2802  FLATCOPY(newnode, rcexpr, RowCompareExpr);
2803  MUTATE(newnode->largs, rcexpr->largs, List *);
2804  MUTATE(newnode->rargs, rcexpr->rargs, List *);
2805  return (Node *) newnode;
2806  }
2807  break;
2808  case T_CoalesceExpr:
2809  {
2810  CoalesceExpr *coalesceexpr = (CoalesceExpr *) node;
2811  CoalesceExpr *newnode;
2812 
2813  FLATCOPY(newnode, coalesceexpr, CoalesceExpr);
2814  MUTATE(newnode->args, coalesceexpr->args, List *);
2815  return (Node *) newnode;
2816  }
2817  break;
2818  case T_MinMaxExpr:
2819  {
2820  MinMaxExpr *minmaxexpr = (MinMaxExpr *) node;
2821  MinMaxExpr *newnode;
2822 
2823  FLATCOPY(newnode, minmaxexpr, MinMaxExpr);
2824  MUTATE(newnode->args, minmaxexpr->args, List *);
2825  return (Node *) newnode;
2826  }
2827  break;
2828  case T_XmlExpr:
2829  {
2830  XmlExpr *xexpr = (XmlExpr *) node;
2831  XmlExpr *newnode;
2832 
2833  FLATCOPY(newnode, xexpr, XmlExpr);
2834  MUTATE(newnode->named_args, xexpr->named_args, List *);
2835  /* assume mutator does not care about arg_names */
2836  MUTATE(newnode->args, xexpr->args, List *);
2837  return (Node *) newnode;
2838  }
2839  break;
2840  case T_NullTest:
2841  {
2842  NullTest *ntest = (NullTest *) node;
2843  NullTest *newnode;
2844 
2845  FLATCOPY(newnode, ntest, NullTest);
2846  MUTATE(newnode->arg, ntest->arg, Expr *);
2847  return (Node *) newnode;
2848  }
2849  break;
2850  case T_BooleanTest:
2851  {
2852  BooleanTest *btest = (BooleanTest *) node;
2853  BooleanTest *newnode;
2854 
2855  FLATCOPY(newnode, btest, BooleanTest);
2856  MUTATE(newnode->arg, btest->arg, Expr *);
2857  return (Node *) newnode;
2858  }
2859  break;
2860  case T_CoerceToDomain:
2861  {
2862  CoerceToDomain *ctest = (CoerceToDomain *) node;
2863  CoerceToDomain *newnode;
2864 
2865  FLATCOPY(newnode, ctest, CoerceToDomain);
2866  MUTATE(newnode->arg, ctest->arg, Expr *);
2867  return (Node *) newnode;
2868  }
2869  break;
2870  case T_TargetEntry:
2871  {
2872  TargetEntry *targetentry = (TargetEntry *) node;
2873  TargetEntry *newnode;
2874 
2875  FLATCOPY(newnode, targetentry, TargetEntry);
2876  MUTATE(newnode->expr, targetentry->expr, Expr *);
2877  return (Node *) newnode;
2878  }
2879  break;
2880  case T_Query:
2881  /* Do nothing with a sub-Query, per discussion above */
2882  return node;
2883  case T_WindowClause:
2884  {
2885  WindowClause *wc = (WindowClause *) node;
2886  WindowClause *newnode;
2887 
2888  FLATCOPY(newnode, wc, WindowClause);
2889  MUTATE(newnode->partitionClause, wc->partitionClause, List *);
2890  MUTATE(newnode->orderClause, wc->orderClause, List *);
2891  MUTATE(newnode->startOffset, wc->startOffset, Node *);
2892  MUTATE(newnode->endOffset, wc->endOffset, Node *);
2893  return (Node *) newnode;
2894  }
2895  break;
2896  case T_CommonTableExpr:
2897  {
2898  CommonTableExpr *cte = (CommonTableExpr *) node;
2899  CommonTableExpr *newnode;
2900 
2901  FLATCOPY(newnode, cte, CommonTableExpr);
2902 
2903  /*
2904  * Also invoke the mutator on the CTE's Query node, so it can
2905  * recurse into the sub-query if it wants to.
2906  */
2907  MUTATE(newnode->ctequery, cte->ctequery, Node *);
2908  return (Node *) newnode;
2909  }
2910  break;
2911  case T_List:
2912  {
2913  /*
2914  * We assume the mutator isn't interested in the list nodes
2915  * per se, so just invoke it on each list element. NOTE: this
2916  * would fail badly on a list with integer elements!
2917  */
2918  List *resultlist;
2919  ListCell *temp;
2920 
2921  resultlist = NIL;
2922  foreach(temp, (List *) node)
2923  {
2924  resultlist = lappend(resultlist,
2925  mutator((Node *) lfirst(temp),
2926  context));
2927  }
2928  return (Node *) resultlist;
2929  }
2930  break;
2931  case T_FromExpr:
2932  {
2933  FromExpr *from = (FromExpr *) node;
2934  FromExpr *newnode;
2935 
2936  FLATCOPY(newnode, from, FromExpr);
2937  MUTATE(newnode->fromlist, from->fromlist, List *);
2938  MUTATE(newnode->quals, from->quals, Node *);
2939  return (Node *) newnode;
2940  }
2941  break;
2942  case T_OnConflictExpr:
2943  {
2944  OnConflictExpr *oc = (OnConflictExpr *) node;
2945  OnConflictExpr *newnode;
2946 
2947  FLATCOPY(newnode, oc, OnConflictExpr);
2948  MUTATE(newnode->arbiterElems, oc->arbiterElems, List *);
2949  MUTATE(newnode->arbiterWhere, oc->arbiterWhere, Node *);
2950  MUTATE(newnode->onConflictSet, oc->onConflictSet, List *);
2951  MUTATE(newnode->onConflictWhere, oc->onConflictWhere, Node *);
2952  MUTATE(newnode->exclRelTlist, oc->exclRelTlist, List *);
2953 
2954  return (Node *) newnode;
2955  }
2956  break;
2957  case T_JoinExpr:
2958  {
2959  JoinExpr *join = (JoinExpr *) node;
2960  JoinExpr *newnode;
2961 
2962  FLATCOPY(newnode, join, JoinExpr);
2963  MUTATE(newnode->larg, join->larg, Node *);
2964  MUTATE(newnode->rarg, join->rarg, Node *);
2965  MUTATE(newnode->quals, join->quals, Node *);
2966  /* We do not mutate alias or using by default */
2967  return (Node *) newnode;
2968  }
2969  break;
2970  case T_SetOperationStmt:
2971  {
2972  SetOperationStmt *setop = (SetOperationStmt *) node;
2973  SetOperationStmt *newnode;
2974 
2975  FLATCOPY(newnode, setop, SetOperationStmt);
2976  MUTATE(newnode->larg, setop->larg, Node *);
2977  MUTATE(newnode->rarg, setop->rarg, Node *);
2978  /* We do not mutate groupClauses by default */
2979  return (Node *) newnode;
2980  }
2981  break;
2982  case T_PlaceHolderVar:
2983  {
2984  PlaceHolderVar *phv = (PlaceHolderVar *) node;
2985  PlaceHolderVar *newnode;
2986 
2987  FLATCOPY(newnode, phv, PlaceHolderVar);
2988  MUTATE(newnode->phexpr, phv->phexpr, Expr *);
2989  /* Assume we need not copy the relids bitmapset */
2990  return (Node *) newnode;
2991  }
2992  break;
2993  case T_InferenceElem:
2994  {
2995  InferenceElem *inferenceelemdexpr = (InferenceElem *) node;
2996  InferenceElem *newnode;
2997 
2998  FLATCOPY(newnode, inferenceelemdexpr, InferenceElem);
2999  MUTATE(newnode->expr, newnode->expr, Node *);
3000  return (Node *) newnode;
3001  }
3002  break;
3003  case T_AppendRelInfo:
3004  {
3005  AppendRelInfo *appinfo = (AppendRelInfo *) node;
3006  AppendRelInfo *newnode;
3007 
3008  FLATCOPY(newnode, appinfo, AppendRelInfo);
3009  MUTATE(newnode->translated_vars, appinfo->translated_vars, List *);
3010  return (Node *) newnode;
3011  }
3012  break;
3013  case T_PlaceHolderInfo:
3014  {
3015  PlaceHolderInfo *phinfo = (PlaceHolderInfo *) node;
3016  PlaceHolderInfo *newnode;
3017 
3018  FLATCOPY(newnode, phinfo, PlaceHolderInfo);
3019  MUTATE(newnode->ph_var, phinfo->ph_var, PlaceHolderVar *);
3020  /* Assume we need not copy the relids bitmapsets */
3021  return (Node *) newnode;
3022  }
3023  break;
3024  case T_RangeTblFunction:
3025  {
3026  RangeTblFunction *rtfunc = (RangeTblFunction *) node;
3027  RangeTblFunction *newnode;
3028 
3029  FLATCOPY(newnode, rtfunc, RangeTblFunction);
3030  MUTATE(newnode->funcexpr, rtfunc->funcexpr, Node *);
3031  /* Assume we need not copy the coldef info lists */
3032  return (Node *) newnode;
3033  }
3034  break;
3035  case T_TableSampleClause:
3036  {
3037  TableSampleClause *tsc = (TableSampleClause *) node;
3038  TableSampleClause *newnode;
3039 
3040  FLATCOPY(newnode, tsc, TableSampleClause);
3041  MUTATE(newnode->args, tsc->args, List *);
3042  MUTATE(newnode->repeatable, tsc->repeatable, Expr *);
3043  return (Node *) newnode;
3044  }
3045  break;
3046  case T_TableFunc:
3047  {
3048  TableFunc *tf = (TableFunc *) node;
3049  TableFunc *newnode;
3050 
3051  FLATCOPY(newnode, tf, TableFunc);
3052  MUTATE(newnode->ns_uris, tf->ns_uris, List *);
3053  MUTATE(newnode->docexpr, tf->docexpr, Node *);
3054  MUTATE(newnode->rowexpr, tf->rowexpr, Node *);
3055  MUTATE(newnode->colexprs, tf->colexprs, List *);
3056  MUTATE(newnode->coldefexprs, tf->coldefexprs, List *);
3057  return (Node *) newnode;
3058  }
3059  break;
3060  default:
3061  elog(ERROR, "unrecognized node type: %d",
3062  (int) nodeTag(node));
3063  break;
3064  }
3065  /* can't get here, but keep compiler happy */
3066  return NULL;
3067 }
List * aggdistinct
Definition: primnodes.h:303
#define NIL
Definition: pg_list.h:69
Expr * refassgnexpr
Definition: primnodes.h:409
List * args
Definition: primnodes.h:1066
List * args
Definition: primnodes.h:985
Node * docexpr
Definition: primnodes.h:84
Expr * arg
Definition: primnodes.h:767
PlaceHolderVar * ph_var
Definition: relation.h:2063
List * args
Definition: primnodes.h:341
List * refs
Definition: primnodes.h:343
List * args
Definition: primnodes.h:359
List * args
Definition: primnodes.h:456
Expr * arg
Definition: primnodes.h:790
List * list_copy(const List *oldlist)
Definition: list.c:1160
Definition: nodes.h:509
List * args
Definition: primnodes.h:301
Expr * arg
Definition: primnodes.h:741
List * fromlist
Definition: primnodes.h:1470
Definition: primnodes.h:163
List * translated_vars
Definition: relation.h:2003
Node * quals
Definition: primnodes.h:1471
List * arbiterElems
Definition: primnodes.h:1489
Node * larg
Definition: primnodes.h:1450
List * aggargtypes
Definition: primnodes.h:299
#define ERROR
Definition: elog.h:43
Expr * phexpr
Definition: relation.h:1850
List * partitionClause
Definition: parsenodes.h:1250
List * args
Definition: primnodes.h:1046
Expr * arg
Definition: primnodes.h:1179
List * coldefexprs
Definition: primnodes.h:91
Node * rowexpr
Definition: primnodes.h:85
List * exclRelTlist
Definition: primnodes.h:1498
List * refupperindexpr
Definition: primnodes.h:403
void check_stack_depth(void)
Definition: postgres.c:3102
List * reflowerindexpr
Definition: primnodes.h:405
List * aggorder
Definition: primnodes.h:302
Expr * arg
Definition: primnodes.h:1202
List * aggdirectargs
Definition: primnodes.h:300
Expr * arg
Definition: primnodes.h:810
List * elements
Definition: primnodes.h:954
Definition: nodes.h:291
List * newvals
Definition: primnodes.h:768
List * cols
Definition: primnodes.h:344
Definition: nodes.h:147
List * lappend(List *list, void *datum)
Definition: list.c:128
Definition: nodes.h:146
Node * startOffset
Definition: parsenodes.h:1253
List * args
Definition: primnodes.h:908
Definition: nodes.h:304
Node * quals
Definition: primnodes.h:1453
#define FLATCOPY(newnode, node, nodetype)
Node * testexpr
Definition: primnodes.h:685
List * colexprs
Definition: primnodes.h:90
List * named_args
Definition: primnodes.h:1143
List * args
Definition: primnodes.h:1145
Node * rarg
Definition: primnodes.h:1451
Expr * arg
Definition: primnodes.h:477
#define NULL
Definition: c.h:229
#define lfirst(lc)
Definition: pg_list.h:106
List * ns_uris
Definition: primnodes.h:82
Expr * aggfilter
Definition: primnodes.h:360
Expr * expr
Definition: primnodes.h:1367
Node * endOffset
Definition: parsenodes.h:1254
Expr * arg
Definition: primnodes.h:875
Expr * aggfilter
Definition: primnodes.h:304
List * args
Definition: primnodes.h:562
#define nodeTag(nodeptr)
Definition: nodes.h:514
Node * arbiterWhere
Definition: primnodes.h:1491
List * orderClause
Definition: parsenodes.h:1251
List * fieldnums
Definition: primnodes.h:769
List * onConflictSet
Definition: primnodes.h:1495
Expr * arg
Definition: primnodes.h:907
#define elog
Definition: elog.h:219
Expr * result
Definition: primnodes.h:920
#define copyObject(obj)
Definition: nodes.h:621
List * args
Definition: primnodes.h:501
Expr * defresult
Definition: primnodes.h:909
Expr * expr
Definition: primnodes.h:919
Node * onConflictWhere
Definition: primnodes.h:1496
Definition: pg_list.h:45
#define MUTATE(newfield, oldfield, fieldtype)
Expr * refexpr
Definition: primnodes.h:407
Definition: nodes.h:148
List * args
Definition: primnodes.h:709
bool expression_tree_walker ( Node node,
bool(*)()  walker,
void *  context 
)

Definition at line 1865 of file nodeFuncs.c.

References Aggref::aggdirectargs, Aggref::aggdistinct, Aggref::aggfilter, WindowFunc::aggfilter, Aggref::aggorder, OnConflictExpr::arbiterElems, OnConflictExpr::arbiterWhere, arg, FieldStore::arg, CaseExpr::arg, generate_unaccent_rules::args, Aggref::args, GroupingFunc::args, WindowFunc::args, FuncExpr::args, OpExpr::args, ScalarArrayOpExpr::args, BoolExpr::args, SubPlan::args, CaseExpr::args, TableSampleClause::args, XmlExpr::args, check_stack_depth(), TableFunc::coldefexprs, TableFunc::colexprs, CommonTableExpr::ctequery, CaseExpr::defresult, TableFunc::docexpr, elog, WindowClause::endOffset, ERROR, OnConflictExpr::exclRelTlist, CaseWhen::expr, expression_tree_walker(), FromExpr::fromlist, JoinExpr::larg, SetOperationStmt::larg, RowCompareExpr::largs, lfirst, lfirst_node, XmlExpr::named_args, FieldStore::newvals, nodeTag, TableFunc::ns_uris, NULL, OnConflictExpr::onConflictSet, OnConflictExpr::onConflictWhere, WindowClause::orderClause, WindowClause::partitionClause, JoinExpr::quals, FromExpr::quals, JoinExpr::rarg, SetOperationStmt::rarg, RowCompareExpr::rargs, ArrayRef::refassgnexpr, ArrayRef::refexpr, ArrayRef::reflowerindexpr, ArrayRef::refupperindexpr, TableSampleClause::repeatable, CaseWhen::result, TableFunc::rowexpr, WindowClause::startOffset, SubLink::subselect, T_Aggref, T_AlternativeSubPlan, T_AppendRelInfo, T_ArrayCoerceExpr, T_ArrayExpr, T_ArrayRef, T_BooleanTest, T_BoolExpr, T_CaseExpr, T_CaseTestExpr, T_CoalesceExpr, T_CoerceToDomain, T_CoerceToDomainValue, T_CoerceViaIO, T_CollateExpr, T_CommonTableExpr, T_Const, T_ConvertRowtypeExpr, T_CurrentOfExpr, T_DistinctExpr, T_FieldSelect, T_FieldStore, T_FromExpr, T_FuncExpr, T_GroupingFunc, T_InferenceElem, T_JoinExpr, T_List, T_MinMaxExpr, T_NamedArgExpr, T_NextValueExpr, T_NullIfExpr, T_NullTest, T_OnConflictExpr, T_OpExpr, T_Param, T_PlaceHolderInfo, T_PlaceHolderVar, T_Query, T_RangeTblFunction, T_RangeTblRef, T_RelabelType, T_RowCompareExpr, T_RowExpr, T_ScalarArrayOpExpr, T_SetOperationStmt, T_SetToDefault, T_SortGroupClause, T_SQLValueFunction, T_SubLink, T_SubPlan, T_TableFunc, T_TableSampleClause, T_TargetEntry, T_Var, T_WindowClause, T_WindowFunc, T_WithCheckOption, T_XmlExpr, SubLink::testexpr, SubPlan::testexpr, and AppendRelInfo::translated_vars.

Referenced by acquireLocksOnSubLinks(), assign_collations_walker(), ChangeVarNodes_walker(), check_agg_arguments(), check_agg_arguments_walker(), check_parameter_resolution_walker(), check_ungrouped_columns_walker(), checkExprHasSubLink_walker(), contain_agg_clause_walker(), contain_aggs_of_level_walker(), contain_context_dependent_node_walker(), contain_leaked_vars_walker(), contain_mutable_functions_walker(), contain_nonstrict_functions_walker(), contain_subplans_walker(), contain_var_clause_walker(), contain_vars_of_level_walker(), contain_volatile_functions_not_nextval_walker(), contain_volatile_functions_walker(), contain_windowfuncs_walker(), contains_multiexpr_param(), contains_target_param(), cost_qual_eval_walker(), expression_returns_set_walker(), expression_tree_walker(), extract_query_dependencies_walker(), finalize_agg_primnode(), finalize_grouping_exprs_walker(), finalize_primnode(), find_expr_references_walker(), find_minmax_aggs_walker(), find_unaggregated_cols_walker(), find_window_functions_walker(), fireRIRonSubLink(), fireRIRrules(), fix_opfuncids_walker(), fix_scan_expr_walker(), flatten_rtes_walker(), get_agg_clause_costs_walker(), get_last_attnums_walker(), IncrementVarSublevelsUp_walker(), isQueryUsingTempRelation_walker(), locate_agg_of_level_walker(), locate_var_of_level_walker(), locate_windowfunc_walker(), max_parallel_hazard_walker(), OffsetVarNodes_walker(), pull_var_clause_walker(), pull_varattnos_walker(), pull_varnos_walker(), pull_vars_walker(), query_contains_extern_params_walker(), rangeTableEntry_used_walker(), ScanQueryWalker(), setRuleCheckAsUser_walker(), split_pathtarget_walker(), and substitute_multiple_relids_walker().

1868 {
1869  ListCell *temp;
1870 
1871  /*
1872  * The walker has already visited the current node, and so we need only
1873  * recurse into any sub-nodes it has.
1874  *
1875  * We assume that the walker is not interested in List nodes per se, so
1876  * when we expect a List we just recurse directly to self without
1877  * bothering to call the walker.
1878  */
1879  if (node == NULL)
1880  return false;
1881 
1882  /* Guard against stack overflow due to overly complex expressions */
1884 
1885  switch (nodeTag(node))
1886  {
1887  case T_Var:
1888  case T_Const:
1889  case T_Param:
1890  case T_CoerceToDomainValue:
1891  case T_CaseTestExpr:
1892  case T_SetToDefault:
1893  case T_CurrentOfExpr:
1894  case T_NextValueExpr:
1895  case T_SQLValueFunction:
1896  case T_RangeTblRef:
1897  case T_SortGroupClause:
1898  /* primitive node types with no expression subnodes */
1899  break;
1900  case T_WithCheckOption:
1901  return walker(((WithCheckOption *) node)->qual, context);
1902  case T_Aggref:
1903  {
1904  Aggref *expr = (Aggref *) node;
1905 
1906  /* recurse directly on List */
1908  walker, context))
1909  return true;
1910  if (expression_tree_walker((Node *) expr->args,
1911  walker, context))
1912  return true;
1913  if (expression_tree_walker((Node *) expr->aggorder,
1914  walker, context))
1915  return true;
1916  if (expression_tree_walker((Node *) expr->aggdistinct,
1917  walker, context))
1918  return true;
1919  if (walker((Node *) expr->aggfilter, context))
1920  return true;
1921  }
1922  break;
1923  case T_GroupingFunc:
1924  {
1925  GroupingFunc *grouping = (GroupingFunc *) node;
1926 
1927  if (expression_tree_walker((Node *) grouping->args,
1928  walker, context))
1929  return true;
1930  }
1931  break;
1932  case T_WindowFunc:
1933  {
1934  WindowFunc *expr = (WindowFunc *) node;
1935 
1936  /* recurse directly on List */
1937  if (expression_tree_walker((Node *) expr->args,
1938  walker, context))
1939  return true;
1940  if (walker((Node *) expr->aggfilter, context))
1941  return true;
1942  }
1943  break;
1944  case T_ArrayRef:
1945  {
1946  ArrayRef *aref = (ArrayRef *) node;
1947 
1948  /* recurse directly for upper/lower array index lists */
1950  walker, context))
1951  return true;
1953  walker, context))
1954  return true;
1955  /* walker must see the refexpr and refassgnexpr, however */
1956  if (walker(aref->refexpr, context))
1957  return true;
1958  if (walker(aref->refassgnexpr, context))
1959  return true;
1960  }
1961  break;
1962  case T_FuncExpr:
1963  {
1964  FuncExpr *expr = (FuncExpr *) node;
1965 
1966  if (expression_tree_walker((Node *) expr->args,
1967  walker, context))
1968  return true;
1969  }
1970  break;
1971  case T_NamedArgExpr:
1972  return walker(((NamedArgExpr *) node)->arg, context);
1973  case T_OpExpr:
1974  case T_DistinctExpr: /* struct-equivalent to OpExpr */
1975  case T_NullIfExpr: /* struct-equivalent to OpExpr */
1976  {
1977  OpExpr *expr = (OpExpr *) node;
1978 
1979  if (expression_tree_walker((Node *) expr->args,
1980  walker, context))
1981  return true;
1982  }
1983  break;
1984  case T_ScalarArrayOpExpr:
1985  {
1986  ScalarArrayOpExpr *expr = (ScalarArrayOpExpr *) node;
1987 
1988  if (expression_tree_walker((Node *) expr->args,
1989  walker, context))
1990  return true;
1991  }
1992  break;
1993  case T_BoolExpr:
1994  {
1995  BoolExpr *expr = (BoolExpr *) node;
1996 
1997  if (expression_tree_walker((Node *) expr->args,
1998  walker, context))
1999  return true;
2000  }
2001  break;
2002  case T_SubLink:
2003  {
2004  SubLink *sublink = (SubLink *) node;
2005 
2006  if (walker(sublink->testexpr, context))
2007  return true;
2008 
2009  /*
2010  * Also invoke the walker on the sublink's Query node, so it
2011  * can recurse into the sub-query if it wants to.
2012  */
2013  return walker(sublink->subselect, context);
2014  }
2015  break;
2016  case T_SubPlan:
2017  {
2018  SubPlan *subplan = (SubPlan *) node;
2019 
2020  /* recurse into the testexpr, but not into the Plan */
2021  if (walker(subplan->testexpr, context))
2022  return true;
2023  /* also examine args list */
2024  if (expression_tree_walker((Node *) subplan->args,
2025  walker, context))
2026  return true;
2027  }
2028  break;
2029  case T_AlternativeSubPlan:
2030  return walker(((AlternativeSubPlan *) node)->subplans, context);
2031  case T_FieldSelect:
2032  return walker(((FieldSelect *) node)->arg, context);
2033  case T_FieldStore:
2034  {
2035  FieldStore *fstore = (FieldStore *) node;
2036 
2037  if (walker(fstore->arg, context))
2038  return true;
2039  if (walker(fstore->newvals, context))
2040  return true;
2041  }
2042  break;
2043  case T_RelabelType:
2044  return walker(((RelabelType *) node)->arg, context);
2045  case T_CoerceViaIO:
2046  return walker(((CoerceViaIO *) node)->arg, context);
2047  case T_ArrayCoerceExpr:
2048  return walker(((ArrayCoerceExpr *) node)->arg, context);
2049  case T_ConvertRowtypeExpr:
2050  return walker(((ConvertRowtypeExpr *) node)->arg, context);
2051  case T_CollateExpr:
2052  return walker(((CollateExpr *) node)->arg, context);
2053  case T_CaseExpr:
2054  {
2055  CaseExpr *caseexpr = (CaseExpr *) node;
2056 
2057  if (walker(caseexpr->arg, context))
2058  return true;
2059  /* we assume walker doesn't care about CaseWhens, either */
2060  foreach(temp, caseexpr->args)
2061  {
2062  CaseWhen *when = lfirst_node(CaseWhen, temp);
2063 
2064  if (walker(when->expr, context))
2065  return true;
2066  if (walker(when->result, context))
2067  return true;
2068  }
2069  if (walker(caseexpr->defresult, context))
2070  return true;
2071  }
2072  break;
2073  case T_ArrayExpr:
2074  return walker(((ArrayExpr *) node)->elements, context);
2075  case T_RowExpr:
2076  /* Assume colnames isn't interesting */
2077  return walker(((RowExpr *) node)->args, context);
2078  case T_RowCompareExpr:
2079  {
2080  RowCompareExpr *rcexpr = (RowCompareExpr *) node;
2081 
2082  if (walker(rcexpr->largs, context))
2083  return true;
2084  if (walker(rcexpr->rargs, context))
2085  return true;
2086  }
2087  break;
2088  case T_CoalesceExpr:
2089  return walker(((CoalesceExpr *) node)->args, context);
2090  case T_MinMaxExpr:
2091  return walker(((MinMaxExpr *) node)->args, context);
2092  case T_XmlExpr:
2093  {
2094  XmlExpr *xexpr = (XmlExpr *) node;
2095 
2096  if (walker(xexpr->named_args, context))
2097  return true;
2098  /* we assume walker doesn't care about arg_names */
2099  if (walker(xexpr->args, context))
2100  return true;
2101  }
2102  break;
2103  case T_NullTest:
2104  return walker(((NullTest *) node)->arg, context);
2105  case T_BooleanTest:
2106  return walker(((BooleanTest *) node)->arg, context);
2107  case T_CoerceToDomain:
2108  return walker(((CoerceToDomain *) node)->arg, context);
2109  case T_TargetEntry:
2110  return walker(((TargetEntry *) node)->expr, context);
2111  case T_Query:
2112  /* Do nothing with a sub-Query, per discussion above */
2113  break;
2114  case T_WindowClause:
2115  {
2116  WindowClause *wc = (WindowClause *) node;
2117 
2118  if (walker(wc->partitionClause, context))
2119  return true;
2120  if (walker(wc->orderClause, context))
2121  return true;
2122  if (walker(wc->startOffset, context))
2123  return true;
2124  if (walker(wc->endOffset, context))
2125  return true;
2126  }
2127  break;
2128  case T_CommonTableExpr:
2129  {
2130  CommonTableExpr *cte = (CommonTableExpr *) node;
2131 
2132  /*
2133  * Invoke the walker on the CTE's Query node, so it can
2134  * recurse into the sub-query if it wants to.
2135  */
2136  return walker(cte->ctequery, context);
2137  }
2138  break;
2139  case T_List:
2140  foreach(temp, (List *) node)
2141  {
2142  if (walker((Node *) lfirst(temp), context))
2143  return true;
2144  }
2145  break;
2146  case T_FromExpr:
2147  {
2148  FromExpr *from = (FromExpr *) node;
2149 
2150  if (walker(from->fromlist, context))
2151  return true;
2152  if (walker(from->quals, context))
2153  return true;
2154  }
2155  break;
2156  case T_OnConflictExpr:
2157  {
2158  OnConflictExpr *onconflict = (OnConflictExpr *) node;
2159 
2160  if (walker((Node *) onconflict->arbiterElems, context))
2161  return true;
2162  if (walker(onconflict->arbiterWhere, context))
2163  return true;
2164  if (walker(onconflict->onConflictSet, context))
2165  return true;
2166  if (walker(onconflict->onConflictWhere, context))
2167  return true;
2168  if (walker(onconflict->exclRelTlist, context))
2169  return true;
2170  }
2171  break;
2172  case T_JoinExpr:
2173  {
2174  JoinExpr *join = (JoinExpr *) node;
2175 
2176  if (walker(join->larg, context))
2177  return true;
2178  if (walker(join->rarg, context))
2179  return true;
2180  if (walker(join->quals, context))
2181  return true;
2182 
2183  /*
2184  * alias clause, using list are deemed uninteresting.
2185  */
2186  }
2187  break;
2188  case T_SetOperationStmt:
2189  {
2190  SetOperationStmt *setop = (SetOperationStmt *) node;
2191 
2192  if (walker(setop->larg, context))
2193  return true;
2194  if (walker(setop->rarg, context))
2195  return true;
2196 
2197  /* groupClauses are deemed uninteresting */
2198  }
2199  break;
2200  case T_PlaceHolderVar:
2201  return walker(((PlaceHolderVar *) node)->phexpr, context);
2202  case T_InferenceElem:
2203  return walker(((InferenceElem *) node)->expr, context);
2204  case T_AppendRelInfo:
2205  {
2206  AppendRelInfo *appinfo = (AppendRelInfo *) node;
2207 
2208  if (expression_tree_walker((Node *) appinfo->translated_vars,
2209  walker, context))
2210  return true;
2211  }
2212  break;
2213  case T_PlaceHolderInfo:
2214  return walker(((PlaceHolderInfo *) node)->ph_var, context);
2215  case T_RangeTblFunction:
2216  return walker(((RangeTblFunction *) node)->funcexpr, context);
2217  case T_TableSampleClause:
2218  {
2219  TableSampleClause *tsc = (TableSampleClause *) node;
2220 
2221  if (expression_tree_walker((Node *) tsc->args,
2222  walker, context))
2223  return true;
2224  if (walker((Node *) tsc->repeatable, context))
2225  return true;
2226  }
2227  break;
2228  case T_TableFunc:
2229  {
2230  TableFunc *tf = (TableFunc *) node;
2231 
2232  if (walker(tf->ns_uris, context))
2233  return true;
2234  if (walker(tf->docexpr, context))
2235  return true;
2236  if (walker(tf->rowexpr, context))
2237  return true;
2238  if (walker(tf->colexprs, context))
2239  return true;
2240  if (walker(tf->coldefexprs, context))
2241  return true;
2242  }
2243  break;
2244  default:
2245  elog(ERROR, "unrecognized node type: %d",
2246  (int) nodeTag(node));
2247  break;
2248  }
2249  return false;
2250 }
List * aggdistinct
Definition: primnodes.h:303
Expr * refassgnexpr
Definition: primnodes.h:409
Node * docexpr
Definition: primnodes.h:84
Expr * arg
Definition: primnodes.h:767
List * args
Definition: primnodes.h:341
List * args
Definition: primnodes.h:359
List * args
Definition: primnodes.h:456
Definition: nodes.h:509
List * args
Definition: primnodes.h:301
List * fromlist
Definition: primnodes.h:1470
List * translated_vars
Definition: relation.h:2003
Node * quals
Definition: primnodes.h:1471
List * arbiterElems
Definition: primnodes.h:1489
Node * larg
Definition: primnodes.h:1450
#define ERROR
Definition: elog.h:43
List * partitionClause
Definition: parsenodes.h:1250
List * coldefexprs
Definition: primnodes.h:91
#define lfirst_node(type, lc)
Definition: pg_list.h:109
Node * rowexpr
Definition: primnodes.h:85
List * exclRelTlist
Definition: primnodes.h:1498
List * refupperindexpr
Definition: primnodes.h:403
void check_stack_depth(void)
Definition: postgres.c:3102
List * reflowerindexpr
Definition: primnodes.h:405
List * aggorder
Definition: primnodes.h:302
List * aggdirectargs
Definition: primnodes.h:300
Definition: type.h:83
Definition: nodes.h:291
List * newvals
Definition: primnodes.h:768
Definition: nodes.h:147
Definition: nodes.h:146
Node * startOffset
Definition: parsenodes.h:1253
List * args
Definition: primnodes.h:908
Definition: nodes.h:304
Node * quals
Definition: primnodes.h:1453
Node * testexpr
Definition: primnodes.h:685
List * colexprs
Definition: primnodes.h:90
List * named_args
Definition: primnodes.h:1143
List * args
Definition: primnodes.h:1145
Node * rarg
Definition: primnodes.h:1451
#define NULL
Definition: c.h:229
#define lfirst(lc)
Definition: pg_list.h:106
List * ns_uris
Definition: primnodes.h:82
Expr * aggfilter
Definition: primnodes.h:360
Node * endOffset
Definition: parsenodes.h:1254
bool expression_tree_walker(Node *node, bool(*walker)(), void *context)
Definition: nodeFuncs.c:1865
Expr * aggfilter
Definition: primnodes.h:304
List * args
Definition: primnodes.h:562
#define nodeTag(nodeptr)
Definition: nodes.h:514
Node * arbiterWhere
Definition: primnodes.h:1491
List * orderClause
Definition: parsenodes.h:1251
List * onConflictSet
Definition: primnodes.h:1495
void * arg
Expr * arg
Definition: primnodes.h:907
#define elog
Definition: elog.h:219
Expr * result
Definition: primnodes.h:920
List * args
Definition: primnodes.h:501
Expr * defresult
Definition: primnodes.h:909
Expr * expr
Definition: primnodes.h:919
Node * onConflictWhere
Definition: primnodes.h:1496
Definition: pg_list.h:45
Expr * refexpr
Definition: primnodes.h:407
Definition: nodes.h:148
List * args
Definition: primnodes.h:709
Oid exprInputCollation ( const Node expr)

Definition at line 949 of file nodeFuncs.c.

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

Referenced by resolve_polymorphic_tupdesc().

950 {
951  Oid coll;
952 
953  if (!expr)
954  return InvalidOid;
955 
956  switch (nodeTag(expr))
957  {
958  case T_Aggref:
959  coll = ((const Aggref *) expr)->inputcollid;
960  break;
961  case T_WindowFunc:
962  coll = ((const WindowFunc *) expr)->inputcollid;
963  break;
964  case T_FuncExpr:
965  coll = ((const FuncExpr *) expr)->inputcollid;
966  break;
967  case T_OpExpr:
968  coll = ((const OpExpr *) expr)->inputcollid;
969  break;
970  case T_DistinctExpr:
971  coll = ((const DistinctExpr *) expr)->inputcollid;
972  break;
973  case T_NullIfExpr:
974  coll = ((const NullIfExpr *) expr)->inputcollid;
975  break;
976  case T_ScalarArrayOpExpr:
977  coll = ((const ScalarArrayOpExpr *) expr)->inputcollid;
978  break;
979  case T_MinMaxExpr:
980  coll = ((const MinMaxExpr *) expr)->inputcollid;
981  break;
982  default:
983  coll = InvalidOid;
984  break;
985  }
986  return coll;
987 }
unsigned int Oid
Definition: postgres_ext.h:31
#define InvalidOid
Definition: postgres_ext.h:36
#define nodeTag(nodeptr)
Definition: nodes.h:514
bool exprIsLengthCoercion ( const Node expr,
int32 coercedTypmod 
)

Definition at line 513 of file nodeFuncs.c.

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

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

514 {
515  if (coercedTypmod != NULL)
516  *coercedTypmod = -1; /* default result on failure */
517 
518  /*
519  * Scalar-type length coercions are FuncExprs, array-type length coercions
520  * are ArrayCoerceExprs
521  */
522  if (expr && IsA(expr, FuncExpr))
523  {
524  const FuncExpr *func = (const FuncExpr *) expr;
525  int nargs;
526  Const *second_arg;
527 
528  /*
529  * If it didn't come from a coercion context, reject.
530  */
531  if (func->funcformat != COERCE_EXPLICIT_CAST &&
533  return false;
534 
535  /*
536  * If it's not a two-argument or three-argument function with the
537  * second argument being an int4 constant, it can't have been created
538  * from a length coercion (it must be a type coercion, instead).
539  */
540  nargs = list_length(func->args);
541  if (nargs < 2 || nargs > 3)
542  return false;
543 
544  second_arg = (Const *) lsecond(func->args);
545  if (!IsA(second_arg, Const) ||
546  second_arg->consttype != INT4OID ||
547  second_arg->constisnull)
548  return false;
549 
550  /*
551  * OK, it is indeed a length-coercion function.
552  */
553  if (coercedTypmod != NULL)
554  *coercedTypmod = DatumGetInt32(second_arg->constvalue);
555 
556  return true;
557  }
558 
559  if (expr && IsA(expr, ArrayCoerceExpr))
560  {
561  const ArrayCoerceExpr *acoerce = (const ArrayCoerceExpr *) expr;
562 
563  /* It's not a length coercion unless there's a nondefault typmod */
564  if (acoerce->resulttypmod < 0)
565  return false;
566 
567  /*
568  * OK, it is indeed a length-coercion expression.
569  */
570  if (coercedTypmod != NULL)
571  *coercedTypmod = acoerce->resulttypmod;
572 
573  return true;
574  }
575 
576  return false;
577 }
Datum constvalue
Definition: primnodes.h:196
#define IsA(nodeptr, _type_)
Definition: nodes.h:560
List * args
Definition: primnodes.h:456
#define DatumGetInt32(X)
Definition: postgres.h:478
#define INT4OID
Definition: pg_type.h:316
#define lsecond(l)
Definition: pg_list.h:116
Oid consttype
Definition: primnodes.h:192
CoercionForm funcformat
Definition: primnodes.h:453
#define NULL
Definition: c.h:229
static int list_length(const List *l)
Definition: pg_list.h:89
int32 resulttypmod
Definition: primnodes.h:836
bool constisnull
Definition: primnodes.h:197
int exprLocation ( const Node expr)

Definition at line 1214 of file nodeFuncs.c.

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

Referenced by addRangeTableEntryForFunction(), addTargetToSortList(), analyzeCTE(), assign_collations_walker(), checkWellFormedRecursion(), coerce_to_boolean(), coerce_to_common_type(), coerce_to_specific_type_typmod(), ExecInitFunc(), exprLocation(), finalize_grouping_exprs_walker(), get_matching_location(), init_sexpr(), parseCheckAggregates(), ParseFuncOrColumn(), parser_coercion_errposition(), resolve_unique_index_expr(), select_common_type(), transformAExprOf(), transformAggregateCall(), transformArrayExpr(), transformArraySubscripts(), transformAssignedExpr(), transformDistinctClause(), transformDistinctOnClause(), transformFromClauseItem(), transformGroupClause(), transformGroupClauseExpr(), transformGroupingSet(), transformIndirection(), transformInsertRow(), transformInsertStmt(), transformMultiAssignRef(), transformOnConflictArbiter(), transformPartitionBound(), transformRangeFunction(), transformReturningList(), transformSelectStmt(), transformSetOperationStmt(), transformSetOperationTree(), and transformValuesClause().

1215 {
1216  int loc;
1217 
1218  if (expr == NULL)
1219  return -1;
1220  switch (nodeTag(expr))
1221  {
1222  case T_RangeVar:
1223  loc = ((const RangeVar *) expr)->location;
1224  break;
1225  case T_TableFunc:
1226  loc = ((const TableFunc *) expr)->location;
1227  break;
1228  case T_Var:
1229  loc = ((const Var *) expr)->location;
1230  break;
1231  case T_Const:
1232  loc = ((const Const *) expr)->location;
1233  break;
1234  case T_Param:
1235  loc = ((const Param *) expr)->location;
1236  break;
1237  case T_Aggref:
1238  /* function name should always be the first thing */
1239  loc = ((const Aggref *) expr)->location;
1240  break;
1241  case T_GroupingFunc:
1242  loc = ((const GroupingFunc *) expr)->location;
1243  break;
1244  case T_WindowFunc:
1245  /* function name should always be the first thing */
1246  loc = ((const WindowFunc *) expr)->location;
1247  break;
1248  case T_ArrayRef:
1249  /* just use array argument's location */
1250  loc = exprLocation((Node *) ((const ArrayRef *) expr)->refexpr);
1251  break;
1252  case T_FuncExpr:
1253  {
1254  const FuncExpr *fexpr = (const FuncExpr *) expr;
1255 
1256  /* consider both function name and leftmost arg */
1257  loc = leftmostLoc(fexpr->location,
1258  exprLocation((Node *) fexpr->args));
1259  }
1260  break;
1261  case T_NamedArgExpr:
1262  {
1263  const NamedArgExpr *na = (const NamedArgExpr *) expr;
1264 
1265  /* consider both argument name and value */
1266  loc = leftmostLoc(na->location,
1267  exprLocation((Node *) na->arg));
1268  }
1269  break;
1270  case T_OpExpr:
1271  case T_DistinctExpr: /* struct-equivalent to OpExpr */
1272  case T_NullIfExpr: /* struct-equivalent to OpExpr */
1273  {
1274  const OpExpr *opexpr = (const OpExpr *) expr;
1275 
1276  /* consider both operator name and leftmost arg */
1277  loc = leftmostLoc(opexpr->location,
1278  exprLocation((Node *) opexpr->args));
1279  }
1280  break;
1281  case T_ScalarArrayOpExpr:
1282  {
1283  const ScalarArrayOpExpr *saopexpr = (const ScalarArrayOpExpr *) expr;
1284 
1285  /* consider both operator name and leftmost arg */
1286  loc = leftmostLoc(saopexpr->location,
1287  exprLocation((Node *) saopexpr->args));
1288  }
1289  break;
1290  case T_BoolExpr:
1291  {
1292  const BoolExpr *bexpr = (const BoolExpr *) expr;
1293 
1294  /*
1295  * Same as above, to handle either NOT or AND/OR. We can't
1296  * special-case NOT because of the way that it's used for
1297  * things like IS NOT BETWEEN.
1298  */
1299  loc = leftmostLoc(bexpr->location,
1300  exprLocation((Node *) bexpr->args));
1301  }
1302  break;
1303  case T_SubLink:
1304  {
1305  const SubLink *sublink = (const SubLink *) expr;
1306 
1307  /* check the testexpr, if any, and the operator/keyword */
1308  loc = leftmostLoc(exprLocation(sublink->testexpr),
1309  sublink->location);
1310  }
1311  break;
1312  case T_FieldSelect:
1313  /* just use argument's location */
1314  loc = exprLocation((Node *) ((const FieldSelect *) expr)->arg);
1315  break;
1316  case T_FieldStore:
1317  /* just use argument's location */
1318  loc = exprLocation((Node *) ((const FieldStore *) expr)->arg);
1319  break;
1320  case T_RelabelType:
1321  {
1322  const RelabelType *rexpr = (const RelabelType *) expr;
1323 
1324  /* Much as above */
1325  loc = leftmostLoc(rexpr->location,
1326  exprLocation((Node *) rexpr->arg));
1327  }
1328  break;
1329  case T_CoerceViaIO:
1330  {
1331  const CoerceViaIO *cexpr = (const CoerceViaIO *) expr;
1332 
1333  /* Much as above */
1334  loc = leftmostLoc(cexpr->location,
1335  exprLocation((Node *) cexpr->arg));
1336  }
1337  break;
1338  case T_ArrayCoerceExpr:
1339  {
1340  const ArrayCoerceExpr *cexpr = (const ArrayCoerceExpr *) expr;
1341 
1342  /* Much as above */
1343  loc = leftmostLoc(cexpr->location,
1344  exprLocation((Node *) cexpr->arg));
1345  }
1346  break;
1347  case T_ConvertRowtypeExpr:
1348  {
1349  const ConvertRowtypeExpr *cexpr = (const ConvertRowtypeExpr *) expr;
1350 
1351  /* Much as above */
1352  loc = leftmostLoc(cexpr->location,
1353  exprLocation((Node *) cexpr->arg));
1354  }
1355  break;
1356  case T_CollateExpr:
1357  /* just use argument's location */
1358  loc = exprLocation((Node *) ((const CollateExpr *) expr)->arg);
1359  break;
1360  case T_CaseExpr:
1361  /* CASE keyword should always be the first thing */
1362  loc = ((const CaseExpr *) expr)->location;
1363  break;
1364  case T_CaseWhen:
1365  /* WHEN keyword should always be the first thing */
1366  loc = ((const CaseWhen *) expr)->location;
1367  break;
1368  case T_ArrayExpr:
1369  /* the location points at ARRAY or [, which must be leftmost */
1370  loc = ((const ArrayExpr *) expr)->location;
1371  break;
1372  case T_RowExpr:
1373  /* the location points at ROW or (, which must be leftmost */
1374  loc = ((const RowExpr *) expr)->location;
1375  break;
1376  case T_RowCompareExpr:
1377  /* just use leftmost argument's location */
1378  loc = exprLocation((Node *) ((const RowCompareExpr *) expr)->largs);
1379  break;
1380  case T_CoalesceExpr:
1381  /* COALESCE keyword should always be the first thing */
1382  loc = ((const CoalesceExpr *) expr)->location;
1383  break;
1384  case T_MinMaxExpr:
1385  /* GREATEST/LEAST keyword should always be the first thing */
1386  loc = ((const MinMaxExpr *) expr)->location;
1387  break;
1388  case T_SQLValueFunction:
1389  /* function keyword should always be the first thing */
1390  loc = ((const SQLValueFunction *) expr)->location;
1391  break;
1392  case T_XmlExpr:
1393  {
1394  const XmlExpr *xexpr = (const XmlExpr *) expr;
1395 
1396  /* consider both function name and leftmost arg */
1397  loc = leftmostLoc(xexpr->location,
1398  exprLocation((Node *) xexpr->args));
1399  }
1400  break;
1401  case T_NullTest:
1402  {
1403  const NullTest *nexpr = (const NullTest *) expr;
1404 
1405  /* Much as above */
1406  loc = leftmostLoc(nexpr->location,
1407  exprLocation((Node *) nexpr->arg));
1408  }
1409  break;
1410  case T_BooleanTest:
1411  {
1412  const BooleanTest *bexpr = (const BooleanTest *) expr;
1413 
1414  /* Much as above */
1415  loc = leftmostLoc(bexpr->location,
1416  exprLocation((Node *) bexpr->arg));
1417  }
1418  break;
1419  case T_CoerceToDomain:
1420  {
1421  const CoerceToDomain *cexpr = (const CoerceToDomain *) expr;
1422 
1423  /* Much as above */
1424  loc = leftmostLoc(cexpr->location,
1425  exprLocation((Node *) cexpr->arg));
1426  }
1427  break;
1428  case T_CoerceToDomainValue:
1429  loc = ((const CoerceToDomainValue *) expr)->location;
1430  break;
1431  case T_SetToDefault:
1432  loc = ((const SetToDefault *) expr)->location;
1433  break;
1434  case T_TargetEntry:
1435  /* just use argument's location */
1436  loc = exprLocation((Node *) ((const TargetEntry *) expr)->expr);
1437  break;
1438  case T_IntoClause:
1439  /* use the contained RangeVar's location --- close enough */
1440  loc = exprLocation((Node *) ((const IntoClause *) expr)->rel);
1441  break;
1442  case T_List:
1443  {
1444  /* report location of first list member that has a location */
1445  ListCell *lc;
1446 
1447  loc = -1; /* just to suppress compiler warning */
1448  foreach(lc, (const List *) expr)
1449  {
1450  loc = exprLocation((Node *) lfirst(lc));
1451  if (loc >= 0)
1452  break;
1453  }
1454  }
1455  break;
1456  case T_A_Expr:
1457  {
1458  const A_Expr *aexpr = (const A_Expr *) expr;
1459 
1460  /* use leftmost of operator or left operand (if any) */
1461  /* we assume right operand can't be to left of operator */
1462  loc = leftmostLoc(aexpr->location,
1463  exprLocation(aexpr->lexpr));
1464  }
1465  break;
1466  case T_ColumnRef:
1467  loc = ((const ColumnRef *) expr)->location;
1468  break;
1469  case T_ParamRef:
1470  loc = ((const ParamRef *) expr)->location;
1471  break;
1472  case T_A_Const:
1473  loc = ((const A_Const *) expr)->location;
1474  break;
1475  case T_FuncCall:
1476  {
1477  const FuncCall *fc = (const FuncCall *) expr;
1478 
1479  /* consider both function name and leftmost arg */
1480  /* (we assume any ORDER BY nodes must be to right of name) */
1481  loc = leftmostLoc(fc->location,
1482  exprLocation((Node *) fc->args));
1483  }
1484  break;
1485  case T_A_ArrayExpr:
1486  /* the location points at ARRAY or [, which must be leftmost */
1487  loc = ((const A_ArrayExpr *) expr)->location;
1488  break;
1489  case T_ResTarget:
1490  /* we need not examine the contained expression (if any) */
1491  loc = ((const ResTarget *) expr)->location;
1492  break;
1493  case T_MultiAssignRef:
1494  loc = exprLocation(((const MultiAssignRef *) expr)->source);
1495  break;
1496  case T_TypeCast:
1497  {
1498  const TypeCast *tc = (const TypeCast *) expr;
1499 
1500  /*
1501  * This could represent CAST(), ::, or TypeName 'literal', so
1502  * any of the components might be leftmost.
1503  */
1504  loc = exprLocation(tc->arg);
1505  loc = leftmostLoc(loc, tc->typeName->location);
1506  loc = leftmostLoc(loc, tc->location);
1507  }
1508  break;
1509  case T_CollateClause:
1510  /* just use argument's location */
1511  loc = exprLocation(((const CollateClause *) expr)->arg);
1512  break;
1513  case T_SortBy:
1514  /* just use argument's location (ignore operator, if any) */
1515  loc = exprLocation(((const SortBy *) expr)->node);
1516  break;
1517  case T_WindowDef:
1518  loc = ((const WindowDef *) expr)->location;
1519  break;
1520  case T_RangeTableSample:
1521  loc = ((const RangeTableSample *) expr)->location;
1522  break;
1523  case T_TypeName:
1524  loc = ((const TypeName *) expr)->location;
1525  break;
1526  case T_ColumnDef:
1527  loc = ((const ColumnDef *) expr)->location;
1528  break;
1529  case T_Constraint:
1530  loc = ((const Constraint *) expr)->location;
1531  break;
1532  case T_FunctionParameter:
1533  /* just use typename's location */
1534  loc = exprLocation((Node *) ((const FunctionParameter *) expr)->argType);
1535  break;
1536  case T_XmlSerialize:
1537  /* XMLSERIALIZE keyword should always be the first thing */
1538  loc = ((const XmlSerialize *) expr)->location;
1539  break;
1540  case T_GroupingSet:
1541  loc = ((const GroupingSet *) expr)->location;
1542  break;
1543  case T_WithClause:
1544  loc = ((const WithClause *) expr)->location;
1545  break;
1546  case T_InferClause:
1547  loc = ((const InferClause *) expr)->location;
1548  break;
1549  case T_OnConflictClause:
1550  loc = ((const OnConflictClause *) expr)->location;
1551  break;
1552  case T_CommonTableExpr:
1553  loc = ((const CommonTableExpr *) expr)->location;
1554  break;
1555  case T_PlaceHolderVar:
1556  /* just use argument's location */
1557  loc = exprLocation((Node *) ((const PlaceHolderVar *) expr)->phexpr);
1558  break;
1559  case T_InferenceElem:
1560  /* just use nested expr's location */
1561  loc = exprLocation((Node *) ((const InferenceElem *) expr)->expr);
1562  break;
1563  case T_PartitionBoundSpec:
1564  loc = ((const PartitionBoundSpec *) expr)->location;
1565  break;
1566  case T_PartitionRangeDatum:
1567  loc = ((const PartitionRangeDatum *) expr)->location;
1568  break;
1569  default:
1570  /* for any other node type it's just unknown... */
1571  loc = -1;
1572  break;
1573  }
1574  return loc;
1575 }
int exprLocation(const Node *expr)
Definition: nodeFuncs.c:1214
List * args
Definition: primnodes.h:456
static int leftmostLoc(int loc1, int loc2)
Definition: nodeFuncs.c:1583
int location
Definition: primnodes.h:1149
Expr * arg
Definition: primnodes.h:790
Definition: nodes.h:509
static int fc(const char *x)
Definition: preproc-init.c:99
int location
Definition: parsenodes.h:359
Definition: primnodes.h:163
int location
Definition: primnodes.h:563
int location
Definition: parsenodes.h:300
Expr * arg
Definition: primnodes.h:1179
int location
Definition: primnodes.h:502
Expr * arg
Definition: primnodes.h:1202
int location
Definition: parsenodes.h:279
Expr * arg
Definition: primnodes.h:810
Node * lexpr
Definition: parsenodes.h:277
Definition: nodes.h:291
Definition: nodes.h:147
Definition: nodes.h:146
TypeName * typeName
Definition: parsenodes.h:299
List * args
Definition: primnodes.h:1145
int location
Definition: primnodes.h:815
Expr * arg
Definition: primnodes.h:477
#define NULL
Definition: c.h:229
#define lfirst(lc)
Definition: pg_list.h:106
int location
Definition: parsenodes.h:216
int location
Definition: primnodes.h:1182
List * args
Definition: parsenodes.h:351
List * args
Definition: primnodes.h:562
#define nodeTag(nodeptr)
Definition: nodes.h:514
void * arg
int location
Definition: primnodes.h:457
List * args
Definition: primnodes.h:501
Definition: pg_list.h:45
int location
Definition: primnodes.h:795
Node * arg
Definition: parsenodes.h:298
Definition: nodes.h:148
void exprSetCollation ( Node expr,
Oid  collation 
)

Definition at line 997 of file nodeFuncs.c.

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

Referenced by assign_collations_walker().

998 {
999  switch (nodeTag(expr))
1000  {
1001  case T_Var:
1002  ((Var *) expr)->varcollid = collation;
1003  break;
1004  case T_Const:
1005  ((Const *) expr)->constcollid = collation;
1006  break;
1007  case T_Param:
1008  ((Param *) expr)->paramcollid = collation;
1009  break;
1010  case T_Aggref:
1011  ((Aggref *) expr)->aggcollid = collation;
1012  break;
1013  case T_GroupingFunc:
1014  Assert(!OidIsValid(collation));
1015  break;
1016  case T_WindowFunc:
1017  ((WindowFunc *) expr)->wincollid = collation;
1018  break;
1019  case T_ArrayRef:
1020  ((ArrayRef *) expr)->refcollid = collation;
1021  break;
1022  case T_FuncExpr:
1023  ((FuncExpr *) expr)->funccollid = collation;
1024  break;
1025  case T_NamedArgExpr:
1026  Assert(collation == exprCollation((Node *) ((NamedArgExpr *) expr)->arg));
1027  break;
1028  case T_OpExpr:
1029  ((OpExpr *) expr)->opcollid = collation;
1030  break;
1031  case T_DistinctExpr:
1032  ((DistinctExpr *) expr)->opcollid = collation;
1033  break;
1034  case T_NullIfExpr:
1035  ((NullIfExpr *) expr)->opcollid = collation;
1036  break;
1037  case T_ScalarArrayOpExpr:
1038  Assert(!OidIsValid(collation)); /* result is always boolean */
1039  break;
1040  case T_BoolExpr:
1041  Assert(!OidIsValid(collation)); /* result is always boolean */
1042  break;
1043  case T_SubLink:
1044 #ifdef USE_ASSERT_CHECKING
1045  {
1046  SubLink *sublink = (SubLink *) expr;
1047 
1048  if (sublink->subLinkType == EXPR_SUBLINK ||
1049  sublink->subLinkType == ARRAY_SUBLINK)
1050  {
1051  /* get the collation of subselect's first target column */
1052  Query *qtree = (Query *) sublink->subselect;
1053  TargetEntry *tent;
1054 
1055  if (!qtree || !IsA(qtree, Query))
1056  elog(ERROR, "cannot set collation for untransformed sublink");
1057  tent = linitial_node(TargetEntry, qtree->targetList);
1058  Assert(!tent->resjunk);
1059  Assert(collation == exprCollation((Node *) tent->expr));
1060  }
1061  else
1062  {
1063  /* otherwise, result is RECORD or BOOLEAN */
1064  Assert(!OidIsValid(collation));
1065  }
1066  }
1067 #endif /* USE_ASSERT_CHECKING */
1068  break;
1069  case T_FieldSelect:
1070  ((FieldSelect *) expr)->resultcollid = collation;
1071  break;
1072  case T_FieldStore:
1073  Assert(!OidIsValid(collation)); /* result is always composite */
1074  break;
1075  case T_RelabelType:
1076  ((RelabelType *) expr)->resultcollid = collation;
1077  break;
1078  case T_CoerceViaIO:
1079  ((CoerceViaIO *) expr)->resultcollid = collation;
1080  break;
1081  case T_ArrayCoerceExpr:
1082  ((ArrayCoerceExpr *) expr)->resultcollid = collation;
1083  break;
1084  case T_ConvertRowtypeExpr:
1085  Assert(!OidIsValid(collation)); /* result is always composite */
1086  break;
1087  case T_CaseExpr:
1088  ((CaseExpr *) expr)->casecollid = collation;
1089  break;
1090  case T_ArrayExpr:
1091  ((ArrayExpr *) expr)->array_collid = collation;
1092  break;
1093  case T_RowExpr:
1094  Assert(!OidIsValid(collation)); /* result is always composite */
1095  break;
1096  case T_RowCompareExpr:
1097  Assert(!OidIsValid(collation)); /* result is always boolean */
1098  break;
1099  case T_CoalesceExpr:
1100  ((CoalesceExpr *) expr)->coalescecollid = collation;
1101  break;
1102  case T_MinMaxExpr:
1103  ((MinMaxExpr *) expr)->minmaxcollid = collation;
1104  break;
1105  case T_SQLValueFunction:
1106  Assert(!OidIsValid(collation)); /* no collatable results */
1107  break;
1108  case T_XmlExpr:
1109  Assert((((XmlExpr *) expr)->op == IS_XMLSERIALIZE) ?
1110  (collation == DEFAULT_COLLATION_OID) :
1111  (collation == InvalidOid));
1112  break;
1113  case T_NullTest:
1114  Assert(!OidIsValid(collation)); /* result is always boolean */
1115  break;
1116  case T_BooleanTest:
1117  Assert(!OidIsValid(collation)); /* result is always boolean */
1118  break;
1119  case T_CoerceToDomain:
1120  ((CoerceToDomain *) expr)->resultcollid = collation;
1121  break;
1122  case T_CoerceToDomainValue:
1123  ((CoerceToDomainValue *) expr)->collation = collation;
1124  break;
1125  case T_SetToDefault:
1126  ((SetToDefault *) expr)->collation = collation;
1127  break;
1128  case T_CurrentOfExpr:
1129  Assert(!OidIsValid(collation)); /* result is always boolean */
1130  break;
1131  case T_NextValueExpr:
1132  Assert(!OidIsValid(collation)); /* result is always an integer
1133  * type */
1134  break;
1135  default:
1136  elog(ERROR, "unrecognized node type: %d", (int) nodeTag(expr));
1137  break;
1138  }
1139 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:560
Definition: nodes.h:509
Definition: primnodes.h:163
#define linitial_node(type, l)
Definition: pg_list.h:114
#define OidIsValid(objectId)
Definition: c.h:538
List * targetList
Definition: parsenodes.h:138
#define ERROR
Definition: elog.h:43
#define DEFAULT_COLLATION_OID
Definition: pg_collation.h:75
Definition: nodes.h:147
Definition: nodes.h:146
#define InvalidOid
Definition: postgres_ext.h:36
#define Assert(condition)
Definition: c.h:675
Oid exprCollation(const Node *expr)
Definition: nodeFuncs.c:748
#define nodeTag(nodeptr)
Definition: nodes.h:514
void * arg
#define elog
Definition: elog.h:219
Definition: nodes.h:148
void exprSetInputCollation ( Node expr,
Oid  inputcollation 
)

Definition at line 1150 of file nodeFuncs.c.

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

Referenced by assign_collations_walker().

1151 {
1152  switch (nodeTag(expr))
1153  {
1154  case T_Aggref:
1155  ((Aggref *) expr)->inputcollid = inputcollation;
1156  break;
1157  case T_WindowFunc:
1158  ((WindowFunc *) expr)->inputcollid = inputcollation;
1159  break;
1160  case T_FuncExpr:
1161  ((FuncExpr *) expr)->inputcollid = inputcollation;
1162  break;
1163  case T_OpExpr:
1164  ((OpExpr *) expr)->inputcollid = inputcollation;
1165  break;
1166  case T_DistinctExpr:
1167  ((DistinctExpr *) expr)->inputcollid = inputcollation;
1168  break;
1169  case T_NullIfExpr:
1170  ((NullIfExpr *) expr)->inputcollid = inputcollation;
1171  break;
1172  case T_ScalarArrayOpExpr:
1173  ((ScalarArrayOpExpr *) expr)->inputcollid = inputcollation;
1174  break;
1175  case T_MinMaxExpr:
1176  ((MinMaxExpr *) expr)->inputcollid = inputcollation;
1177  break;
1178  default:
1179  break;
1180  }
1181 }
#define nodeTag(nodeptr)
Definition: nodes.h:514
Oid exprType ( const Node expr)

Definition at line 42 of file nodeFuncs.c.

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

Referenced by addTargetToGroupList(), addTargetToSortList(), analyzeCTE(), analyzeCTETargetList(), appendAggOrderBy(), assign_collations_walker(), assign_hypothetical_collations(), assign_nestloop_param_placeholdervar(), ATExecAlterColumnType(), ATPrepAlterColumnType(), build_column_default(), build_subplan(), canonicalize_ec_expression(), check_functions_in_node(), check_hashjoinable(), check_mergejoinable(), check_sql_fn_retval(), checkRuleResultList(), coerce_record_to_complex(), coerce_to_boolean(), coerce_to_common_type(), coerce_to_specific_type_typmod(), compare_tlist_datatypes(), compute_semijoin_info(), ComputeIndexAttrs(), ComputePartitionAttrs(), ConstructTupleDescriptor(), convert_EXISTS_to_ANY(), cookDefault(), cost_qual_eval_walker(), create_ctas_nodata(), create_indexscan_plan(), DefineVirtualRelation(), deparseNullTest(), estimate_num_groups(), eval_const_expressions_mutator(), EvaluateParams(), examine_attribute(), examine_variable(), exec_simple_recheck_plan(), ExecBuildProjectionInfo(), ExecCheckPlanOutput(), ExecEvalConvertRowtype(), ExecEvalXmlExpr(), ExecInitExprRec(), ExecInitIndexScan(), ExecMakeTableFunctionResult(), ExecTypeFromExprList(), ExecTypeFromTLInternal(), ExecWindowAgg(), expandRecordVariable(), ExpandRowReference(), expandRTE(), exprType(), exprTypmod(), find_minmax_aggs_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_agg_clause_costs_walker(), get_call_expr_argtype(), get_expr_result_type(), get_first_col_type(), get_fn_expr_rettype(), get_func_expr(), get_name_for_var_field(), get_oper_expr(), get_rte_attribute_type(), get_rule_expr(), get_rule_orderby(), get_simple_binary_op_name(), get_sublink_expr(), get_windowfunc_expr(), hash_ok_operator(), initialize_peragg(), inline_function(), internal_get_result_type(), IsTidEqualClause(), make_op(), make_scalar_array_op(), makeVarFromTargetEntry(), makeWholeRowVar(), ordered_set_startup(), ParseFuncOrColumn(), pg_get_indexdef_worker(), pg_get_partkeydef_worker(), prepare_query_params(), preprocess_minmax_aggregates(), ProcedureCreate(), process_equivalence(), process_matched_tle(), recheck_cast_function_args(), relabel_to_typmod(), RelationBuildPartitionKey(), remove_unused_subquery_outputs(), replace_outer_grouping(), replace_outer_placeholdervar(), resolveTargetListUnknowns(), scalararraysel(), select_common_type(), set_append_rel_size(), set_dummy_tlist_references(), set_pathtarget_cost_width(), set_rel_width(), show_sortorder_options(), tlist_matches_coltypelist(), tlist_same_datatypes(), transformAExprNullIf(), transformAExprOf(), transformAggregateCall(), transformArrayExpr(), transformArraySubscripts(), transformAssignedExpr(), transformAssignmentIndirection(), transformAssignmentSubscripts(), transformCaseExpr(), transformCollateClause(), transformExprRecurse(), transformIndirection(), transformInsertStmt(), transformMultiAssignRef(), transformPartitionBound(), transformSetOperationTree(), transformSubLink(), transformTypeCast(), unknown_attribute(), and xmlelement().

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

Definition at line 276 of file nodeFuncs.c.

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

Referenced by analyzeCTE(), analyzeCTETargetList(), assign_hypothetical_collations(), assign_nestloop_param_placeholdervar(), 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_variable(), exec_simple_recheck_plan(), ExecTypeFromExprList(), ExecTypeFromTLInternal(), expandRecordVariable(), ExpandRowReference(), expandRTE(), exprTypmod(), find_placeholder_info(), generate_append_tlist(), generate_setop_tlist(), generate_subquery_params(), get_agg_clause_costs_walker(), get_first_col_type(), get_name_for_var_field(), get_rte_attribute_type(), get_rule_expr(), interval_transform(), makeVarFromTargetEntry(), numeric_transform(), RelationBuildPartitionKey(), remove_unused_subquery_outputs(), replace_outer_placeholdervar(), set_append_rel_size(), set_dummy_tlist_references(), set_pathtarget_cost_width(), set_rel_width(), TemporalTransform(), transformCaseExpr(), transformIndirection(), transformMultiAssignRef(), transformSetOperationTree(), transformSubLink(), transformValuesClause(), varbit_transform(), and varchar_transform().

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

Definition at line 1604 of file nodeFuncs.c.

References fix_opfuncids_walker(), and NULL.

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

1605 {
1606  /* This tree walk requires no special setup, so away we go... */
1607  fix_opfuncids_walker(node, NULL);
1608 }
static bool fix_opfuncids_walker(Node *node, void *context)
Definition: nodeFuncs.c:1611
#define NULL
Definition: c.h:229
bool planstate_tree_walker ( struct PlanState planstate,
bool(*)()  walker,
void *  context 
)

Definition at line 3719 of file nodeFuncs.c.

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

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

3722 {
3723  Plan *plan = planstate->plan;
3724  ListCell *lc;
3725 
3726  /* initPlan-s */
3727  if (planstate_walk_subplans(planstate->initPlan, walker, context))
3728  return true;
3729 
3730  /* lefttree */
3731  if (outerPlanState(planstate))
3732  {
3733  if (walker(outerPlanState(planstate), context))
3734  return true;
3735  }
3736 
3737  /* righttree */
3738  if (innerPlanState(planstate))
3739  {
3740  if (walker(innerPlanState(planstate), context))
3741  return true;
3742  }
3743 
3744  /* special child plans */
3745  switch (nodeTag(plan))
3746  {
3747  case T_ModifyTable:
3748  if (planstate_walk_members(((ModifyTable *) plan)->plans,
3749  ((ModifyTableState *) planstate)->mt_plans,
3750  walker, context))
3751  return true;
3752  break;
3753  case T_Append:
3754  if (planstate_walk_members(((Append *) plan)->appendplans,
3755  ((AppendState *) planstate)->appendplans,
3756  walker, context))
3757  return true;
3758  break;
3759  case T_MergeAppend:
3760  if (planstate_walk_members(((MergeAppend *) plan)->mergeplans,
3761  ((MergeAppendState *) planstate)->mergeplans,
3762  walker, context))
3763  return true;
3764  break;
3765  case T_BitmapAnd:
3766  if (planstate_walk_members(((BitmapAnd *) plan)->bitmapplans,
3767  ((BitmapAndState *) planstate)->bitmapplans,
3768  walker, context))
3769  return true;
3770  break;
3771  case T_BitmapOr:
3772  if (planstate_walk_members(((BitmapOr *) plan)->bitmapplans,
3773  ((BitmapOrState *) planstate)->bitmapplans,
3774  walker, context))
3775  return true;
3776  break;
3777  case T_SubqueryScan:
3778  if (walker(((SubqueryScanState *) planstate)->subplan, context))
3779  return true;
3780  break;
3781  case T_CustomScan:
3782  foreach(lc, ((CustomScanState *) planstate)->custom_ps)
3783  {
3784  if (walker((PlanState *) lfirst(lc), context))
3785  return true;
3786  }
3787  break;
3788  default:
3789  break;
3790  }
3791 
3792  /* subPlan-s */
3793  if (planstate_walk_subplans(planstate->subPlan, walker, context))
3794  return true;
3795 
3796  return false;
3797 }
List * initPlan
Definition: execnodes.h:830
List * subPlan
Definition: execnodes.h:832
Definition: nodes.h:48
#define outerPlanState(node)
Definition: execnodes.h:855
static bool planstate_walk_subplans(List *plans, bool(*walker)(), void *context)
Definition: nodeFuncs.c:3803
Plan * plan
Definition: execnodes.h:813
#define lfirst(lc)
Definition: pg_list.h:106
#define nodeTag(nodeptr)
Definition: nodes.h:514
static bool planstate_walk_members(List *plans, PlanState **planstates, bool(*walker)(), void *context)
Definition: nodeFuncs.c:3828
#define innerPlanState(node)
Definition: execnodes.h:854
Node* query_or_expression_tree_mutator ( Node node,
Node *(*)()  mutator,
void *  context,
int  flags 
)

Definition at line 3223 of file nodeFuncs.c.

References IsA, and query_tree_mutator().

Referenced by map_variable_attnos(), and replace_rte_variables().

3227 {
3228  if (node && IsA(node, Query))
3229  return (Node *) query_tree_mutator((Query *) node,
3230  mutator,
3231  context,
3232  flags);
3233  else
3234  return mutator(node, context);
3235 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:560
Definition: nodes.h:509
Query * query_tree_mutator(Query *query, Node *(*mutator)(), void *context, int flags)
Definition: nodeFuncs.c:3090
bool query_or_expression_tree_walker ( Node node,
bool(*)()  walker,
void *  context,
int  flags 
)

Definition at line 3200 of file nodeFuncs.c.

References IsA, and query_tree_walker().

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

3204 {
3205  if (node && IsA(node, Query))
3206  return query_tree_walker((Query *) node,
3207  walker,
3208  context,
3209  flags);
3210  else
3211  return walker(node, context);
3212 }
bool query_tree_walker(Query *query, bool(*walker)(), void *context, int flags)
Definition: nodeFuncs.c:2268
#define IsA(nodeptr, _type_)
Definition: nodes.h:560
Query* query_tree_mutator ( Query query,
Node *(*)()  mutator,
void *  context,
int  flags 
)

Definition at line 3090 of file nodeFuncs.c.

References Assert, copyObject, Query::cteList, FLATCOPY, Query::havingQual, IsA, Query::jointree, Query::limitCount, Query::limitOffset, MUTATE, NULL, Query::onConflict, QTW_DONT_COPY_QUERY, QTW_IGNORE_CTE_SUBQUERIES, range_table_mutator(), Query::returningList, Query::rtable, Query::setOperations, Query::targetList, and Query::withCheckOptions.

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

3094 {
3095  Assert(query != NULL && IsA(query, Query));
3096 
3097  if (!(flags & QTW_DONT_COPY_QUERY))
3098  {
3099  Query *newquery;
3100 
3101  FLATCOPY(newquery, query, Query);
3102  query = newquery;
3103  }
3104 
3105  MUTATE(query->targetList, query->targetList, List *);
3106  MUTATE(query->withCheckOptions, query->withCheckOptions, List *);
3107  MUTATE(query->onConflict, query->onConflict, OnConflictExpr *);
3108  MUTATE(query->returningList, query->returningList, List *);
3109  MUTATE(query->jointree, query->jointree, FromExpr *);
3110  MUTATE(query->setOperations, query->setOperations, Node *);
3111  MUTATE(query->havingQual, query->havingQual, Node *);
3112  MUTATE(query->limitOffset, query->limitOffset, Node *);
3113  MUTATE(query->limitCount, query->limitCount, Node *);
3114  if (!(flags & QTW_IGNORE_CTE_SUBQUERIES))
3115  MUTATE(query->cteList, query->cteList, List *);
3116  else /* else copy CTE list as-is */
3117  query->cteList = copyObject(query->cteList);
3118  query->rtable = range_table_mutator(query->rtable,
3119  mutator, context, flags);
3120  return query;
3121 }
Node * limitOffset
Definition: parsenodes.h:158
#define IsA(nodeptr, _type_)
Definition: nodes.h:560
FromExpr * jointree
Definition: parsenodes.h:136
OnConflictExpr * onConflict
Definition: parsenodes.h:142
List * withCheckOptions
Definition: parsenodes.h:169
Definition: nodes.h:509
#define QTW_DONT_COPY_QUERY
Definition: nodeFuncs.h:26
List * targetList
Definition: parsenodes.h:138
#define QTW_IGNORE_CTE_SUBQUERIES
Definition: nodeFuncs.h:21
List * rtable
Definition: parsenodes.h:135
Node * limitCount
Definition: parsenodes.h:159
List * returningList
Definition: parsenodes.h:144
#define FLATCOPY(newnode, node, nodetype)
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
List * cteList
Definition: parsenodes.h:133
Node * setOperations
Definition: parsenodes.h:163
List * range_table_mutator(List *rtable, Node *(*mutator)(), void *context, int flags)
Definition: nodeFuncs.c:3129
#define copyObject(obj)
Definition: nodes.h:621
Node * havingQual
Definition: parsenodes.h:150
Definition: pg_list.h:45
#define MUTATE(newfield, oldfield, fieldtype)
bool query_tree_walker ( Query query,
bool(*)()  walker,
void *  context,
int  flags 
)

Definition at line 2268 of file nodeFuncs.c.

References Assert, Query::cteList, Query::havingQual, IsA, Query::jointree, Query::limitCount, Query::limitOffset, NULL, Query::onConflict, QTW_IGNORE_CTE_SUBQUERIES, QTW_IGNORE_RANGE_TABLE, range_table_walker(), Query::returningList, Query::rtable, Query::setOperations, Query::targetList, and Query::withCheckOptions.

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

2272 {
2273  Assert(query != NULL && IsA(query, Query));
2274 
2275  if (walker((Node *) query->targetList, context))
2276  return true;
2277  if (walker((Node *) query->withCheckOptions, context))
2278  return true;
2279  if (walker((Node *) query->onConflict, context))
2280  return true;
2281  if (walker((Node *) query->returningList, context))
2282  return true;
2283  if (walker((Node *) query->jointree, context))
2284  return true;
2285  if (walker(query->setOperations, context))
2286  return true;
2287  if (walker(query->havingQual, context))
2288  return true;
2289  if (walker(query->limitOffset, context))
2290  return true;
2291  if (walker(query->limitCount, context))
2292  return true;
2293  if (!(flags & QTW_IGNORE_CTE_SUBQUERIES))
2294  {
2295  if (walker((Node *) query->cteList, context))
2296  return true;
2297  }
2298  if (!(flags & QTW_IGNORE_RANGE_TABLE))
2299  {
2300  if (range_table_walker(query->rtable, walker, context, flags))
2301  return true;
2302  }
2303  return false;
2304 }
Node * limitOffset
Definition: parsenodes.h:158
#define IsA(nodeptr, _type_)
Definition: nodes.h:560
FromExpr * jointree
Definition: parsenodes.h:136
OnConflictExpr * onConflict
Definition: parsenodes.h:142
List * withCheckOptions
Definition: parsenodes.h:169
Definition: nodes.h:509
List * targetList
Definition: parsenodes.h:138
#define QTW_IGNORE_CTE_SUBQUERIES
Definition: nodeFuncs.h:21
List * rtable
Definition: parsenodes.h:135
Node * limitCount
Definition: parsenodes.h:159
List * returningList
Definition: parsenodes.h:144
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
bool range_table_walker(List *rtable, bool(*walker)(), void *context, int flags)
Definition: nodeFuncs.c:2312
List * cteList
Definition: parsenodes.h:133
Node * setOperations
Definition: parsenodes.h:163
#define QTW_IGNORE_RANGE_TABLE
Definition: nodeFuncs.h:24
Node * havingQual
Definition: parsenodes.h:150
List* range_table_mutator ( List rtable,
Node *(*)()  mutator,
void *  context,
int  flags 
)

Definition at line 3129 of file nodeFuncs.c.

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

Referenced by query_tree_mutator().

3133 {
3134  List *newrt = NIL;
3135  ListCell *rt;
3136 
3137  foreach(rt, rtable)
3138  {
3139  RangeTblEntry *rte = (RangeTblEntry *) lfirst(rt);
3140  RangeTblEntry *newrte;
3141 
3142  FLATCOPY(newrte, rte, RangeTblEntry);
3143  switch (rte->rtekind)
3144  {
3145  case RTE_RELATION:
3146  MUTATE(newrte->tablesample, rte->tablesample,
3147  TableSampleClause *);
3148  /* we don't bother to copy eref, aliases, etc; OK? */
3149  break;
3150  case RTE_CTE:
3151  case RTE_NAMEDTUPLESTORE:
3152  /* nothing to do */
3153  break;
3154  case RTE_SUBQUERY:
3155  if (!(flags & QTW_IGNORE_RT_SUBQUERIES))
3156  {
3157  CHECKFLATCOPY(newrte->subquery, rte->subquery, Query);
3158  MUTATE(newrte->subquery, newrte->subquery, Query *);
3159  }
3160  else
3161  {
3162  /* else, copy RT subqueries as-is */
3163  newrte->subquery = copyObject(rte->subquery);
3164  }
3165  break;
3166  case RTE_JOIN:
3167  if (!(flags & QTW_IGNORE_JOINALIASES))
3168  MUTATE(newrte->joinaliasvars, rte->joinaliasvars, List *);
3169  else
3170  {
3171  /* else, copy join aliases as-is */
3172  newrte->joinaliasvars = copyObject(rte->joinaliasvars);
3173  }
3174  break;
3175  case RTE_FUNCTION:
3176  MUTATE(newrte->functions, rte->functions, List *);
3177  break;
3178  case RTE_TABLEFUNC:
3179  MUTATE(newrte->tablefunc, rte->tablefunc, TableFunc *);
3180  break;
3181  case RTE_VALUES:
3182  MUTATE(newrte->values_lists, rte->values_lists, List *);
3183  break;
3184  }
3185  MUTATE(newrte->securityQuals, rte->securityQuals, List *);
3186  newrt = lappend(newrt, newrte);
3187  }
3188  return newrt;
3189 }
#define NIL
Definition: pg_list.h:69
List * joinaliasvars
Definition: parsenodes.h:968
#define CHECKFLATCOPY(newnode, node, nodetype)
List * securityQuals
Definition: parsenodes.h:1025
List * values_lists
Definition: parsenodes.h:989
TableFunc * tablefunc
Definition: parsenodes.h:984
List * lappend(List *list, void *datum)
Definition: list.c:128
#define FLATCOPY(newnode, node, nodetype)
#define lfirst(lc)
Definition: pg_list.h:106
List * functions
Definition: parsenodes.h:978
RTEKind rtekind
Definition: parsenodes.h:929
#define QTW_IGNORE_RT_SUBQUERIES
Definition: nodeFuncs.h:20
Query * subquery
Definition: parsenodes.h:947
#define copyObject(obj)
Definition: nodes.h:621
Definition: pg_list.h:45
struct TableSampleClause * tablesample
Definition: parsenodes.h:942
#define MUTATE(newfield, oldfield, fieldtype)
#define QTW_IGNORE_JOINALIASES
Definition: nodeFuncs.h:23
bool range_table_walker ( List rtable,
bool(*)()  walker,
void *  context,
int  flags 
)

Definition at line 2312 of file nodeFuncs.c.

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

Referenced by IncrementVarSublevelsUp_rtable(), and query_tree_walker().

2316 {
2317  ListCell *rt;
2318 
2319  foreach(rt, rtable)
2320  {
2321  RangeTblEntry *rte = (RangeTblEntry *) lfirst(rt);
2322 
2323  /* For historical reasons, visiting RTEs is not the default */
2324  if (flags & QTW_EXAMINE_RTES)
2325  if (walker(rte, context))
2326  return true;
2327 
2328  switch (rte->rtekind)
2329  {
2330  case RTE_RELATION:
2331  if (walker(rte->tablesample, context))
2332  return true;
2333  break;
2334  case RTE_CTE:
2335  case RTE_NAMEDTUPLESTORE:
2336  /* nothing to do */
2337  break;
2338  case RTE_SUBQUERY:
2339  if (!(flags & QTW_IGNORE_RT_SUBQUERIES))
2340  if (walker(rte->subquery, context))
2341  return true;
2342  break;
2343  case RTE_JOIN:
2344  if (!(flags & QTW_IGNORE_JOINALIASES))
2345  if (walker(rte->joinaliasvars, context))
2346  return true;
2347  break;
2348  case RTE_FUNCTION:
2349  if (walker(rte->functions, context))
2350  return true;
2351  break;
2352  case RTE_TABLEFUNC:
2353  if (walker(rte->tablefunc, context))
2354  return true;
2355  break;
2356  case RTE_VALUES:
2357  if (walker(rte->values_lists, context))
2358  return true;
2359  break;
2360  }
2361 
2362  if (walker(rte->securityQuals, context))
2363  return true;
2364  }
2365  return false;
2366 }
List * joinaliasvars
Definition: parsenodes.h:968
List * securityQuals
Definition: parsenodes.h:1025
List * values_lists
Definition: parsenodes.h:989