1 /*-------------------------------------------------------------------------
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
10 * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
11 * Portions Copyright (c) 1994, Regents of the University of California
13 * $PostgreSQL: pgsql/src/include/nodes/primnodes.h,v 1.97 2004/04/01 21:28:46 tgl Exp $
15 *-------------------------------------------------------------------------
20 #include "access/attnum.h"
21 #include "nodes/pg_list.h"
22 #include "nodes/value.h"
25 /* ----------------------------------------------------------------
27 * ----------------------------------------------------------------
30 /*--------------------
31 * Resdom (Result Domain)
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.
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!
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.
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.
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
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
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 */
97 * specifies an alias for a range variable; the alias might also
98 * specify renaming of columns within the table.
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) */
108 typedef enum InhOption
110 INH_NO, /* Do NOT scan child tables */
111 INH_YES, /* DO scan child tables */
112 INH_DEFAULT /* Use current SQL_inheritance option */
116 * RangeVar - range variable, used in FROM clauses
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.
123 typedef struct RangeVar
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 */
136 /* ----------------------------------------------------------------
137 * node types for executable expressions
138 * ----------------------------------------------------------------
142 * Expr - generic superclass for executable-expression nodes
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.
155 * Var - expression node representing a variable (ie, a table column)
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.
169 #define PRS2_OLD_VARNO 1
170 #define PRS2_NEW_VARNO 2
175 Index varno; /* index of this var's relation in the
176 * range table (could also be INNER or
178 AttrNumber varattno; /* attribute number of this var, or zero
180 Oid vartype; /* pg_type tuple OID for the type of this
182 int32 vartypmod; /* pg_attribute typmod value */
186 * for subquery variables referencing outer relations; 0 in a normal
187 * var, >0 means N levels up
189 Index varnoold; /* original value of varno, for debugging */
190 AttrNumber varoattno; /* original value of varattno */
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. */
213 * paramkind - specifies the kind of parameter. The possible values
214 * for this field are specified in "params.h", and they are:
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.
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.
224 * PARAM_EXEC: The parameter is an internal executor parameter.
225 * It has a number contained in the `paramid' field.
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 */
240 typedef struct Aggref
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 ...) */
252 * ArrayRef: describes an array subscripting operation
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.
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
268 * Note: refrestype is NOT the element type, but the array type,
269 * when doing subarray fetch or either type of store.
272 typedef struct ArrayRef
275 Oid refrestype; /* type of the result of the ArrayRef
277 Oid refarraytype; /* type of the array proper */
278 Oid refelemtype; /* type of the array elements */
279 List *refupperindexpr;/* expressions that evaluate to upper
281 List *reflowerindexpr;/* expressions that evaluate to lower
283 Expr *refexpr; /* the expression that evaluates to an
285 Expr *refassgnexpr; /* expression for the source value, or
290 * CoercionContext - distinguishes the allowed set of type casts
292 * NB: ordering of the alternatives is significant; later (larger) values
293 * allow more casts than earlier ones.
295 typedef enum CoercionContext
297 COERCION_IMPLICIT, /* coercion in context of expression */
298 COERCION_ASSIGNMENT, /* coercion in context of assignment */
299 COERCION_EXPLICIT /* explicit cast operation */
303 * CoercionForm - information showing how to display a function-call node
305 typedef enum CoercionForm
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 */
314 * FuncExpr - expression node for a function call
316 typedef struct FuncExpr
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 */
327 * OpExpr - expression node for an operator invocation
329 * Semantically, this is essentially the same as a function call.
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.
335 typedef struct OpExpr
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) */
346 * DistinctExpr - expression node for "x IS DISTINCT FROM y"
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.
355 typedef OpExpr DistinctExpr;
358 * ScalarArrayOpExpr - expression node for "scalar op ANY/ALL (array)"
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.
367 typedef struct ScalarArrayOpExpr
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 */
377 * BoolExpr - expression node for the basic Boolean operators AND, OR, NOT
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.
385 typedef enum BoolExprType
387 AND_EXPR, OR_EXPR, NOT_EXPR
390 typedef struct BoolExpr
394 List *args; /* arguments to this expression */
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.
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
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.
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
440 typedef enum SubLinkType
451 typedef struct SubLink
454 SubLinkType subLinkType; /* EXISTS, ALL, ANY, MULTIEXPR, EXPR */
455 bool useOr; /* TRUE to combine column results with
457 List *lefthand; /* list of outer-query expressions on the
459 List *operName; /* originally specified operator name */
460 List *operOids; /* OIDs of actual combining operators */
461 Node *subselect; /* subselect as Query* or parsetree */
465 * SubPlan - executable expression node for a subplan (sub-SELECT)
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.
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.
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.)
491 typedef struct SubPlan
494 /* Fields copied from original SubLink: */
495 SubLinkType subLinkType; /* EXISTS, ALL, ANY, MULTIEXPR, EXPR */
496 bool useOr; /* TRUE to combine column results with
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
521 List *args; /* exprs to pass as parParam values */
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.
533 typedef struct FieldSelect
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
540 int32 resulttypmod; /* output typmod (usually -1) */
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.)
556 typedef struct RelabelType
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 */
566 * CaseExpr - a CASE expression
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.
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.
583 * Note: we can test whether a CaseExpr has been through parse analysis
584 * yet by checking whether casetype is InvalidOid or not.
587 typedef struct CaseExpr
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) */
597 * CaseWhen - one arm of a CASE expression
599 typedef struct CaseWhen
602 Expr *expr; /* condition expression */
603 Expr *result; /* substitution result */
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.
611 typedef struct CaseTestExpr
614 Oid typeId; /* type for substituted value */
615 int32 typeMod; /* typemod for substituted value */
619 * ArrayExpr - an ARRAY[] expression
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.
626 typedef struct ArrayExpr
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 */
636 * CoalesceExpr - a COALESCE expression
638 typedef struct CoalesceExpr
641 Oid coalescetype; /* type of expression result */
642 List *args; /* the arguments */
646 * NullIfExpr - a NULLIF expression
648 * Like DistinctExpr, this is represented the same as an OpExpr referencing
649 * the "=" operator for x and y.
651 typedef OpExpr NullIfExpr;
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.
663 typedef enum NullTestType
668 typedef struct NullTest
671 Expr *arg; /* input expression */
672 NullTestType nulltesttype; /* IS NULL, IS NOT NULL */
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.
684 typedef enum BoolTestType
686 IS_TRUE, IS_NOT_TRUE, IS_FALSE, IS_NOT_FALSE, IS_UNKNOWN, IS_NOT_UNKNOWN
689 typedef struct BooleanTest
692 Expr *arg; /* input expression */
693 BoolTestType booltesttype; /* test type */
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.
705 typedef struct CoerceToDomain
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 */
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.
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.
723 typedef struct CoerceToDomainValue
726 Oid typeId; /* type for substituted value */
727 int32 typeMod; /* typemod for substituted value */
728 } CoerceToDomainValue;
731 * Placeholder node for a DEFAULT marker in an INSERT or UPDATE command.
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.
737 typedef struct SetToDefault
740 Oid typeId; /* type for substituted value */
741 int32 typeMod; /* typemod for substituted value */
746 * a target entry (used in query target lists)
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.
753 * The separation between TargetEntry and Resdom is historical. One of these
754 * days, Resdom should probably get folded into TargetEntry.
756 typedef struct TargetEntry
759 Resdom *resdom; /* descriptor for targetlist item */
760 Expr *expr; /* expression to evaluate */
764 /* ----------------------------------------------------------------
765 * node types for join trees
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).
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.
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.
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
796 * ----------------------------------------------------------------
800 * RangeTblRef - reference to an entry in the query's rangetable
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.
806 typedef struct RangeTblRef
813 * JoinExpr - for SQL JOIN expressions
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.
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.
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.
833 typedef struct JoinExpr
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 */
847 * FromExpr - represents a FROM ... WHERE ... construct
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.
855 typedef struct FromExpr
858 List *fromlist; /* List of join subtrees */
859 Node *quals; /* qualifiers on join, if any */
862 #endif /* PRIMNODES_H */