]> granicus.if.org Git - postgresql/blob - src/include/nodes/primnodes.h
Replace TupleTableSlot convention for whole-row variables and function
[postgresql] / src / include / nodes / primnodes.h
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-2003, PostgreSQL Global Development Group
11  * Portions Copyright (c) 1994, Regents of the University of California
12  *
13  * $PostgreSQL: pgsql/src/include/nodes/primnodes.h,v 1.97 2004/04/01 21:28:46 tgl Exp $
14  *
15  *-------------------------------------------------------------------------
16  */
17 #ifndef PRIMNODES_H
18 #define PRIMNODES_H
19
20 #include "access/attnum.h"
21 #include "nodes/pg_list.h"
22 #include "nodes/value.h"
23
24
25 /* ----------------------------------------------------------------
26  *                                              node definitions
27  * ----------------------------------------------------------------
28  */
29
30 /*--------------------
31  * Resdom (Result Domain)
32  *
33  * Notes:
34  *
35  * In a SELECT's targetlist, resno should always be equal to the item's
36  * ordinal position (counting from 1).  However, in an INSERT or UPDATE
37  * targetlist, resno represents the attribute number of the destination
38  * column for the item; so there may be missing or out-of-order resnos.
39  * In an UPDATE, it is even legal to have duplicated resnos; consider
40  *              UPDATE table SET arraycol[1] = ..., arraycol[2] = ..., ...
41  * The two meanings come together in the executor, because the planner
42  * transforms INSERT/UPDATE tlists into a normalized form with exactly
43  * one entry for each column of the destination table.  Before that's
44  * happened, however, it is risky to assume that resno == position.
45  * Generally get_tle_by_resno() should be used rather than nth() to fetch
46  * tlist entries by resno.
47  *
48  * resname is required to represent the correct column name in non-resjunk
49  * entries of top-level SELECT targetlists, since it will be used as the
50  * column title sent to the frontend.  In most other contexts it is only
51  * a debugging aid, and may be wrong or even NULL.  (In particular, it may
52  * be wrong in a tlist from a stored rule, if the referenced column has been
53  * renamed by ALTER TABLE since the rule was made.  Also, the planner tends
54  * to store NULL rather than look up a valid name for tlist entries in
55  * non-toplevel plan nodes.)  In resjunk entries, resname should be either
56  * a specific system-generated name (such as "ctid") or NULL; anything else
57  * risks confusing ExecGetJunkAttribute!
58  *
59  * ressortgroupref is used in the representation of ORDER BY and
60  * GROUP BY items.      Targetlist entries with ressortgroupref=0 are not
61  * sort/group items.  If ressortgroupref>0, then this item is an ORDER BY or
62  * GROUP BY value.      No two entries in a targetlist may have the same nonzero
63  * ressortgroupref --- but there is no particular meaning to the nonzero
64  * values, except as tags.      (For example, one must not assume that lower
65  * ressortgroupref means a more significant sort key.)  The order of the
66  * associated SortClause or GroupClause lists determine the semantics.
67  *
68  * resorigtbl/resorigcol identify the source of the column, if it is a
69  * simple reference to a column of a base table (or view).      If it is not
70  * a simple reference, these fields are zeroes.
71  *
72  * If resjunk is true then the column is a working column (such as a sort key)
73  * that should be removed from the final output of the query.  Resjunk columns
74  * must have resnos that cannot duplicate any regular column's resno.  Also
75  * note that there are places that assume resjunk columns come after non-junk
76  * columns.
77  *--------------------
78  */
79 typedef struct Resdom
80 {
81         NodeTag         type;
82         AttrNumber      resno;                  /* attribute number (see notes above) */
83         Oid                     restype;                /* type of the value */
84         int32           restypmod;              /* type-specific modifier of the value */
85         char       *resname;            /* name of the column (could be NULL) */
86         Index           ressortgroupref;/* nonzero if referenced by a sort/group
87                                                                  * clause */
88         Oid                     resorigtbl;             /* OID of column's source table */
89         AttrNumber      resorigcol;             /* column's number in source table */
90         bool            resjunk;                /* set to true to eliminate the attribute
91                                                                  * from final target list */
92 } Resdom;
93
94
95 /*
96  * Alias -
97  *        specifies an alias for a range variable; the alias might also
98  *        specify renaming of columns within the table.
99  */
100 typedef struct Alias
101 {
102         NodeTag         type;
103         char       *aliasname;          /* aliased rel name (never qualified) */
104         List       *colnames;           /* optional list of column aliases */
105         /* Note: colnames is a list of Value nodes (always strings) */
106 } Alias;
107
108 typedef enum InhOption
109 {
110         INH_NO,                                         /* Do NOT scan child tables */
111         INH_YES,                                        /* DO scan child tables */
112         INH_DEFAULT                                     /* Use current SQL_inheritance option */
113 } InhOption;
114
115 /*
116  * RangeVar - range variable, used in FROM clauses
117  *
118  * Also used to represent table names in utility statements; there, the alias
119  * field is not used, and inhOpt shows whether to apply the operation
120  * recursively to child tables.  In some contexts it is also useful to carry
121  * a TEMP table indication here.
122  */
123 typedef struct RangeVar
124 {
125         NodeTag         type;
126         char       *catalogname;        /* the catalog (database) name, or NULL */
127         char       *schemaname;         /* the schema name, or NULL */
128         char       *relname;            /* the relation/sequence name */
129         InhOption       inhOpt;                 /* expand rel by inheritance? recursively
130                                                                  * act on children? */
131         bool            istemp;                 /* is this a temp relation/sequence? */
132         Alias      *alias;                      /* table alias & optional column aliases */
133 } RangeVar;
134
135
136 /* ----------------------------------------------------------------
137  *                                      node types for executable expressions
138  * ----------------------------------------------------------------
139  */
140
141 /*
142  * Expr - generic superclass for executable-expression nodes
143  *
144  * All node types that are used in executable expression trees should derive
145  * from Expr (that is, have Expr as their first field).  Since Expr only
146  * contains NodeTag, this is a formality, but it is an easy form of
147  * documentation.  See also the ExprState node types in execnodes.h.
148  */
149 typedef struct Expr
150 {
151         NodeTag         type;
152 } Expr;
153
154 /*
155  * Var - expression node representing a variable (ie, a table column)
156  *
157  * Note: during parsing/planning, varnoold/varoattno are always just copies
158  * of varno/varattno.  At the tail end of planning, Var nodes appearing in
159  * upper-level plan nodes are reassigned to point to the outputs of their
160  * subplans; for example, in a join node varno becomes INNER or OUTER and
161  * varattno becomes the index of the proper element of that subplan's target
162  * list.  But varnoold/varoattno continue to hold the original values.
163  * The code doesn't really need varnoold/varoattno, but they are very useful
164  * for debugging and interpreting completed plans, so we keep them around.
165  */
166 #define    INNER                65000
167 #define    OUTER                65001
168
169 #define    PRS2_OLD_VARNO                       1
170 #define    PRS2_NEW_VARNO                       2
171
172 typedef struct Var
173 {
174         Expr            xpr;
175         Index           varno;                  /* index of this var's relation in the
176                                                                  * range table (could also be INNER or
177                                                                  * OUTER) */
178         AttrNumber      varattno;               /* attribute number of this var, or zero
179                                                                  * for all */
180         Oid                     vartype;                /* pg_type tuple OID for the type of this
181                                                                  * var */
182         int32           vartypmod;              /* pg_attribute typmod value */
183         Index           varlevelsup;
184
185         /*
186          * for subquery variables referencing outer relations; 0 in a normal
187          * var, >0 means N levels up
188          */
189         Index           varnoold;               /* original value of varno, for debugging */
190         AttrNumber      varoattno;              /* original value of varattno */
191 } Var;
192
193 /*
194  * Const
195  */
196 typedef struct Const
197 {
198         Expr            xpr;
199         Oid                     consttype;              /* PG_TYPE OID of the constant's datatype */
200         int                     constlen;               /* typlen of the constant's datatype */
201         Datum           constvalue;             /* the constant's value */
202         bool            constisnull;    /* whether the constant is null (if true,
203                                                                  * constvalue is undefined) */
204         bool            constbyval;             /* whether this datatype is passed by
205                                                                  * value. If true, then all the
206                                                                  * information is stored in the Datum. If
207                                                                  * false, then the Datum contains a
208                                                                  * pointer to the information. */
209 } Const;
210
211 /* ----------------
212  * Param
213  *              paramkind - specifies the kind of parameter. The possible values
214  *              for this field are specified in "params.h", and they are:
215  *
216  *              PARAM_NAMED: The parameter has a name, i.e. something
217  *                              like `$.salary' or `$.foobar'.
218  *                              In this case field `paramname' must be a valid name.
219  *
220  *              PARAM_NUM:       The parameter has only a numeric identifier,
221  *                              i.e. something like `$1', `$2' etc.
222  *                              The number is contained in the `paramid' field.
223  *
224  *              PARAM_EXEC:  The parameter is an internal executor parameter.
225  *                              It has a number contained in the `paramid' field.
226  * ----------------
227  */
228 typedef struct Param
229 {
230         Expr            xpr;
231         int                     paramkind;              /* kind of parameter. See above */
232         AttrNumber      paramid;                /* numeric ID for parameter ("$1") */
233         char       *paramname;          /* name for parameter ("$.foo") */
234         Oid                     paramtype;              /* PG_TYPE OID of parameter's datatype */
235 } Param;
236
237 /*
238  * Aggref
239  */
240 typedef struct Aggref
241 {
242         Expr            xpr;
243         Oid                     aggfnoid;               /* pg_proc Oid of the aggregate */
244         Oid                     aggtype;                /* type Oid of result of the aggregate */
245         Expr       *target;                     /* expression we are aggregating on */
246         Index           agglevelsup;    /* > 0 if agg belongs to outer query */
247         bool            aggstar;                /* TRUE if argument was really '*' */
248         bool            aggdistinct;    /* TRUE if it's agg(DISTINCT ...) */
249 } Aggref;
250
251 /* ----------------
252  *      ArrayRef: describes an array subscripting operation
253  *
254  * An ArrayRef can describe fetching a single element from an array,
255  * fetching a subarray (array slice), storing a single element into
256  * an array, or storing a slice.  The "store" cases work with an
257  * initial array value and a source value that is inserted into the
258  * appropriate part of the array; the result of the operation is an
259  * entire new modified array value.
260  *
261  * If reflowerindexpr = NIL, then we are fetching or storing a single array
262  * element at the subscripts given by refupperindexpr.  Otherwise we are
263  * fetching or storing an array slice, that is a rectangular subarray
264  * with lower and upper bounds given by the index expressions.
265  * reflowerindexpr must be the same length as refupperindexpr when it
266  * is not NIL.
267  *
268  * Note: refrestype is NOT the element type, but the array type,
269  * when doing subarray fetch or either type of store.
270  * ----------------
271  */
272 typedef struct ArrayRef
273 {
274         Expr            xpr;
275         Oid                     refrestype;             /* type of the result of the ArrayRef
276                                                                  * operation */
277         Oid                     refarraytype;   /* type of the array proper */
278         Oid                     refelemtype;    /* type of the array elements */
279         List       *refupperindexpr;/* expressions that evaluate to upper
280                                                                  * array indexes */
281         List       *reflowerindexpr;/* expressions that evaluate to lower
282                                                                  * array indexes */
283         Expr       *refexpr;            /* the expression that evaluates to an
284                                                                  * array value */
285         Expr       *refassgnexpr;       /* expression for the source value, or
286                                                                  * NULL if fetch */
287 } ArrayRef;
288
289 /*
290  * CoercionContext - distinguishes the allowed set of type casts
291  *
292  * NB: ordering of the alternatives is significant; later (larger) values
293  * allow more casts than earlier ones.
294  */
295 typedef enum CoercionContext
296 {
297         COERCION_IMPLICIT,                      /* coercion in context of expression */
298         COERCION_ASSIGNMENT,            /* coercion in context of assignment */
299         COERCION_EXPLICIT                       /* explicit cast operation */
300 } CoercionContext;
301
302 /*
303  * CoercionForm - information showing how to display a function-call node
304  */
305 typedef enum CoercionForm
306 {
307         COERCE_EXPLICIT_CALL,           /* display as a function call */
308         COERCE_EXPLICIT_CAST,           /* display as an explicit cast */
309         COERCE_IMPLICIT_CAST,           /* implicit cast, so hide it */
310         COERCE_DONTCARE                         /* special case for planner */
311 } CoercionForm;
312
313 /*
314  * FuncExpr - expression node for a function call
315  */
316 typedef struct FuncExpr
317 {
318         Expr            xpr;
319         Oid                     funcid;                 /* PG_PROC OID of the function */
320         Oid                     funcresulttype; /* PG_TYPE OID of result value */
321         bool            funcretset;             /* true if function returns set */
322         CoercionForm funcformat;        /* how to display this function call */
323         List       *args;                       /* arguments to the function */
324 } FuncExpr;
325
326 /*
327  * OpExpr - expression node for an operator invocation
328  *
329  * Semantically, this is essentially the same as a function call.
330  *
331  * Note that opfuncid is not necessarily filled in immediately on creation
332  * of the node.  The planner makes sure it is valid before passing the node
333  * tree to the executor, but during parsing/planning opfuncid is typically 0.
334  */
335 typedef struct OpExpr
336 {
337         Expr            xpr;
338         Oid                     opno;                   /* PG_OPERATOR OID of the operator */
339         Oid                     opfuncid;               /* PG_PROC OID of underlying function */
340         Oid                     opresulttype;   /* PG_TYPE OID of result value */
341         bool            opretset;               /* true if operator returns set */
342         List       *args;                       /* arguments to the operator (1 or 2) */
343 } OpExpr;
344
345 /*
346  * DistinctExpr - expression node for "x IS DISTINCT FROM y"
347  *
348  * Except for the nodetag, this is represented identically to an OpExpr
349  * referencing the "=" operator for x and y.
350  * We use "=", not the more obvious "<>", because more datatypes have "="
351  * than "<>".  This means the executor must invert the operator result.
352  * Note that the operator function won't be called at all if either input
353  * is NULL, since then the result can be determined directly.
354  */
355 typedef OpExpr DistinctExpr;
356
357 /*
358  * ScalarArrayOpExpr - expression node for "scalar op ANY/ALL (array)"
359  *
360  * The operator must yield boolean.  It is applied to the left operand
361  * and each element of the righthand array, and the results are combined
362  * with OR or AND (for ANY or ALL respectively).  The node representation
363  * is almost the same as for the underlying operator, but we need a useOr
364  * flag to remember whether it's ANY or ALL, and we don't have to store
365  * the result type because it must be boolean.
366  */
367 typedef struct ScalarArrayOpExpr
368 {
369         Expr            xpr;
370         Oid                     opno;                   /* PG_OPERATOR OID of the operator */
371         Oid                     opfuncid;               /* PG_PROC OID of underlying function */
372         bool            useOr;                  /* true for ANY, false for ALL */
373         List       *args;                       /* the scalar and array operands */
374 } ScalarArrayOpExpr;
375
376 /*
377  * BoolExpr - expression node for the basic Boolean operators AND, OR, NOT
378  *
379  * Notice the arguments are given as a List.  For NOT, of course the list
380  * must always have exactly one element.  For AND and OR, the executor can
381  * handle any number of arguments.      The parser treats AND and OR as binary
382  * and so it only produces two-element lists, but the optimizer will flatten
383  * trees of AND and OR nodes to produce longer lists when possible.
384  */
385 typedef enum BoolExprType
386 {
387         AND_EXPR, OR_EXPR, NOT_EXPR
388 } BoolExprType;
389
390 typedef struct BoolExpr
391 {
392         Expr            xpr;
393         BoolExprType boolop;
394         List       *args;                       /* arguments to this expression */
395 } BoolExpr;
396
397 /* ----------------
398  * SubLink
399  *
400  * A SubLink represents a subselect appearing in an expression, and in some
401  * cases also the combining operator(s) just above it.  The subLinkType
402  * indicates the form of the expression represented:
403  *      EXISTS_SUBLINK          EXISTS(SELECT ...)
404  *      ALL_SUBLINK                     (lefthand) op ALL (SELECT ...)
405  *      ANY_SUBLINK                     (lefthand) op ANY (SELECT ...)
406  *      MULTIEXPR_SUBLINK       (lefthand) op (SELECT ...)
407  *      EXPR_SUBLINK            (SELECT with single targetlist item ...)
408  *      ARRAY_SUBLINK           ARRAY(SELECT with single targetlist item ...)
409  * For ALL, ANY, and MULTIEXPR, the lefthand is a list of expressions of the
410  * same length as the subselect's targetlist.  MULTIEXPR will *always* have
411  * a list with more than one entry; if the subselect has just one target
412  * then the parser will create an EXPR_SUBLINK instead (and any operator
413  * above the subselect will be represented separately).  Note that both
414  * MULTIEXPR and EXPR require the subselect to deliver only one row.
415  * ARRAY requires just one target column, and creates an array of the target
416  * column's type using one or more rows resulting from the subselect.
417  * ALL, ANY, and MULTIEXPR require the combining operators to deliver boolean
418  * results.  These are reduced to one result per row using OR or AND semantics
419  * depending on the "useOr" flag.  ALL and ANY combine the per-row results
420  * using AND and OR semantics respectively.
421  *
422  * SubLink is classed as an Expr node, but it is not actually executable;
423  * it must be replaced in the expression tree by a SubPlan node during
424  * planning.
425  *
426  * NOTE: in the raw output of gram.y, lefthand contains a list of raw
427  * expressions; useOr and operOids are not filled in yet.  Also, subselect
428  * is a raw parsetree.  During parse analysis, the parser transforms the
429  * lefthand expression list using normal expression transformation rules.
430  * It fills operOids with the OIDs representing the specific operator(s)
431  * to apply to each pair of lefthand and targetlist expressions.
432  * And subselect is transformed to a Query.  This is the representation
433  * seen in saved rules and in the rewriter.
434  *
435  * In EXISTS, EXPR, and ARRAY SubLinks, lefthand, operName, and operOids are
436  * unused and are always NIL.  useOr is not significant either for these
437  * sublink types.
438  * ----------------
439  */
440 typedef enum SubLinkType
441 {
442         EXISTS_SUBLINK,
443         ALL_SUBLINK,
444         ANY_SUBLINK,
445         MULTIEXPR_SUBLINK,
446         EXPR_SUBLINK,
447         ARRAY_SUBLINK
448 } SubLinkType;
449
450
451 typedef struct SubLink
452 {
453         Expr            xpr;
454         SubLinkType subLinkType;        /* EXISTS, ALL, ANY, MULTIEXPR, EXPR */
455         bool            useOr;                  /* TRUE to combine column results with
456                                                                  * "OR" not "AND" */
457         List       *lefthand;           /* list of outer-query expressions on the
458                                                                  * left */
459         List       *operName;           /* originally specified operator name */
460         List       *operOids;           /* OIDs of actual combining operators */
461         Node       *subselect;          /* subselect as Query* or parsetree */
462 } SubLink;
463
464 /*
465  * SubPlan - executable expression node for a subplan (sub-SELECT)
466  *
467  * The planner replaces SubLink nodes in expression trees with SubPlan
468  * nodes after it has finished planning the subquery.  SubPlan contains
469  * a sub-plantree and rtable instead of a sub-Query.
470  *
471  * In an ordinary subplan, "exprs" points to a list of executable expressions
472  * (OpExpr trees) for the combining operators; their left-hand arguments are
473  * the original lefthand expressions, and their right-hand arguments are
474  * PARAM_EXEC Param nodes representing the outputs of the sub-select.
475  * (NOTE: runtime coercion functions may be inserted as well.)  But if the
476  * sub-select becomes an initplan rather than a subplan, these executable
477  * expressions are part of the outer plan's expression tree (and the SubPlan
478  * node itself is not).  In this case "exprs" is NIL to avoid duplication.
479  *
480  * The planner also derives lists of the values that need to be passed into
481  * and out of the subplan.      Input values are represented as a list "args" of
482  * expressions to be evaluated in the outer-query context (currently these
483  * args are always just Vars, but in principle they could be any expression).
484  * The values are assigned to the global PARAM_EXEC params indexed by parParam
485  * (the parParam and args lists must have the same ordering).  setParam is a
486  * list of the PARAM_EXEC params that are computed by the sub-select, if it
487  * is an initplan; they are listed in order by sub-select output column
488  * position.  (parParam and setParam are integer Lists, not Bitmapsets,
489  * because their ordering is significant.)
490  */
491 typedef struct SubPlan
492 {
493         Expr            xpr;
494         /* Fields copied from original SubLink: */
495         SubLinkType subLinkType;        /* EXISTS, ALL, ANY, MULTIEXPR, EXPR */
496         bool            useOr;                  /* TRUE to combine column results with
497                                                                  * "OR" not "AND" */
498         /* The combining operators, transformed to executable expressions: */
499         List       *exprs;                      /* list of OpExpr expression trees */
500         List       *paramIds;           /* IDs of Params embedded in the above */
501         /* Note: paramIds has a one-to-one correspondence to the exprs list */
502         /* The subselect, transformed to a Plan: */
503         struct Plan *plan;                      /* subselect plan itself */
504         int                     plan_id;                /* dummy thing because of we haven't equal
505                                                                  * funcs for plan nodes... actually, we
506                                                                  * could put *plan itself somewhere else
507                                                                  * (TopPlan node ?)... */
508         List       *rtable;                     /* range table for subselect */
509         /* Information about execution strategy: */
510         bool            useHashTable;   /* TRUE to store subselect output in a
511                                                                  * hash table (implies we are doing "IN") */
512         bool            unknownEqFalse; /* TRUE if it's okay to return FALSE when
513                                                                  * the spec result is UNKNOWN; this allows
514                                                                  * much simpler handling of null values */
515         /* Information for passing params into and out of the subselect: */
516         /* setParam and parParam are lists of integers (param IDs) */
517         List       *setParam;           /* initplan subqueries have to set these
518                                                                  * Params for parent plan */
519         List       *parParam;           /* indices of input Params from parent
520                                                                  * plan */
521         List       *args;                       /* exprs to pass as parParam values */
522 } SubPlan;
523
524 /* ----------------
525  * FieldSelect
526  *
527  * FieldSelect represents the operation of extracting one field from a tuple
528  * value.  At runtime, the input expression is expected to yield a rowtype
529  * Datum.  The specified field number is extracted and returned as a Datum.
530  * ----------------
531  */
532
533 typedef struct FieldSelect
534 {
535         Expr            xpr;
536         Expr       *arg;                        /* input expression */
537         AttrNumber      fieldnum;               /* attribute number of field to extract */
538         Oid                     resulttype;             /* type of the field (result type of this
539                                                                  * node) */
540         int32           resulttypmod;   /* output typmod (usually -1) */
541 } FieldSelect;
542
543 /* ----------------
544  * RelabelType
545  *
546  * RelabelType represents a "dummy" type coercion between two binary-
547  * compatible datatypes, such as reinterpreting the result of an OID
548  * expression as an int4.  It is a no-op at runtime; we only need it
549  * to provide a place to store the correct type to be attributed to
550  * the expression result during type resolution.  (We can't get away
551  * with just overwriting the type field of the input expression node,
552  * so we need a separate node to show the coercion's result type.)
553  * ----------------
554  */
555
556 typedef struct RelabelType
557 {
558         Expr            xpr;
559         Expr       *arg;                        /* input expression */
560         Oid                     resulttype;             /* output type of coercion expression */
561         int32           resulttypmod;   /* output typmod (usually -1) */
562         CoercionForm relabelformat; /* how to display this node */
563 } RelabelType;
564
565 /*----------
566  * CaseExpr - a CASE expression
567  *
568  * We support two distinct forms of CASE expression:
569  *              CASE WHEN boolexpr THEN expr [ WHEN boolexpr THEN expr ... ]
570  *              CASE testexpr WHEN compexpr THEN expr [ WHEN compexpr THEN expr ... ]
571  * These are distinguishable by the "arg" field being NULL in the first case
572  * and the testexpr in the second case.
573  *
574  * In the raw grammar output for the second form, the condition expressions
575  * of the WHEN clauses are just the comparison values.  Parse analysis
576  * converts these to valid boolean expressions of the form
577  *              CaseTestExpr '=' compexpr
578  * where the CaseTestExpr node is a placeholder that emits the correct
579  * value at runtime.  This structure is used so that the testexpr need be
580  * evaluated only once.  Note that after parse analysis, the condition
581  * expressions always yield boolean.
582  *
583  * Note: we can test whether a CaseExpr has been through parse analysis
584  * yet by checking whether casetype is InvalidOid or not.
585  *----------
586  */
587 typedef struct CaseExpr
588 {
589         Expr            xpr;
590         Oid                     casetype;               /* type of expression result */
591         Expr       *arg;                        /* implicit equality comparison argument */
592         List       *args;                       /* the arguments (list of WHEN clauses) */
593         Expr       *defresult;          /* the default result (ELSE clause) */
594 } CaseExpr;
595
596 /*
597  * CaseWhen - one arm of a CASE expression
598  */
599 typedef struct CaseWhen
600 {
601         Expr            xpr;
602         Expr       *expr;                       /* condition expression */
603         Expr       *result;                     /* substitution result */
604 } CaseWhen;
605
606 /*
607  * Placeholder node for the test value to be processed by a CASE expression.
608  * This is effectively like a Param, but can be implemented more simply
609  * since we need only one replacement value at a time.
610  */
611 typedef struct CaseTestExpr
612 {
613         Expr            xpr;
614         Oid                     typeId;                 /* type for substituted value */
615         int32           typeMod;                /* typemod for substituted value */
616 } CaseTestExpr;
617
618 /*
619  * ArrayExpr - an ARRAY[] expression
620  *
621  * Note: if multidims is false, the constituent expressions all yield the
622  * scalar type identified by element_typeid.  If multidims is true, the
623  * constituent expressions all yield arrays of element_typeid (ie, the same
624  * type as array_typeid); at runtime we must check for compatible subscripts.
625  */
626 typedef struct ArrayExpr
627 {
628         Expr            xpr;
629         Oid                     array_typeid;   /* type of expression result */
630         Oid                     element_typeid; /* common type of array elements */
631         List       *elements;           /* the array elements or sub-arrays */
632         bool            multidims;              /* true if elements are sub-arrays */
633 } ArrayExpr;
634
635 /*
636  * CoalesceExpr - a COALESCE expression
637  */
638 typedef struct CoalesceExpr
639 {
640         Expr            xpr;
641         Oid                     coalescetype;   /* type of expression result */
642         List       *args;                       /* the arguments */
643 } CoalesceExpr;
644
645 /*
646  * NullIfExpr - a NULLIF expression
647  *
648  * Like DistinctExpr, this is represented the same as an OpExpr referencing
649  * the "=" operator for x and y.
650  */
651 typedef OpExpr NullIfExpr;
652
653 /* ----------------
654  * NullTest
655  *
656  * NullTest represents the operation of testing a value for NULLness.
657  * Currently, we only support scalar input values, but eventually a
658  * row-constructor input should be supported.
659  * The appropriate test is performed and returned as a boolean Datum.
660  * ----------------
661  */
662
663 typedef enum NullTestType
664 {
665         IS_NULL, IS_NOT_NULL
666 } NullTestType;
667
668 typedef struct NullTest
669 {
670         Expr            xpr;
671         Expr       *arg;                        /* input expression */
672         NullTestType nulltesttype;      /* IS NULL, IS NOT NULL */
673 } NullTest;
674
675 /*
676  * BooleanTest
677  *
678  * BooleanTest represents the operation of determining whether a boolean
679  * is TRUE, FALSE, or UNKNOWN (ie, NULL).  All six meaningful combinations
680  * are supported.  Note that a NULL input does *not* cause a NULL result.
681  * The appropriate test is performed and returned as a boolean Datum.
682  */
683
684 typedef enum BoolTestType
685 {
686         IS_TRUE, IS_NOT_TRUE, IS_FALSE, IS_NOT_FALSE, IS_UNKNOWN, IS_NOT_UNKNOWN
687 } BoolTestType;
688
689 typedef struct BooleanTest
690 {
691         Expr            xpr;
692         Expr       *arg;                        /* input expression */
693         BoolTestType booltesttype;      /* test type */
694 } BooleanTest;
695
696 /*
697  * CoerceToDomain
698  *
699  * CoerceToDomain represents the operation of coercing a value to a domain
700  * type.  At runtime (and not before) the precise set of constraints to be
701  * checked will be determined.  If the value passes, it is returned as the
702  * result; if not, an error is raised.  Note that this is equivalent to
703  * RelabelType in the scenario where no constraints are applied.
704  */
705 typedef struct CoerceToDomain
706 {
707         Expr            xpr;
708         Expr       *arg;                        /* input expression */
709         Oid                     resulttype;             /* domain type ID (result type) */
710         int32           resulttypmod;   /* output typmod (currently always -1) */
711         CoercionForm coercionformat;    /* how to display this node */
712 } CoerceToDomain;
713
714 /*
715  * Placeholder node for the value to be processed by a domain's check
716  * constraint.  This is effectively like a Param, but can be implemented more
717  * simply since we need only one replacement value at a time.
718  *
719  * Note: the typeId/typeMod will be set from the domain's base type, not
720  * the domain itself.  This is because we shouldn't consider the value to
721  * be a member of the domain if we haven't yet checked its constraints.
722  */
723 typedef struct CoerceToDomainValue
724 {
725         Expr            xpr;
726         Oid                     typeId;                 /* type for substituted value */
727         int32           typeMod;                /* typemod for substituted value */
728 } CoerceToDomainValue;
729
730 /*
731  * Placeholder node for a DEFAULT marker in an INSERT or UPDATE command.
732  *
733  * This is not an executable expression: it must be replaced by the actual
734  * column default expression during rewriting.  But it is convenient to
735  * treat it as an expression node during parsing and rewriting.
736  */
737 typedef struct SetToDefault
738 {
739         Expr            xpr;
740         Oid                     typeId;                 /* type for substituted value */
741         int32           typeMod;                /* typemod for substituted value */
742 } SetToDefault;
743
744 /*
745  * TargetEntry -
746  *         a target entry (used in query target lists)
747  *
748  * Strictly speaking, a TargetEntry isn't an expression node (since it can't
749  * be evaluated by ExecEvalExpr).  But we treat it as one anyway, since in
750  * very many places it's convenient to process a whole query targetlist as a
751  * single expression tree.
752  *
753  * The separation between TargetEntry and Resdom is historical.  One of these
754  * days, Resdom should probably get folded into TargetEntry.
755  */
756 typedef struct TargetEntry
757 {
758         Expr            xpr;
759         Resdom     *resdom;                     /* descriptor for targetlist item */
760         Expr       *expr;                       /* expression to evaluate */
761 } TargetEntry;
762
763
764 /* ----------------------------------------------------------------
765  *                                      node types for join trees
766  *
767  * The leaves of a join tree structure are RangeTblRef nodes.  Above
768  * these, JoinExpr nodes can appear to denote a specific kind of join
769  * or qualified join.  Also, FromExpr nodes can appear to denote an
770  * ordinary cross-product join ("FROM foo, bar, baz WHERE ...").
771  * FromExpr is like a JoinExpr of jointype JOIN_INNER, except that it
772  * may have any number of child nodes, not just two.  Also, there is an
773  * implementation-defined difference: the planner is allowed to join the
774  * children of a FromExpr using whatever join order seems good to it.
775  * At present, JoinExpr nodes are always joined in exactly the order
776  * implied by the jointree structure (except the planner may choose to
777  * swap inner and outer members of a join pair).
778  *
779  * NOTE: the top level of a Query's jointree is always a FromExpr.
780  * Even if the jointree contains no rels, there will be a FromExpr.
781  *
782  * NOTE: the qualification expressions present in JoinExpr nodes are
783  * *in addition to* the query's main WHERE clause, which appears as the
784  * qual of the top-level FromExpr.      The reason for associating quals with
785  * specific nodes in the jointree is that the position of a qual is critical
786  * when outer joins are present.  (If we enforce a qual too soon or too late,
787  * that may cause the outer join to produce the wrong set of NULL-extended
788  * rows.)  If all joins are inner joins then all the qual positions are
789  * semantically interchangeable.
790  *
791  * NOTE: in the raw output of gram.y, a join tree contains RangeVar,
792  * RangeSubselect, and RangeFunction nodes, which are all replaced by
793  * RangeTblRef nodes during the parse analysis phase.  Also, the top-level
794  * FromExpr is added during parse analysis; the grammar regards FROM and
795  * WHERE as separate.
796  * ----------------------------------------------------------------
797  */
798
799 /*
800  * RangeTblRef - reference to an entry in the query's rangetable
801  *
802  * We could use direct pointers to the RT entries and skip having these
803  * nodes, but multiple pointers to the same node in a querytree cause
804  * lots of headaches, so it seems better to store an index into the RT.
805  */
806 typedef struct RangeTblRef
807 {
808         NodeTag         type;
809         int                     rtindex;
810 } RangeTblRef;
811
812 /*----------
813  * JoinExpr - for SQL JOIN expressions
814  *
815  * isNatural, using, and quals are interdependent.      The user can write only
816  * one of NATURAL, USING(), or ON() (this is enforced by the grammar).
817  * If he writes NATURAL then parse analysis generates the equivalent USING()
818  * list, and from that fills in "quals" with the right equality comparisons.
819  * If he writes USING() then "quals" is filled with equality comparisons.
820  * If he writes ON() then only "quals" is set.  Note that NATURAL/USING
821  * are not equivalent to ON() since they also affect the output column list.
822  *
823  * alias is an Alias node representing the AS alias-clause attached to the
824  * join expression, or NULL if no clause.  NB: presence or absence of the
825  * alias has a critical impact on semantics, because a join with an alias
826  * restricts visibility of the tables/columns inside it.
827  *
828  * During parse analysis, an RTE is created for the Join, and its index
829  * is filled into rtindex.      This RTE is present mainly so that Vars can
830  * be created that refer to the outputs of the join.
831  *----------
832  */
833 typedef struct JoinExpr
834 {
835         NodeTag         type;
836         JoinType        jointype;               /* type of join */
837         bool            isNatural;              /* Natural join? Will need to shape table */
838         Node       *larg;                       /* left subtree */
839         Node       *rarg;                       /* right subtree */
840         List       *using;                      /* USING clause, if any (list of String) */
841         Node       *quals;                      /* qualifiers on join, if any */
842         Alias      *alias;                      /* user-written alias clause, if any */
843         int                     rtindex;                /* RT index assigned for join */
844 } JoinExpr;
845
846 /*----------
847  * FromExpr - represents a FROM ... WHERE ... construct
848  *
849  * This is both more flexible than a JoinExpr (it can have any number of
850  * children, including zero) and less so --- we don't need to deal with
851  * aliases and so on.  The output column set is implicitly just the union
852  * of the outputs of the children.
853  *----------
854  */
855 typedef struct FromExpr
856 {
857         NodeTag         type;
858         List       *fromlist;           /* List of join subtrees */
859         Node       *quals;                      /* qualifiers on join, if any */
860 } FromExpr;
861
862 #endif   /* PRIMNODES_H */