gooderp18绿色标准版
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

1528 rindas
60KB

  1. /*-------------------------------------------------------------------------
  2. *
  3. * primnodes.h
  4. * Definitions for "primitive" node types, those that are used in more
  5. * than one of the parse/plan/execute stages of the query pipeline.
  6. * Currently, these are mostly nodes for executable expressions
  7. * and join trees.
  8. *
  9. *
  10. * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
  11. * Portions Copyright (c) 1994, Regents of the University of California
  12. *
  13. * src/include/nodes/primnodes.h
  14. *
  15. *-------------------------------------------------------------------------
  16. */
  17. #ifndef PRIMNODES_H
  18. #define PRIMNODES_H
  19. #include "access/attnum.h"
  20. #include "nodes/bitmapset.h"
  21. #include "nodes/pg_list.h"
  22. /* ----------------------------------------------------------------
  23. * node definitions
  24. * ----------------------------------------------------------------
  25. */
  26. /*
  27. * Alias -
  28. * specifies an alias for a range variable; the alias might also
  29. * specify renaming of columns within the table.
  30. *
  31. * Note: colnames is a list of Value nodes (always strings). In Alias structs
  32. * associated with RTEs, there may be entries corresponding to dropped
  33. * columns; these are normally empty strings (""). See parsenodes.h for info.
  34. */
  35. typedef struct Alias
  36. {
  37. NodeTag type;
  38. char *aliasname; /* aliased rel name (never qualified) */
  39. List *colnames; /* optional list of column aliases */
  40. } Alias;
  41. /* What to do at commit time for temporary relations */
  42. typedef enum OnCommitAction
  43. {
  44. ONCOMMIT_NOOP, /* No ON COMMIT clause (do nothing) */
  45. ONCOMMIT_PRESERVE_ROWS, /* ON COMMIT PRESERVE ROWS (do nothing) */
  46. ONCOMMIT_DELETE_ROWS, /* ON COMMIT DELETE ROWS */
  47. ONCOMMIT_DROP /* ON COMMIT DROP */
  48. } OnCommitAction;
  49. /*
  50. * RangeVar - range variable, used in FROM clauses
  51. *
  52. * Also used to represent table names in utility statements; there, the alias
  53. * field is not used, and inh tells whether to apply the operation
  54. * recursively to child tables. In some contexts it is also useful to carry
  55. * a TEMP table indication here.
  56. */
  57. typedef struct RangeVar
  58. {
  59. NodeTag type;
  60. char *catalogname; /* the catalog (database) name, or NULL */
  61. char *schemaname; /* the schema name, or NULL */
  62. char *relname; /* the relation/sequence name */
  63. bool inh; /* expand rel by inheritance? recursively act
  64. * on children? */
  65. char relpersistence; /* see RELPERSISTENCE_* in pg_class.h */
  66. Alias *alias; /* table alias & optional column aliases */
  67. int location; /* token location, or -1 if unknown */
  68. } RangeVar;
  69. /*
  70. * TableFunc - node for a table function, such as XMLTABLE.
  71. *
  72. * Entries in the ns_names list are either string Value nodes containing
  73. * literal namespace names, or NULL pointers to represent DEFAULT.
  74. */
  75. typedef struct TableFunc
  76. {
  77. NodeTag type;
  78. List *ns_uris; /* list of namespace URI expressions */
  79. List *ns_names; /* list of namespace names or NULL */
  80. Node *docexpr; /* input document expression */
  81. Node *rowexpr; /* row filter expression */
  82. List *colnames; /* column names (list of String) */
  83. List *coltypes; /* OID list of column type OIDs */
  84. List *coltypmods; /* integer list of column typmods */
  85. List *colcollations; /* OID list of column collation OIDs */
  86. List *colexprs; /* list of column filter expressions */
  87. List *coldefexprs; /* list of column default expressions */
  88. Bitmapset *notnulls; /* nullability flag for each output column */
  89. int ordinalitycol; /* counts from 0; -1 if none specified */
  90. int location; /* token location, or -1 if unknown */
  91. } TableFunc;
  92. /*
  93. * IntoClause - target information for SELECT INTO, CREATE TABLE AS, and
  94. * CREATE MATERIALIZED VIEW
  95. *
  96. * For CREATE MATERIALIZED VIEW, viewQuery is the parsed-but-not-rewritten
  97. * SELECT Query for the view; otherwise it's NULL. (Although it's actually
  98. * Query*, we declare it as Node* to avoid a forward reference.)
  99. */
  100. typedef struct IntoClause
  101. {
  102. NodeTag type;
  103. RangeVar *rel; /* target relation name */
  104. List *colNames; /* column names to assign, or NIL */
  105. char *accessMethod; /* table access method */
  106. List *options; /* options from WITH clause */
  107. OnCommitAction onCommit; /* what do we do at COMMIT? */
  108. char *tableSpaceName; /* table space to use, or NULL */
  109. Node *viewQuery; /* materialized view's SELECT query */
  110. bool skipData; /* true for WITH NO DATA */
  111. } IntoClause;
  112. /* ----------------------------------------------------------------
  113. * node types for executable expressions
  114. * ----------------------------------------------------------------
  115. */
  116. /*
  117. * Expr - generic superclass for executable-expression nodes
  118. *
  119. * All node types that are used in executable expression trees should derive
  120. * from Expr (that is, have Expr as their first field). Since Expr only
  121. * contains NodeTag, this is a formality, but it is an easy form of
  122. * documentation. See also the ExprState node types in execnodes.h.
  123. */
  124. typedef struct Expr
  125. {
  126. NodeTag type;
  127. } Expr;
  128. /*
  129. * Var - expression node representing a variable (ie, a table column)
  130. *
  131. * Note: during parsing/planning, varnoold/varoattno are always just copies
  132. * of varno/varattno. At the tail end of planning, Var nodes appearing in
  133. * upper-level plan nodes are reassigned to point to the outputs of their
  134. * subplans; for example, in a join node varno becomes INNER_VAR or OUTER_VAR
  135. * and varattno becomes the index of the proper element of that subplan's
  136. * target list. Similarly, INDEX_VAR is used to identify Vars that reference
  137. * an index column rather than a heap column. (In ForeignScan and CustomScan
  138. * plan nodes, INDEX_VAR is abused to signify references to columns of a
  139. * custom scan tuple type.) In all these cases, varnoold/varoattno hold the
  140. * original values. The code doesn't really need varnoold/varoattno, but they
  141. * are very useful for debugging and interpreting completed plans, so we keep
  142. * them around.
  143. */
  144. #define INNER_VAR 65000 /* reference to inner subplan */
  145. #define OUTER_VAR 65001 /* reference to outer subplan */
  146. #define INDEX_VAR 65002 /* reference to index column */
  147. #define IS_SPECIAL_VARNO(varno) ((varno) >= INNER_VAR)
  148. /* Symbols for the indexes of the special RTE entries in rules */
  149. #define PRS2_OLD_VARNO 1
  150. #define PRS2_NEW_VARNO 2
  151. typedef struct Var
  152. {
  153. Expr xpr;
  154. Index varno; /* index of this var's relation in the range
  155. * table, or INNER_VAR/OUTER_VAR/INDEX_VAR */
  156. AttrNumber varattno; /* attribute number of this var, or zero for
  157. * all attrs ("whole-row Var") */
  158. Oid vartype; /* pg_type OID for the type of this var */
  159. int32 vartypmod; /* pg_attribute typmod value */
  160. Oid varcollid; /* OID of collation, or InvalidOid if none */
  161. Index varlevelsup; /* for subquery variables referencing outer
  162. * relations; 0 in a normal var, >0 means N
  163. * levels up */
  164. Index varnoold; /* original value of varno, for debugging */
  165. AttrNumber varoattno; /* original value of varattno */
  166. int location; /* token location, or -1 if unknown */
  167. } Var;
  168. /*
  169. * Const
  170. *
  171. * Note: for varlena data types, we make a rule that a Const node's value
  172. * must be in non-extended form (4-byte header, no compression or external
  173. * references). This ensures that the Const node is self-contained and makes
  174. * it more likely that equal() will see logically identical values as equal.
  175. */
  176. typedef struct Const
  177. {
  178. Expr xpr;
  179. Oid consttype; /* pg_type OID of the constant's datatype */
  180. int32 consttypmod; /* typmod value, if any */
  181. Oid constcollid; /* OID of collation, or InvalidOid if none */
  182. int constlen; /* typlen of the constant's datatype */
  183. Datum constvalue; /* the constant's value */
  184. bool constisnull; /* whether the constant is null (if true,
  185. * constvalue is undefined) */
  186. bool constbyval; /* whether this datatype is passed by value.
  187. * If true, then all the information is stored
  188. * in the Datum. If false, then the Datum
  189. * contains a pointer to the information. */
  190. int location; /* token location, or -1 if unknown */
  191. } Const;
  192. /*
  193. * Param
  194. *
  195. * paramkind specifies the kind of parameter. The possible values
  196. * for this field are:
  197. *
  198. * PARAM_EXTERN: The parameter value is supplied from outside the plan.
  199. * Such parameters are numbered from 1 to n.
  200. *
  201. * PARAM_EXEC: The parameter is an internal executor parameter, used
  202. * for passing values into and out of sub-queries or from
  203. * nestloop joins to their inner scans.
  204. * For historical reasons, such parameters are numbered from 0.
  205. * These numbers are independent of PARAM_EXTERN numbers.
  206. *
  207. * PARAM_SUBLINK: The parameter represents an output column of a SubLink
  208. * node's sub-select. The column number is contained in the
  209. * `paramid' field. (This type of Param is converted to
  210. * PARAM_EXEC during planning.)
  211. *
  212. * PARAM_MULTIEXPR: Like PARAM_SUBLINK, the parameter represents an
  213. * output column of a SubLink node's sub-select, but here, the
  214. * SubLink is always a MULTIEXPR SubLink. The high-order 16 bits
  215. * of the `paramid' field contain the SubLink's subLinkId, and
  216. * the low-order 16 bits contain the column number. (This type
  217. * of Param is also converted to PARAM_EXEC during planning.)
  218. */
  219. typedef enum ParamKind
  220. {
  221. PARAM_EXTERN,
  222. PARAM_EXEC,
  223. PARAM_SUBLINK,
  224. PARAM_MULTIEXPR
  225. } ParamKind;
  226. typedef struct Param
  227. {
  228. Expr xpr;
  229. ParamKind paramkind; /* kind of parameter. See above */
  230. int paramid; /* numeric ID for parameter */
  231. Oid paramtype; /* pg_type OID of parameter's datatype */
  232. int32 paramtypmod; /* typmod value, if known */
  233. Oid paramcollid; /* OID of collation, or InvalidOid if none */
  234. int location; /* token location, or -1 if unknown */
  235. } Param;
  236. /*
  237. * Aggref
  238. *
  239. * The aggregate's args list is a targetlist, ie, a list of TargetEntry nodes.
  240. *
  241. * For a normal (non-ordered-set) aggregate, the non-resjunk TargetEntries
  242. * represent the aggregate's regular arguments (if any) and resjunk TLEs can
  243. * be added at the end to represent ORDER BY expressions that are not also
  244. * arguments. As in a top-level Query, the TLEs can be marked with
  245. * ressortgroupref indexes to let them be referenced by SortGroupClause
  246. * entries in the aggorder and/or aggdistinct lists. This represents ORDER BY
  247. * and DISTINCT operations to be applied to the aggregate input rows before
  248. * they are passed to the transition function. The grammar only allows a
  249. * simple "DISTINCT" specifier for the arguments, but we use the full
  250. * query-level representation to allow more code sharing.
  251. *
  252. * For an ordered-set aggregate, the args list represents the WITHIN GROUP
  253. * (aggregated) arguments, all of which will be listed in the aggorder list.
  254. * DISTINCT is not supported in this case, so aggdistinct will be NIL.
  255. * The direct arguments appear in aggdirectargs (as a list of plain
  256. * expressions, not TargetEntry nodes).
  257. *
  258. * aggtranstype is the data type of the state transition values for this
  259. * aggregate (resolved to an actual type, if agg's transtype is polymorphic).
  260. * This is determined during planning and is InvalidOid before that.
  261. *
  262. * aggargtypes is an OID list of the data types of the direct and regular
  263. * arguments. Normally it's redundant with the aggdirectargs and args lists,
  264. * but in a combining aggregate, it's not because the args list has been
  265. * replaced with a single argument representing the partial-aggregate
  266. * transition values.
  267. *
  268. * aggsplit indicates the expected partial-aggregation mode for the Aggref's
  269. * parent plan node. It's always set to AGGSPLIT_SIMPLE in the parser, but
  270. * the planner might change it to something else. We use this mainly as
  271. * a crosscheck that the Aggrefs match the plan; but note that when aggsplit
  272. * indicates a non-final mode, aggtype reflects the transition data type
  273. * not the SQL-level output type of the aggregate.
  274. */
  275. typedef struct Aggref
  276. {
  277. Expr xpr;
  278. Oid aggfnoid; /* pg_proc Oid of the aggregate */
  279. Oid aggtype; /* type Oid of result of the aggregate */
  280. Oid aggcollid; /* OID of collation of result */
  281. Oid inputcollid; /* OID of collation that function should use */
  282. Oid aggtranstype; /* type Oid of aggregate's transition value */
  283. List *aggargtypes; /* type Oids of direct and aggregated args */
  284. List *aggdirectargs; /* direct arguments, if an ordered-set agg */
  285. List *args; /* aggregated arguments and sort expressions */
  286. List *aggorder; /* ORDER BY (list of SortGroupClause) */
  287. List *aggdistinct; /* DISTINCT (list of SortGroupClause) */
  288. Expr *aggfilter; /* FILTER expression, if any */
  289. bool aggstar; /* true if argument list was really '*' */
  290. bool aggvariadic; /* true if variadic arguments have been
  291. * combined into an array last argument */
  292. char aggkind; /* aggregate kind (see pg_aggregate.h) */
  293. Index agglevelsup; /* > 0 if agg belongs to outer query */
  294. AggSplit aggsplit; /* expected agg-splitting mode of parent Agg */
  295. int location; /* token location, or -1 if unknown */
  296. } Aggref;
  297. /*
  298. * GroupingFunc
  299. *
  300. * A GroupingFunc is a GROUPING(...) expression, which behaves in many ways
  301. * like an aggregate function (e.g. it "belongs" to a specific query level,
  302. * which might not be the one immediately containing it), but also differs in
  303. * an important respect: it never evaluates its arguments, they merely
  304. * designate expressions from the GROUP BY clause of the query level to which
  305. * it belongs.
  306. *
  307. * The spec defines the evaluation of GROUPING() purely by syntactic
  308. * replacement, but we make it a real expression for optimization purposes so
  309. * that one Agg node can handle multiple grouping sets at once. Evaluating the
  310. * result only needs the column positions to check against the grouping set
  311. * being projected. However, for EXPLAIN to produce meaningful output, we have
  312. * to keep the original expressions around, since expression deparse does not
  313. * give us any feasible way to get at the GROUP BY clause.
  314. *
  315. * Also, we treat two GroupingFunc nodes as equal if they have equal arguments
  316. * lists and agglevelsup, without comparing the refs and cols annotations.
  317. *
  318. * In raw parse output we have only the args list; parse analysis fills in the
  319. * refs list, and the planner fills in the cols list.
  320. */
  321. typedef struct GroupingFunc
  322. {
  323. Expr xpr;
  324. List *args; /* arguments, not evaluated but kept for
  325. * benefit of EXPLAIN etc. */
  326. List *refs; /* ressortgrouprefs of arguments */
  327. List *cols; /* actual column positions set by planner */
  328. Index agglevelsup; /* same as Aggref.agglevelsup */
  329. int location; /* token location */
  330. } GroupingFunc;
  331. /*
  332. * WindowFunc
  333. */
  334. typedef struct WindowFunc
  335. {
  336. Expr xpr;
  337. Oid winfnoid; /* pg_proc Oid of the function */
  338. Oid wintype; /* type Oid of result of the window function */
  339. Oid wincollid; /* OID of collation of result */
  340. Oid inputcollid; /* OID of collation that function should use */
  341. List *args; /* arguments to the window function */
  342. Expr *aggfilter; /* FILTER expression, if any */
  343. Index winref; /* index of associated WindowClause */
  344. bool winstar; /* true if argument list was really '*' */
  345. bool winagg; /* is function a simple aggregate? */
  346. int location; /* token location, or -1 if unknown */
  347. } WindowFunc;
  348. /* ----------------
  349. * SubscriptingRef: describes a subscripting operation over a container
  350. * (array, etc).
  351. *
  352. * A SubscriptingRef can describe fetching a single element from a container,
  353. * fetching a part of container (e.g. array slice), storing a single element into
  354. * a container, or storing a slice. The "store" cases work with an
  355. * initial container value and a source value that is inserted into the
  356. * appropriate part of the container; the result of the operation is an
  357. * entire new modified container value.
  358. *
  359. * If reflowerindexpr = NIL, then we are fetching or storing a single container
  360. * element at the subscripts given by refupperindexpr. Otherwise we are
  361. * fetching or storing a container slice, that is a rectangular subcontainer
  362. * with lower and upper bounds given by the index expressions.
  363. * reflowerindexpr must be the same length as refupperindexpr when it
  364. * is not NIL.
  365. *
  366. * In the slice case, individual expressions in the subscript lists can be
  367. * NULL, meaning "substitute the array's current lower or upper bound".
  368. *
  369. * Note: the result datatype is the element type when fetching a single
  370. * element; but it is the array type when doing subarray fetch or either
  371. * type of store.
  372. *
  373. * Note: for the cases where a container is returned, if refexpr yields a R/W
  374. * expanded container, then the implementation is allowed to modify that object
  375. * in-place and return the same object.)
  376. * ----------------
  377. */
  378. typedef struct SubscriptingRef
  379. {
  380. Expr xpr;
  381. Oid refcontainertype; /* type of the container proper */
  382. Oid refelemtype; /* type of the container elements */
  383. int32 reftypmod; /* typmod of the container (and elements too) */
  384. Oid refcollid; /* OID of collation, or InvalidOid if none */
  385. List *refupperindexpr; /* expressions that evaluate to upper
  386. * container indexes */
  387. List *reflowerindexpr; /* expressions that evaluate to lower
  388. * container indexes, or NIL for single
  389. * container element */
  390. Expr *refexpr; /* the expression that evaluates to a
  391. * container value */
  392. Expr *refassgnexpr; /* expression for the source value, or NULL if
  393. * fetch */
  394. } SubscriptingRef;
  395. /*
  396. * CoercionContext - distinguishes the allowed set of type casts
  397. *
  398. * NB: ordering of the alternatives is significant; later (larger) values
  399. * allow more casts than earlier ones.
  400. */
  401. typedef enum CoercionContext
  402. {
  403. COERCION_IMPLICIT, /* coercion in context of expression */
  404. COERCION_ASSIGNMENT, /* coercion in context of assignment */
  405. COERCION_EXPLICIT /* explicit cast operation */
  406. } CoercionContext;
  407. /*
  408. * CoercionForm - how to display a node that could have come from a cast
  409. *
  410. * NB: equal() ignores CoercionForm fields, therefore this *must* not carry
  411. * any semantically significant information. We need that behavior so that
  412. * the planner will consider equivalent implicit and explicit casts to be
  413. * equivalent. In cases where those actually behave differently, the coercion
  414. * function's arguments will be different.
  415. */
  416. typedef enum CoercionForm
  417. {
  418. COERCE_EXPLICIT_CALL, /* display as a function call */
  419. COERCE_EXPLICIT_CAST, /* display as an explicit cast */
  420. COERCE_IMPLICIT_CAST /* implicit cast, so hide it */
  421. } CoercionForm;
  422. /*
  423. * FuncExpr - expression node for a function call
  424. */
  425. typedef struct FuncExpr
  426. {
  427. Expr xpr;
  428. Oid funcid; /* PG_PROC OID of the function */
  429. Oid funcresulttype; /* PG_TYPE OID of result value */
  430. bool funcretset; /* true if function returns set */
  431. bool funcvariadic; /* true if variadic arguments have been
  432. * combined into an array last argument */
  433. CoercionForm funcformat; /* how to display this function call */
  434. Oid funccollid; /* OID of collation of result */
  435. Oid inputcollid; /* OID of collation that function should use */
  436. List *args; /* arguments to the function */
  437. int location; /* token location, or -1 if unknown */
  438. } FuncExpr;
  439. /*
  440. * NamedArgExpr - a named argument of a function
  441. *
  442. * This node type can only appear in the args list of a FuncCall or FuncExpr
  443. * node. We support pure positional call notation (no named arguments),
  444. * named notation (all arguments are named), and mixed notation (unnamed
  445. * arguments followed by named ones).
  446. *
  447. * Parse analysis sets argnumber to the positional index of the argument,
  448. * but doesn't rearrange the argument list.
  449. *
  450. * The planner will convert argument lists to pure positional notation
  451. * during expression preprocessing, so execution never sees a NamedArgExpr.
  452. */
  453. typedef struct NamedArgExpr
  454. {
  455. Expr xpr;
  456. Expr *arg; /* the argument expression */
  457. char *name; /* the name */
  458. int argnumber; /* argument's number in positional notation */
  459. int location; /* argument name location, or -1 if unknown */
  460. } NamedArgExpr;
  461. /*
  462. * OpExpr - expression node for an operator invocation
  463. *
  464. * Semantically, this is essentially the same as a function call.
  465. *
  466. * Note that opfuncid is not necessarily filled in immediately on creation
  467. * of the node. The planner makes sure it is valid before passing the node
  468. * tree to the executor, but during parsing/planning opfuncid can be 0.
  469. */
  470. typedef struct OpExpr
  471. {
  472. Expr xpr;
  473. Oid opno; /* PG_OPERATOR OID of the operator */
  474. Oid opfuncid; /* PG_PROC OID of underlying function */
  475. Oid opresulttype; /* PG_TYPE OID of result value */
  476. bool opretset; /* true if operator returns set */
  477. Oid opcollid; /* OID of collation of result */
  478. Oid inputcollid; /* OID of collation that operator should use */
  479. List *args; /* arguments to the operator (1 or 2) */
  480. int location; /* token location, or -1 if unknown */
  481. } OpExpr;
  482. /*
  483. * DistinctExpr - expression node for "x IS DISTINCT FROM y"
  484. *
  485. * Except for the nodetag, this is represented identically to an OpExpr
  486. * referencing the "=" operator for x and y.
  487. * We use "=", not the more obvious "<>", because more datatypes have "="
  488. * than "<>". This means the executor must invert the operator result.
  489. * Note that the operator function won't be called at all if either input
  490. * is NULL, since then the result can be determined directly.
  491. */
  492. typedef OpExpr DistinctExpr;
  493. /*
  494. * NullIfExpr - a NULLIF expression
  495. *
  496. * Like DistinctExpr, this is represented the same as an OpExpr referencing
  497. * the "=" operator for x and y.
  498. */
  499. typedef OpExpr NullIfExpr;
  500. /*
  501. * ScalarArrayOpExpr - expression node for "scalar op ANY/ALL (array)"
  502. *
  503. * The operator must yield boolean. It is applied to the left operand
  504. * and each element of the righthand array, and the results are combined
  505. * with OR or AND (for ANY or ALL respectively). The node representation
  506. * is almost the same as for the underlying operator, but we need a useOr
  507. * flag to remember whether it's ANY or ALL, and we don't have to store
  508. * the result type (or the collation) because it must be boolean.
  509. */
  510. typedef struct ScalarArrayOpExpr
  511. {
  512. Expr xpr;
  513. Oid opno; /* PG_OPERATOR OID of the operator */
  514. Oid opfuncid; /* PG_PROC OID of underlying function */
  515. bool useOr; /* true for ANY, false for ALL */
  516. Oid inputcollid; /* OID of collation that operator should use */
  517. List *args; /* the scalar and array operands */
  518. int location; /* token location, or -1 if unknown */
  519. } ScalarArrayOpExpr;
  520. /*
  521. * BoolExpr - expression node for the basic Boolean operators AND, OR, NOT
  522. *
  523. * Notice the arguments are given as a List. For NOT, of course the list
  524. * must always have exactly one element. For AND and OR, there can be two
  525. * or more arguments.
  526. */
  527. typedef enum BoolExprType
  528. {
  529. AND_EXPR, OR_EXPR, NOT_EXPR
  530. } BoolExprType;
  531. typedef struct BoolExpr
  532. {
  533. Expr xpr;
  534. BoolExprType boolop;
  535. List *args; /* arguments to this expression */
  536. int location; /* token location, or -1 if unknown */
  537. } BoolExpr;
  538. /*
  539. * SubLink
  540. *
  541. * A SubLink represents a subselect appearing in an expression, and in some
  542. * cases also the combining operator(s) just above it. The subLinkType
  543. * indicates the form of the expression represented:
  544. * EXISTS_SUBLINK EXISTS(SELECT ...)
  545. * ALL_SUBLINK (lefthand) op ALL (SELECT ...)
  546. * ANY_SUBLINK (lefthand) op ANY (SELECT ...)
  547. * ROWCOMPARE_SUBLINK (lefthand) op (SELECT ...)
  548. * EXPR_SUBLINK (SELECT with single targetlist item ...)
  549. * MULTIEXPR_SUBLINK (SELECT with multiple targetlist items ...)
  550. * ARRAY_SUBLINK ARRAY(SELECT with single targetlist item ...)
  551. * CTE_SUBLINK WITH query (never actually part of an expression)
  552. * For ALL, ANY, and ROWCOMPARE, the lefthand is a list of expressions of the
  553. * same length as the subselect's targetlist. ROWCOMPARE will *always* have
  554. * a list with more than one entry; if the subselect has just one target
  555. * then the parser will create an EXPR_SUBLINK instead (and any operator
  556. * above the subselect will be represented separately).
  557. * ROWCOMPARE, EXPR, and MULTIEXPR require the subselect to deliver at most
  558. * one row (if it returns no rows, the result is NULL).
  559. * ALL, ANY, and ROWCOMPARE require the combining operators to deliver boolean
  560. * results. ALL and ANY combine the per-row results using AND and OR
  561. * semantics respectively.
  562. * ARRAY requires just one target column, and creates an array of the target
  563. * column's type using any number of rows resulting from the subselect.
  564. *
  565. * SubLink is classed as an Expr node, but it is not actually executable;
  566. * it must be replaced in the expression tree by a SubPlan node during
  567. * planning.
  568. *
  569. * NOTE: in the raw output of gram.y, testexpr contains just the raw form
  570. * of the lefthand expression (if any), and operName is the String name of
  571. * the combining operator. Also, subselect is a raw parsetree. During parse
  572. * analysis, the parser transforms testexpr into a complete boolean expression
  573. * that compares the lefthand value(s) to PARAM_SUBLINK nodes representing the
  574. * output columns of the subselect. And subselect is transformed to a Query.
  575. * This is the representation seen in saved rules and in the rewriter.
  576. *
  577. * In EXISTS, EXPR, MULTIEXPR, and ARRAY SubLinks, testexpr and operName
  578. * are unused and are always null.
  579. *
  580. * subLinkId is currently used only for MULTIEXPR SubLinks, and is zero in
  581. * other SubLinks. This number identifies different multiple-assignment
  582. * subqueries within an UPDATE statement's SET list. It is unique only
  583. * within a particular targetlist. The output column(s) of the MULTIEXPR
  584. * are referenced by PARAM_MULTIEXPR Params appearing elsewhere in the tlist.
  585. *
  586. * The CTE_SUBLINK case never occurs in actual SubLink nodes, but it is used
  587. * in SubPlans generated for WITH subqueries.
  588. */
  589. typedef enum SubLinkType
  590. {
  591. EXISTS_SUBLINK,
  592. ALL_SUBLINK,
  593. ANY_SUBLINK,
  594. ROWCOMPARE_SUBLINK,
  595. EXPR_SUBLINK,
  596. MULTIEXPR_SUBLINK,
  597. ARRAY_SUBLINK,
  598. CTE_SUBLINK /* for SubPlans only */
  599. } SubLinkType;
  600. typedef struct SubLink
  601. {
  602. Expr xpr;
  603. SubLinkType subLinkType; /* see above */
  604. int subLinkId; /* ID (1..n); 0 if not MULTIEXPR */
  605. Node *testexpr; /* outer-query test for ALL/ANY/ROWCOMPARE */
  606. List *operName; /* originally specified operator name */
  607. Node *subselect; /* subselect as Query* or raw parsetree */
  608. int location; /* token location, or -1 if unknown */
  609. } SubLink;
  610. /*
  611. * SubPlan - executable expression node for a subplan (sub-SELECT)
  612. *
  613. * The planner replaces SubLink nodes in expression trees with SubPlan
  614. * nodes after it has finished planning the subquery. SubPlan references
  615. * a sub-plantree stored in the subplans list of the toplevel PlannedStmt.
  616. * (We avoid a direct link to make it easier to copy expression trees
  617. * without causing multiple processing of the subplan.)
  618. *
  619. * In an ordinary subplan, testexpr points to an executable expression
  620. * (OpExpr, an AND/OR tree of OpExprs, or RowCompareExpr) for the combining
  621. * operator(s); the left-hand arguments are the original lefthand expressions,
  622. * and the right-hand arguments are PARAM_EXEC Param nodes representing the
  623. * outputs of the sub-select. (NOTE: runtime coercion functions may be
  624. * inserted as well.) This is just the same expression tree as testexpr in
  625. * the original SubLink node, but the PARAM_SUBLINK nodes are replaced by
  626. * suitably numbered PARAM_EXEC nodes.
  627. *
  628. * If the sub-select becomes an initplan rather than a subplan, the executable
  629. * expression is part of the outer plan's expression tree (and the SubPlan
  630. * node itself is not, but rather is found in the outer plan's initPlan
  631. * list). In this case testexpr is NULL to avoid duplication.
  632. *
  633. * The planner also derives lists of the values that need to be passed into
  634. * and out of the subplan. Input values are represented as a list "args" of
  635. * expressions to be evaluated in the outer-query context (currently these
  636. * args are always just Vars, but in principle they could be any expression).
  637. * The values are assigned to the global PARAM_EXEC params indexed by parParam
  638. * (the parParam and args lists must have the same ordering). setParam is a
  639. * list of the PARAM_EXEC params that are computed by the sub-select, if it
  640. * is an initplan; they are listed in order by sub-select output column
  641. * position. (parParam and setParam are integer Lists, not Bitmapsets,
  642. * because their ordering is significant.)
  643. *
  644. * Also, the planner computes startup and per-call costs for use of the
  645. * SubPlan. Note that these include the cost of the subquery proper,
  646. * evaluation of the testexpr if any, and any hashtable management overhead.
  647. */
  648. typedef struct SubPlan
  649. {
  650. Expr xpr;
  651. /* Fields copied from original SubLink: */
  652. SubLinkType subLinkType; /* see above */
  653. /* The combining operators, transformed to an executable expression: */
  654. Node *testexpr; /* OpExpr or RowCompareExpr expression tree */
  655. List *paramIds; /* IDs of Params embedded in the above */
  656. /* Identification of the Plan tree to use: */
  657. int plan_id; /* Index (from 1) in PlannedStmt.subplans */
  658. /* Identification of the SubPlan for EXPLAIN and debugging purposes: */
  659. char *plan_name; /* A name assigned during planning */
  660. /* Extra data useful for determining subplan's output type: */
  661. Oid firstColType; /* Type of first column of subplan result */
  662. int32 firstColTypmod; /* Typmod of first column of subplan result */
  663. Oid firstColCollation; /* Collation of first column of subplan
  664. * result */
  665. /* Information about execution strategy: */
  666. bool useHashTable; /* true to store subselect output in a hash
  667. * table (implies we are doing "IN") */
  668. bool unknownEqFalse; /* true if it's okay to return FALSE when the
  669. * spec result is UNKNOWN; this allows much
  670. * simpler handling of null values */
  671. bool parallel_safe; /* is the subplan parallel-safe? */
  672. /* Note: parallel_safe does not consider contents of testexpr or args */
  673. /* Information for passing params into and out of the subselect: */
  674. /* setParam and parParam are lists of integers (param IDs) */
  675. List *setParam; /* initplan subqueries have to set these
  676. * Params for parent plan */
  677. List *parParam; /* indices of input Params from parent plan */
  678. List *args; /* exprs to pass as parParam values */
  679. /* Estimated execution costs: */
  680. Cost startup_cost; /* one-time setup cost */
  681. Cost per_call_cost; /* cost for each subplan evaluation */
  682. } SubPlan;
  683. /*
  684. * AlternativeSubPlan - expression node for a choice among SubPlans
  685. *
  686. * The subplans are given as a List so that the node definition need not
  687. * change if there's ever more than two alternatives. For the moment,
  688. * though, there are always exactly two; and the first one is the fast-start
  689. * plan.
  690. */
  691. typedef struct AlternativeSubPlan
  692. {
  693. Expr xpr;
  694. List *subplans; /* SubPlan(s) with equivalent results */
  695. } AlternativeSubPlan;
  696. /* ----------------
  697. * FieldSelect
  698. *
  699. * FieldSelect represents the operation of extracting one field from a tuple
  700. * value. At runtime, the input expression is expected to yield a rowtype
  701. * Datum. The specified field number is extracted and returned as a Datum.
  702. * ----------------
  703. */
  704. typedef struct FieldSelect
  705. {
  706. Expr xpr;
  707. Expr *arg; /* input expression */
  708. AttrNumber fieldnum; /* attribute number of field to extract */
  709. Oid resulttype; /* type of the field (result type of this
  710. * node) */
  711. int32 resulttypmod; /* output typmod (usually -1) */
  712. Oid resultcollid; /* OID of collation of the field */
  713. } FieldSelect;
  714. /* ----------------
  715. * FieldStore
  716. *
  717. * FieldStore represents the operation of modifying one field in a tuple
  718. * value, yielding a new tuple value (the input is not touched!). Like
  719. * the assign case of SubscriptingRef, this is used to implement UPDATE of a
  720. * portion of a column.
  721. *
  722. * resulttype is always a named composite type (not a domain). To update
  723. * a composite domain value, apply CoerceToDomain to the FieldStore.
  724. *
  725. * A single FieldStore can actually represent updates of several different
  726. * fields. The parser only generates FieldStores with single-element lists,
  727. * but the planner will collapse multiple updates of the same base column
  728. * into one FieldStore.
  729. * ----------------
  730. */
  731. typedef struct FieldStore
  732. {
  733. Expr xpr;
  734. Expr *arg; /* input tuple value */
  735. List *newvals; /* new value(s) for field(s) */
  736. List *fieldnums; /* integer list of field attnums */
  737. Oid resulttype; /* type of result (same as type of arg) */
  738. /* Like RowExpr, we deliberately omit a typmod and collation here */
  739. } FieldStore;
  740. /* ----------------
  741. * RelabelType
  742. *
  743. * RelabelType represents a "dummy" type coercion between two binary-
  744. * compatible datatypes, such as reinterpreting the result of an OID
  745. * expression as an int4. It is a no-op at runtime; we only need it
  746. * to provide a place to store the correct type to be attributed to
  747. * the expression result during type resolution. (We can't get away
  748. * with just overwriting the type field of the input expression node,
  749. * so we need a separate node to show the coercion's result type.)
  750. * ----------------
  751. */
  752. typedef struct RelabelType
  753. {
  754. Expr xpr;
  755. Expr *arg; /* input expression */
  756. Oid resulttype; /* output type of coercion expression */
  757. int32 resulttypmod; /* output typmod (usually -1) */
  758. Oid resultcollid; /* OID of collation, or InvalidOid if none */
  759. CoercionForm relabelformat; /* how to display this node */
  760. int location; /* token location, or -1 if unknown */
  761. } RelabelType;
  762. /* ----------------
  763. * CoerceViaIO
  764. *
  765. * CoerceViaIO represents a type coercion between two types whose textual
  766. * representations are compatible, implemented by invoking the source type's
  767. * typoutput function then the destination type's typinput function.
  768. * ----------------
  769. */
  770. typedef struct CoerceViaIO
  771. {
  772. Expr xpr;
  773. Expr *arg; /* input expression */
  774. Oid resulttype; /* output type of coercion */
  775. /* output typmod is not stored, but is presumed -1 */
  776. Oid resultcollid; /* OID of collation, or InvalidOid if none */
  777. CoercionForm coerceformat; /* how to display this node */
  778. int location; /* token location, or -1 if unknown */
  779. } CoerceViaIO;
  780. /* ----------------
  781. * ArrayCoerceExpr
  782. *
  783. * ArrayCoerceExpr represents a type coercion from one array type to another,
  784. * which is implemented by applying the per-element coercion expression
  785. * "elemexpr" to each element of the source array. Within elemexpr, the
  786. * source element is represented by a CaseTestExpr node. Note that even if
  787. * elemexpr is a no-op (that is, just CaseTestExpr + RelabelType), the
  788. * coercion still requires some effort: we have to fix the element type OID
  789. * stored in the array header.
  790. * ----------------
  791. */
  792. typedef struct ArrayCoerceExpr
  793. {
  794. Expr xpr;
  795. Expr *arg; /* input expression (yields an array) */
  796. Expr *elemexpr; /* expression representing per-element work */
  797. Oid resulttype; /* output type of coercion (an array type) */
  798. int32 resulttypmod; /* output typmod (also element typmod) */
  799. Oid resultcollid; /* OID of collation, or InvalidOid if none */
  800. CoercionForm coerceformat; /* how to display this node */
  801. int location; /* token location, or -1 if unknown */
  802. } ArrayCoerceExpr;
  803. /* ----------------
  804. * ConvertRowtypeExpr
  805. *
  806. * ConvertRowtypeExpr represents a type coercion from one composite type
  807. * to another, where the source type is guaranteed to contain all the columns
  808. * needed for the destination type plus possibly others; the columns need not
  809. * be in the same positions, but are matched up by name. This is primarily
  810. * used to convert a whole-row value of an inheritance child table into a
  811. * valid whole-row value of its parent table's rowtype. Both resulttype
  812. * and the exposed type of "arg" must be named composite types (not domains).
  813. * ----------------
  814. */
  815. typedef struct ConvertRowtypeExpr
  816. {
  817. Expr xpr;
  818. Expr *arg; /* input expression */
  819. Oid resulttype; /* output type (always a composite type) */
  820. /* Like RowExpr, we deliberately omit a typmod and collation here */
  821. CoercionForm convertformat; /* how to display this node */
  822. int location; /* token location, or -1 if unknown */
  823. } ConvertRowtypeExpr;
  824. /*----------
  825. * CollateExpr - COLLATE
  826. *
  827. * The planner replaces CollateExpr with RelabelType during expression
  828. * preprocessing, so execution never sees a CollateExpr.
  829. *----------
  830. */
  831. typedef struct CollateExpr
  832. {
  833. Expr xpr;
  834. Expr *arg; /* input expression */
  835. Oid collOid; /* collation's OID */
  836. int location; /* token location, or -1 if unknown */
  837. } CollateExpr;
  838. /*----------
  839. * CaseExpr - a CASE expression
  840. *
  841. * We support two distinct forms of CASE expression:
  842. * CASE WHEN boolexpr THEN expr [ WHEN boolexpr THEN expr ... ]
  843. * CASE testexpr WHEN compexpr THEN expr [ WHEN compexpr THEN expr ... ]
  844. * These are distinguishable by the "arg" field being NULL in the first case
  845. * and the testexpr in the second case.
  846. *
  847. * In the raw grammar output for the second form, the condition expressions
  848. * of the WHEN clauses are just the comparison values. Parse analysis
  849. * converts these to valid boolean expressions of the form
  850. * CaseTestExpr '=' compexpr
  851. * where the CaseTestExpr node is a placeholder that emits the correct
  852. * value at runtime. This structure is used so that the testexpr need be
  853. * evaluated only once. Note that after parse analysis, the condition
  854. * expressions always yield boolean.
  855. *
  856. * Note: we can test whether a CaseExpr has been through parse analysis
  857. * yet by checking whether casetype is InvalidOid or not.
  858. *----------
  859. */
  860. typedef struct CaseExpr
  861. {
  862. Expr xpr;
  863. Oid casetype; /* type of expression result */
  864. Oid casecollid; /* OID of collation, or InvalidOid if none */
  865. Expr *arg; /* implicit equality comparison argument */
  866. List *args; /* the arguments (list of WHEN clauses) */
  867. Expr *defresult; /* the default result (ELSE clause) */
  868. int location; /* token location, or -1 if unknown */
  869. } CaseExpr;
  870. /*
  871. * CaseWhen - one arm of a CASE expression
  872. */
  873. typedef struct CaseWhen
  874. {
  875. Expr xpr;
  876. Expr *expr; /* condition expression */
  877. Expr *result; /* substitution result */
  878. int location; /* token location, or -1 if unknown */
  879. } CaseWhen;
  880. /*
  881. * Placeholder node for the test value to be processed by a CASE expression.
  882. * This is effectively like a Param, but can be implemented more simply
  883. * since we need only one replacement value at a time.
  884. *
  885. * We also abuse this node type for some other purposes, including:
  886. * * Placeholder for the current array element value in ArrayCoerceExpr;
  887. * see build_coercion_expression().
  888. * * Nested FieldStore/SubscriptingRef assignment expressions in INSERT/UPDATE;
  889. * see transformAssignmentIndirection().
  890. *
  891. * The uses in CaseExpr and ArrayCoerceExpr are safe only to the extent that
  892. * there is not any other CaseExpr or ArrayCoerceExpr between the value source
  893. * node and its child CaseTestExpr(s). This is true in the parse analysis
  894. * output, but the planner's function-inlining logic has to be careful not to
  895. * break it.
  896. *
  897. * The nested-assignment-expression case is safe because the only node types
  898. * that can be above such CaseTestExprs are FieldStore and SubscriptingRef.
  899. */
  900. typedef struct CaseTestExpr
  901. {
  902. Expr xpr;
  903. Oid typeId; /* type for substituted value */
  904. int32 typeMod; /* typemod for substituted value */
  905. Oid collation; /* collation for the substituted value */
  906. } CaseTestExpr;
  907. /*
  908. * ArrayExpr - an ARRAY[] expression
  909. *
  910. * Note: if multidims is false, the constituent expressions all yield the
  911. * scalar type identified by element_typeid. If multidims is true, the
  912. * constituent expressions all yield arrays of element_typeid (ie, the same
  913. * type as array_typeid); at runtime we must check for compatible subscripts.
  914. */
  915. typedef struct ArrayExpr
  916. {
  917. Expr xpr;
  918. Oid array_typeid; /* type of expression result */
  919. Oid array_collid; /* OID of collation, or InvalidOid if none */
  920. Oid element_typeid; /* common type of array elements */
  921. List *elements; /* the array elements or sub-arrays */
  922. bool multidims; /* true if elements are sub-arrays */
  923. int location; /* token location, or -1 if unknown */
  924. } ArrayExpr;
  925. /*
  926. * RowExpr - a ROW() expression
  927. *
  928. * Note: the list of fields must have a one-for-one correspondence with
  929. * physical fields of the associated rowtype, although it is okay for it
  930. * to be shorter than the rowtype. That is, the N'th list element must
  931. * match up with the N'th physical field. When the N'th physical field
  932. * is a dropped column (attisdropped) then the N'th list element can just
  933. * be a NULL constant. (This case can only occur for named composite types,
  934. * not RECORD types, since those are built from the RowExpr itself rather
  935. * than vice versa.) It is important not to assume that length(args) is
  936. * the same as the number of columns logically present in the rowtype.
  937. *
  938. * colnames provides field names in cases where the names can't easily be
  939. * obtained otherwise. Names *must* be provided if row_typeid is RECORDOID.
  940. * If row_typeid identifies a known composite type, colnames can be NIL to
  941. * indicate the type's cataloged field names apply. Note that colnames can
  942. * be non-NIL even for a composite type, and typically is when the RowExpr
  943. * was created by expanding a whole-row Var. This is so that we can retain
  944. * the column alias names of the RTE that the Var referenced (which would
  945. * otherwise be very difficult to extract from the parsetree). Like the
  946. * args list, colnames is one-for-one with physical fields of the rowtype.
  947. */
  948. typedef struct RowExpr
  949. {
  950. Expr xpr;
  951. List *args; /* the fields */
  952. Oid row_typeid; /* RECORDOID or a composite type's ID */
  953. /*
  954. * row_typeid cannot be a domain over composite, only plain composite. To
  955. * create a composite domain value, apply CoerceToDomain to the RowExpr.
  956. *
  957. * Note: we deliberately do NOT store a typmod. Although a typmod will be
  958. * associated with specific RECORD types at runtime, it will differ for
  959. * different backends, and so cannot safely be stored in stored
  960. * parsetrees. We must assume typmod -1 for a RowExpr node.
  961. *
  962. * We don't need to store a collation either. The result type is
  963. * necessarily composite, and composite types never have a collation.
  964. */
  965. CoercionForm row_format; /* how to display this node */
  966. List *colnames; /* list of String, or NIL */
  967. int location; /* token location, or -1 if unknown */
  968. } RowExpr;
  969. /*
  970. * RowCompareExpr - row-wise comparison, such as (a, b) <= (1, 2)
  971. *
  972. * We support row comparison for any operator that can be determined to
  973. * act like =, <>, <, <=, >, or >= (we determine this by looking for the
  974. * operator in btree opfamilies). Note that the same operator name might
  975. * map to a different operator for each pair of row elements, since the
  976. * element datatypes can vary.
  977. *
  978. * A RowCompareExpr node is only generated for the < <= > >= cases;
  979. * the = and <> cases are translated to simple AND or OR combinations
  980. * of the pairwise comparisons. However, we include = and <> in the
  981. * RowCompareType enum for the convenience of parser logic.
  982. */
  983. typedef enum RowCompareType
  984. {
  985. /* Values of this enum are chosen to match btree strategy numbers */
  986. ROWCOMPARE_LT = 1, /* BTLessStrategyNumber */
  987. ROWCOMPARE_LE = 2, /* BTLessEqualStrategyNumber */
  988. ROWCOMPARE_EQ = 3, /* BTEqualStrategyNumber */
  989. ROWCOMPARE_GE = 4, /* BTGreaterEqualStrategyNumber */
  990. ROWCOMPARE_GT = 5, /* BTGreaterStrategyNumber */
  991. ROWCOMPARE_NE = 6 /* no such btree strategy */
  992. } RowCompareType;
  993. typedef struct RowCompareExpr
  994. {
  995. Expr xpr;
  996. RowCompareType rctype; /* LT LE GE or GT, never EQ or NE */
  997. List *opnos; /* OID list of pairwise comparison ops */
  998. List *opfamilies; /* OID list of containing operator families */
  999. List *inputcollids; /* OID list of collations for comparisons */
  1000. List *largs; /* the left-hand input arguments */
  1001. List *rargs; /* the right-hand input arguments */
  1002. } RowCompareExpr;
  1003. /*
  1004. * CoalesceExpr - a COALESCE expression
  1005. */
  1006. typedef struct CoalesceExpr
  1007. {
  1008. Expr xpr;
  1009. Oid coalescetype; /* type of expression result */
  1010. Oid coalescecollid; /* OID of collation, or InvalidOid if none */
  1011. List *args; /* the arguments */
  1012. int location; /* token location, or -1 if unknown */
  1013. } CoalesceExpr;
  1014. /*
  1015. * MinMaxExpr - a GREATEST or LEAST function
  1016. */
  1017. typedef enum MinMaxOp
  1018. {
  1019. IS_GREATEST,
  1020. IS_LEAST
  1021. } MinMaxOp;
  1022. typedef struct MinMaxExpr
  1023. {
  1024. Expr xpr;
  1025. Oid minmaxtype; /* common type of arguments and result */
  1026. Oid minmaxcollid; /* OID of collation of result */
  1027. Oid inputcollid; /* OID of collation that function should use */
  1028. MinMaxOp op; /* function to execute */
  1029. List *args; /* the arguments */
  1030. int location; /* token location, or -1 if unknown */
  1031. } MinMaxExpr;
  1032. /*
  1033. * SQLValueFunction - parameterless functions with special grammar productions
  1034. *
  1035. * The SQL standard categorizes some of these as <datetime value function>
  1036. * and others as <general value specification>. We call 'em SQLValueFunctions
  1037. * for lack of a better term. We store type and typmod of the result so that
  1038. * some code doesn't need to know each function individually, and because
  1039. * we would need to store typmod anyway for some of the datetime functions.
  1040. * Note that currently, all variants return non-collating datatypes, so we do
  1041. * not need a collation field; also, all these functions are stable.
  1042. */
  1043. typedef enum SQLValueFunctionOp
  1044. {
  1045. SVFOP_CURRENT_DATE,
  1046. SVFOP_CURRENT_TIME,
  1047. SVFOP_CURRENT_TIME_N,
  1048. SVFOP_CURRENT_TIMESTAMP,
  1049. SVFOP_CURRENT_TIMESTAMP_N,
  1050. SVFOP_LOCALTIME,
  1051. SVFOP_LOCALTIME_N,
  1052. SVFOP_LOCALTIMESTAMP,
  1053. SVFOP_LOCALTIMESTAMP_N,
  1054. SVFOP_CURRENT_ROLE,
  1055. SVFOP_CURRENT_USER,
  1056. SVFOP_USER,
  1057. SVFOP_SESSION_USER,
  1058. SVFOP_CURRENT_CATALOG,
  1059. SVFOP_CURRENT_SCHEMA
  1060. } SQLValueFunctionOp;
  1061. typedef struct SQLValueFunction
  1062. {
  1063. Expr xpr;
  1064. SQLValueFunctionOp op; /* which function this is */
  1065. Oid type; /* result type/typmod */
  1066. int32 typmod;
  1067. int location; /* token location, or -1 if unknown */
  1068. } SQLValueFunction;
  1069. /*
  1070. * XmlExpr - various SQL/XML functions requiring special grammar productions
  1071. *
  1072. * 'name' carries the "NAME foo" argument (already XML-escaped).
  1073. * 'named_args' and 'arg_names' represent an xml_attribute list.
  1074. * 'args' carries all other arguments.
  1075. *
  1076. * Note: result type/typmod/collation are not stored, but can be deduced
  1077. * from the XmlExprOp. The type/typmod fields are just used for display
  1078. * purposes, and are NOT necessarily the true result type of the node.
  1079. */
  1080. typedef enum XmlExprOp
  1081. {
  1082. IS_XMLCONCAT, /* XMLCONCAT(args) */
  1083. IS_XMLELEMENT, /* XMLELEMENT(name, xml_attributes, args) */
  1084. IS_XMLFOREST, /* XMLFOREST(xml_attributes) */
  1085. IS_XMLPARSE, /* XMLPARSE(text, is_doc, preserve_ws) */
  1086. IS_XMLPI, /* XMLPI(name [, args]) */
  1087. IS_XMLROOT, /* XMLROOT(xml, version, standalone) */
  1088. IS_XMLSERIALIZE, /* XMLSERIALIZE(is_document, xmlval) */
  1089. IS_DOCUMENT /* xmlval IS DOCUMENT */
  1090. } XmlExprOp;
  1091. typedef enum
  1092. {
  1093. XMLOPTION_DOCUMENT,
  1094. XMLOPTION_CONTENT
  1095. } XmlOptionType;
  1096. typedef struct XmlExpr
  1097. {
  1098. Expr xpr;
  1099. XmlExprOp op; /* xml function ID */
  1100. char *name; /* name in xml(NAME foo ...) syntaxes */
  1101. List *named_args; /* non-XML expressions for xml_attributes */
  1102. List *arg_names; /* parallel list of Value strings */
  1103. List *args; /* list of expressions */
  1104. XmlOptionType xmloption; /* DOCUMENT or CONTENT */
  1105. Oid type; /* target type/typmod for XMLSERIALIZE */
  1106. int32 typmod;
  1107. int location; /* token location, or -1 if unknown */
  1108. } XmlExpr;
  1109. /* ----------------
  1110. * NullTest
  1111. *
  1112. * NullTest represents the operation of testing a value for NULLness.
  1113. * The appropriate test is performed and returned as a boolean Datum.
  1114. *
  1115. * When argisrow is false, this simply represents a test for the null value.
  1116. *
  1117. * When argisrow is true, the input expression must yield a rowtype, and
  1118. * the node implements "row IS [NOT] NULL" per the SQL standard. This
  1119. * includes checking individual fields for NULLness when the row datum
  1120. * itself isn't NULL.
  1121. *
  1122. * NOTE: the combination of a rowtype input and argisrow==false does NOT
  1123. * correspond to the SQL notation "row IS [NOT] NULL"; instead, this case
  1124. * represents the SQL notation "row IS [NOT] DISTINCT FROM NULL".
  1125. * ----------------
  1126. */
  1127. typedef enum NullTestType
  1128. {
  1129. IS_NULL, IS_NOT_NULL
  1130. } NullTestType;
  1131. typedef struct NullTest
  1132. {
  1133. Expr xpr;
  1134. Expr *arg; /* input expression */
  1135. NullTestType nulltesttype; /* IS NULL, IS NOT NULL */
  1136. bool argisrow; /* T to perform field-by-field null checks */
  1137. int location; /* token location, or -1 if unknown */
  1138. } NullTest;
  1139. /*
  1140. * BooleanTest
  1141. *
  1142. * BooleanTest represents the operation of determining whether a boolean
  1143. * is TRUE, FALSE, or UNKNOWN (ie, NULL). All six meaningful combinations
  1144. * are supported. Note that a NULL input does *not* cause a NULL result.
  1145. * The appropriate test is performed and returned as a boolean Datum.
  1146. */
  1147. typedef enum BoolTestType
  1148. {
  1149. IS_TRUE, IS_NOT_TRUE, IS_FALSE, IS_NOT_FALSE, IS_UNKNOWN, IS_NOT_UNKNOWN
  1150. } BoolTestType;
  1151. typedef struct BooleanTest
  1152. {
  1153. Expr xpr;
  1154. Expr *arg; /* input expression */
  1155. BoolTestType booltesttype; /* test type */
  1156. int location; /* token location, or -1 if unknown */
  1157. } BooleanTest;
  1158. /*
  1159. * CoerceToDomain
  1160. *
  1161. * CoerceToDomain represents the operation of coercing a value to a domain
  1162. * type. At runtime (and not before) the precise set of constraints to be
  1163. * checked will be determined. If the value passes, it is returned as the
  1164. * result; if not, an error is raised. Note that this is equivalent to
  1165. * RelabelType in the scenario where no constraints are applied.
  1166. */
  1167. typedef struct CoerceToDomain
  1168. {
  1169. Expr xpr;
  1170. Expr *arg; /* input expression */
  1171. Oid resulttype; /* domain type ID (result type) */
  1172. int32 resulttypmod; /* output typmod (currently always -1) */
  1173. Oid resultcollid; /* OID of collation, or InvalidOid if none */
  1174. CoercionForm coercionformat; /* how to display this node */
  1175. int location; /* token location, or -1 if unknown */
  1176. } CoerceToDomain;
  1177. /*
  1178. * Placeholder node for the value to be processed by a domain's check
  1179. * constraint. This is effectively like a Param, but can be implemented more
  1180. * simply since we need only one replacement value at a time.
  1181. *
  1182. * Note: the typeId/typeMod/collation will be set from the domain's base type,
  1183. * not the domain itself. This is because we shouldn't consider the value
  1184. * to be a member of the domain if we haven't yet checked its constraints.
  1185. */
  1186. typedef struct CoerceToDomainValue
  1187. {
  1188. Expr xpr;
  1189. Oid typeId; /* type for substituted value */
  1190. int32 typeMod; /* typemod for substituted value */
  1191. Oid collation; /* collation for the substituted value */
  1192. int location; /* token location, or -1 if unknown */
  1193. } CoerceToDomainValue;
  1194. /*
  1195. * Placeholder node for a DEFAULT marker in an INSERT or UPDATE command.
  1196. *
  1197. * This is not an executable expression: it must be replaced by the actual
  1198. * column default expression during rewriting. But it is convenient to
  1199. * treat it as an expression node during parsing and rewriting.
  1200. */
  1201. typedef struct SetToDefault
  1202. {
  1203. Expr xpr;
  1204. Oid typeId; /* type for substituted value */
  1205. int32 typeMod; /* typemod for substituted value */
  1206. Oid collation; /* collation for the substituted value */
  1207. int location; /* token location, or -1 if unknown */
  1208. } SetToDefault;
  1209. /*
  1210. * Node representing [WHERE] CURRENT OF cursor_name
  1211. *
  1212. * CURRENT OF is a bit like a Var, in that it carries the rangetable index
  1213. * of the target relation being constrained; this aids placing the expression
  1214. * correctly during planning. We can assume however that its "levelsup" is
  1215. * always zero, due to the syntactic constraints on where it can appear.
  1216. *
  1217. * The referenced cursor can be represented either as a hardwired string
  1218. * or as a reference to a run-time parameter of type REFCURSOR. The latter
  1219. * case is for the convenience of plpgsql.
  1220. */
  1221. typedef struct CurrentOfExpr
  1222. {
  1223. Expr xpr;
  1224. Index cvarno; /* RT index of target relation */
  1225. char *cursor_name; /* name of referenced cursor, or NULL */
  1226. int cursor_param; /* refcursor parameter number, or 0 */
  1227. } CurrentOfExpr;
  1228. /*
  1229. * NextValueExpr - get next value from sequence
  1230. *
  1231. * This has the same effect as calling the nextval() function, but it does not
  1232. * check permissions on the sequence. This is used for identity columns,
  1233. * where the sequence is an implicit dependency without its own permissions.
  1234. */
  1235. typedef struct NextValueExpr
  1236. {
  1237. Expr xpr;
  1238. Oid seqid;
  1239. Oid typeId;
  1240. } NextValueExpr;
  1241. /*
  1242. * InferenceElem - an element of a unique index inference specification
  1243. *
  1244. * This mostly matches the structure of IndexElems, but having a dedicated
  1245. * primnode allows for a clean separation between the use of index parameters
  1246. * by utility commands, and this node.
  1247. */
  1248. typedef struct InferenceElem
  1249. {
  1250. Expr xpr;
  1251. Node *expr; /* expression to infer from, or NULL */
  1252. Oid infercollid; /* OID of collation, or InvalidOid */
  1253. Oid inferopclass; /* OID of att opclass, or InvalidOid */
  1254. } InferenceElem;
  1255. /*--------------------
  1256. * TargetEntry -
  1257. * a target entry (used in query target lists)
  1258. *
  1259. * Strictly speaking, a TargetEntry isn't an expression node (since it can't
  1260. * be evaluated by ExecEvalExpr). But we treat it as one anyway, since in
  1261. * very many places it's convenient to process a whole query targetlist as a
  1262. * single expression tree.
  1263. *
  1264. * In a SELECT's targetlist, resno should always be equal to the item's
  1265. * ordinal position (counting from 1). However, in an INSERT or UPDATE
  1266. * targetlist, resno represents the attribute number of the destination
  1267. * column for the item; so there may be missing or out-of-order resnos.
  1268. * It is even legal to have duplicated resnos; consider
  1269. * UPDATE table SET arraycol[1] = ..., arraycol[2] = ..., ...
  1270. * The two meanings come together in the executor, because the planner
  1271. * transforms INSERT/UPDATE tlists into a normalized form with exactly
  1272. * one entry for each column of the destination table. Before that's
  1273. * happened, however, it is risky to assume that resno == position.
  1274. * Generally get_tle_by_resno() should be used rather than list_nth()
  1275. * to fetch tlist entries by resno, and only in SELECT should you assume
  1276. * that resno is a unique identifier.
  1277. *
  1278. * resname is required to represent the correct column name in non-resjunk
  1279. * entries of top-level SELECT targetlists, since it will be used as the
  1280. * column title sent to the frontend. In most other contexts it is only
  1281. * a debugging aid, and may be wrong or even NULL. (In particular, it may
  1282. * be wrong in a tlist from a stored rule, if the referenced column has been
  1283. * renamed by ALTER TABLE since the rule was made. Also, the planner tends
  1284. * to store NULL rather than look up a valid name for tlist entries in
  1285. * non-toplevel plan nodes.) In resjunk entries, resname should be either
  1286. * a specific system-generated name (such as "ctid") or NULL; anything else
  1287. * risks confusing ExecGetJunkAttribute!
  1288. *
  1289. * ressortgroupref is used in the representation of ORDER BY, GROUP BY, and
  1290. * DISTINCT items. Targetlist entries with ressortgroupref=0 are not
  1291. * sort/group items. If ressortgroupref>0, then this item is an ORDER BY,
  1292. * GROUP BY, and/or DISTINCT target value. No two entries in a targetlist
  1293. * may have the same nonzero ressortgroupref --- but there is no particular
  1294. * meaning to the nonzero values, except as tags. (For example, one must
  1295. * not assume that lower ressortgroupref means a more significant sort key.)
  1296. * The order of the associated SortGroupClause lists determine the semantics.
  1297. *
  1298. * resorigtbl/resorigcol identify the source of the column, if it is a
  1299. * simple reference to a column of a base table (or view). If it is not
  1300. * a simple reference, these fields are zeroes.
  1301. *
  1302. * If resjunk is true then the column is a working column (such as a sort key)
  1303. * that should be removed from the final output of the query. Resjunk columns
  1304. * must have resnos that cannot duplicate any regular column's resno. Also
  1305. * note that there are places that assume resjunk columns come after non-junk
  1306. * columns.
  1307. *--------------------
  1308. */
  1309. typedef struct TargetEntry
  1310. {
  1311. Expr xpr;
  1312. Expr *expr; /* expression to evaluate */
  1313. AttrNumber resno; /* attribute number (see notes above) */
  1314. char *resname; /* name of the column (could be NULL) */
  1315. Index ressortgroupref; /* nonzero if referenced by a sort/group
  1316. * clause */
  1317. Oid resorigtbl; /* OID of column's source table */
  1318. AttrNumber resorigcol; /* column's number in source table */
  1319. bool resjunk; /* set to true to eliminate the attribute from
  1320. * final target list */
  1321. } TargetEntry;
  1322. /* ----------------------------------------------------------------
  1323. * node types for join trees
  1324. *
  1325. * The leaves of a join tree structure are RangeTblRef nodes. Above
  1326. * these, JoinExpr nodes can appear to denote a specific kind of join
  1327. * or qualified join. Also, FromExpr nodes can appear to denote an
  1328. * ordinary cross-product join ("FROM foo, bar, baz WHERE ...").
  1329. * FromExpr is like a JoinExpr of jointype JOIN_INNER, except that it
  1330. * may have any number of child nodes, not just two.
  1331. *
  1332. * NOTE: the top level of a Query's jointree is always a FromExpr.
  1333. * Even if the jointree contains no rels, there will be a FromExpr.
  1334. *
  1335. * NOTE: the qualification expressions present in JoinExpr nodes are
  1336. * *in addition to* the query's main WHERE clause, which appears as the
  1337. * qual of the top-level FromExpr. The reason for associating quals with
  1338. * specific nodes in the jointree is that the position of a qual is critical
  1339. * when outer joins are present. (If we enforce a qual too soon or too late,
  1340. * that may cause the outer join to produce the wrong set of NULL-extended
  1341. * rows.) If all joins are inner joins then all the qual positions are
  1342. * semantically interchangeable.
  1343. *
  1344. * NOTE: in the raw output of gram.y, a join tree contains RangeVar,
  1345. * RangeSubselect, and RangeFunction nodes, which are all replaced by
  1346. * RangeTblRef nodes during the parse analysis phase. Also, the top-level
  1347. * FromExpr is added during parse analysis; the grammar regards FROM and
  1348. * WHERE as separate.
  1349. * ----------------------------------------------------------------
  1350. */
  1351. /*
  1352. * RangeTblRef - reference to an entry in the query's rangetable
  1353. *
  1354. * We could use direct pointers to the RT entries and skip having these
  1355. * nodes, but multiple pointers to the same node in a querytree cause
  1356. * lots of headaches, so it seems better to store an index into the RT.
  1357. */
  1358. typedef struct RangeTblRef
  1359. {
  1360. NodeTag type;
  1361. int rtindex;
  1362. } RangeTblRef;
  1363. /*----------
  1364. * JoinExpr - for SQL JOIN expressions
  1365. *
  1366. * isNatural, usingClause, and quals are interdependent. The user can write
  1367. * only one of NATURAL, USING(), or ON() (this is enforced by the grammar).
  1368. * If he writes NATURAL then parse analysis generates the equivalent USING()
  1369. * list, and from that fills in "quals" with the right equality comparisons.
  1370. * If he writes USING() then "quals" is filled with equality comparisons.
  1371. * If he writes ON() then only "quals" is set. Note that NATURAL/USING
  1372. * are not equivalent to ON() since they also affect the output column list.
  1373. *
  1374. * alias is an Alias node representing the AS alias-clause attached to the
  1375. * join expression, or NULL if no clause. NB: presence or absence of the
  1376. * alias has a critical impact on semantics, because a join with an alias
  1377. * restricts visibility of the tables/columns inside it.
  1378. *
  1379. * During parse analysis, an RTE is created for the Join, and its index
  1380. * is filled into rtindex. This RTE is present mainly so that Vars can
  1381. * be created that refer to the outputs of the join. The planner sometimes
  1382. * generates JoinExprs internally; these can have rtindex = 0 if there are
  1383. * no join alias variables referencing such joins.
  1384. *----------
  1385. */
  1386. typedef struct JoinExpr
  1387. {
  1388. NodeTag type;
  1389. JoinType jointype; /* type of join */
  1390. bool isNatural; /* Natural join? Will need to shape table */
  1391. Node *larg; /* left subtree */
  1392. Node *rarg; /* right subtree */
  1393. List *usingClause; /* USING clause, if any (list of String) */
  1394. Node *quals; /* qualifiers on join, if any */
  1395. Alias *alias; /* user-written alias clause, if any */
  1396. int rtindex; /* RT index assigned for join, or 0 */
  1397. } JoinExpr;
  1398. /*----------
  1399. * FromExpr - represents a FROM ... WHERE ... construct
  1400. *
  1401. * This is both more flexible than a JoinExpr (it can have any number of
  1402. * children, including zero) and less so --- we don't need to deal with
  1403. * aliases and so on. The output column set is implicitly just the union
  1404. * of the outputs of the children.
  1405. *----------
  1406. */
  1407. typedef struct FromExpr
  1408. {
  1409. NodeTag type;
  1410. List *fromlist; /* List of join subtrees */
  1411. Node *quals; /* qualifiers on join, if any */
  1412. } FromExpr;
  1413. /*----------
  1414. * OnConflictExpr - represents an ON CONFLICT DO ... expression
  1415. *
  1416. * The optimizer requires a list of inference elements, and optionally a WHERE
  1417. * clause to infer a unique index. The unique index (or, occasionally,
  1418. * indexes) inferred are used to arbitrate whether or not the alternative ON
  1419. * CONFLICT path is taken.
  1420. *----------
  1421. */
  1422. typedef struct OnConflictExpr
  1423. {
  1424. NodeTag type;
  1425. OnConflictAction action; /* DO NOTHING or UPDATE? */
  1426. /* Arbiter */
  1427. List *arbiterElems; /* unique index arbiter list (of
  1428. * InferenceElem's) */
  1429. Node *arbiterWhere; /* unique index arbiter WHERE clause */
  1430. Oid constraint; /* pg_constraint OID for arbiter */
  1431. /* ON CONFLICT UPDATE */
  1432. List *onConflictSet; /* List of ON CONFLICT SET TargetEntrys */
  1433. Node *onConflictWhere; /* qualifiers to restrict UPDATE to */
  1434. int exclRelIndex; /* RT index of 'excluded' relation */
  1435. List *exclRelTlist; /* tlist of the EXCLUDED pseudo relation */
  1436. } OnConflictExpr;
  1437. #endif /* PRIMNODES_H */
上海开阖软件有限公司 沪ICP备12045867号-1