primnodes.h 64 KB

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