Eneboo - Documentación para desarrolladores
src/libpq/include/nodes/primnodes.h
Ir a la documentación de este archivo.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * primnodes.h
00004  *        Definitions for "primitive" node types, those that are used in more
00005  *        than one of the parse/plan/execute stages of the query pipeline.
00006  *        Currently, these are mostly nodes for executable expressions
00007  *        and join trees.
00008  *
00009  *
00010  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
00011  * Portions Copyright (c) 1994, Regents of the University of California
00012  *
00013  * $PostgreSQL: pgsql/src/include/nodes/primnodes.h,v 1.109 2005/10/15 02:49:45 momjian Exp $
00014  *
00015  *-------------------------------------------------------------------------
00016  */
00017 #ifndef PRIMNODES_H
00018 #define PRIMNODES_H
00019 
00020 #include "access/attnum.h"
00021 #include "nodes/pg_list.h"
00022 #include "nodes/value.h"
00023 
00024 
00025 /* ----------------------------------------------------------------
00026  *                                              node definitions
00027  * ----------------------------------------------------------------
00028  */
00029 
00030 /*
00031  * Alias -
00032  *        specifies an alias for a range variable; the alias might also
00033  *        specify renaming of columns within the table.
00034  *
00035  * Note: colnames is a list of Value nodes (always strings).  In Alias structs
00036  * associated with RTEs, there may be entries corresponding to dropped
00037  * columns; these are normally empty strings ("").      See parsenodes.h for info.
00038  */
00039 typedef struct Alias
00040 {
00041         NodeTag         type;
00042         char       *aliasname;          /* aliased rel name (never qualified) */
00043         List       *colnames;           /* optional list of column aliases */
00044 } Alias;
00045 
00046 typedef enum InhOption
00047 {
00048         INH_NO,                                         /* Do NOT scan child tables */
00049         INH_YES,                                        /* DO scan child tables */
00050         INH_DEFAULT                                     /* Use current SQL_inheritance option */
00051 } InhOption;
00052 
00053 /*
00054  * RangeVar - range variable, used in FROM clauses
00055  *
00056  * Also used to represent table names in utility statements; there, the alias
00057  * field is not used, and inhOpt shows whether to apply the operation
00058  * recursively to child tables.  In some contexts it is also useful to carry
00059  * a TEMP table indication here.
00060  */
00061 typedef struct RangeVar
00062 {
00063         NodeTag         type;
00064         char       *catalogname;        /* the catalog (database) name, or NULL */
00065         char       *schemaname;         /* the schema name, or NULL */
00066         char       *relname;            /* the relation/sequence name */
00067         InhOption       inhOpt;                 /* expand rel by inheritance? recursively act
00068                                                                  * on children? */
00069         bool            istemp;                 /* is this a temp relation/sequence? */
00070         Alias      *alias;                      /* table alias & optional column aliases */
00071 } RangeVar;
00072 
00073 
00074 /* ----------------------------------------------------------------
00075  *                                      node types for executable expressions
00076  * ----------------------------------------------------------------
00077  */
00078 
00079 /*
00080  * Expr - generic superclass for executable-expression nodes
00081  *
00082  * All node types that are used in executable expression trees should derive
00083  * from Expr (that is, have Expr as their first field).  Since Expr only
00084  * contains NodeTag, this is a formality, but it is an easy form of
00085  * documentation.  See also the ExprState node types in execnodes.h.
00086  */
00087 typedef struct Expr
00088 {
00089         NodeTag         type;
00090 } Expr;
00091 
00092 /*
00093  * Var - expression node representing a variable (ie, a table column)
00094  *
00095  * Note: during parsing/planning, varnoold/varoattno are always just copies
00096  * of varno/varattno.  At the tail end of planning, Var nodes appearing in
00097  * upper-level plan nodes are reassigned to point to the outputs of their
00098  * subplans; for example, in a join node varno becomes INNER or OUTER and
00099  * varattno becomes the index of the proper element of that subplan's target
00100  * list.  But varnoold/varoattno continue to hold the original values.
00101  * The code doesn't really need varnoold/varoattno, but they are very useful
00102  * for debugging and interpreting completed plans, so we keep them around.
00103  */
00104 #define    INNER                65000
00105 #define    OUTER                65001
00106 
00107 #define    PRS2_OLD_VARNO                       1
00108 #define    PRS2_NEW_VARNO                       2
00109 
00110 typedef struct Var
00111 {
00112         Expr            xpr;
00113         Index           varno;                  /* index of this var's relation in the range
00114                                                                  * table (could also be INNER or OUTER) */
00115         AttrNumber      varattno;               /* attribute number of this var, or zero for
00116                                                                  * all */
00117         Oid                     vartype;                /* pg_type tuple OID for the type of this var */
00118         int32           vartypmod;              /* pg_attribute typmod value */
00119         Index           varlevelsup;
00120 
00121         /*
00122          * for subquery variables referencing outer relations; 0 in a normal var,
00123          * >0 means N levels up
00124          */
00125         Index           varnoold;               /* original value of varno, for debugging */
00126         AttrNumber      varoattno;              /* original value of varattno */
00127 } Var;
00128 
00129 /*
00130  * Const
00131  */
00132 typedef struct Const
00133 {
00134         Expr            xpr;
00135         Oid                     consttype;              /* PG_TYPE OID of the constant's datatype */
00136         int                     constlen;               /* typlen of the constant's datatype */
00137         Datum           constvalue;             /* the constant's value */
00138         bool            constisnull;    /* whether the constant is null (if true,
00139                                                                  * constvalue is undefined) */
00140         bool            constbyval;             /* whether this datatype is passed by value.
00141                                                                  * If true, then all the information is stored
00142                                                                  * in the Datum. If false, then the Datum
00143                                                                  * contains a pointer to the information. */
00144 } Const;
00145 
00146 /* ----------------
00147  * Param
00148  *              paramkind - specifies the kind of parameter. The possible values
00149  *              for this field are specified in "params.h", and they are:
00150  *
00151  *              PARAM_NAMED: The parameter has a name, i.e. something
00152  *                              like `$.salary' or `$.foobar'.
00153  *                              In this case field `paramname' must be a valid name.
00154  *
00155  *              PARAM_NUM:       The parameter has only a numeric identifier,
00156  *                              i.e. something like `$1', `$2' etc.
00157  *                              The number is contained in the `paramid' field.
00158  *
00159  *              PARAM_EXEC:  The parameter is an internal executor parameter.
00160  *                              It has a number contained in the `paramid' field.
00161  * ----------------
00162  */
00163 typedef struct Param
00164 {
00165         Expr            xpr;
00166         int                     paramkind;              /* kind of parameter. See above */
00167         AttrNumber      paramid;                /* numeric ID for parameter ("$1") */
00168         char       *paramname;          /* name for parameter ("$.foo") */
00169         Oid                     paramtype;              /* PG_TYPE OID of parameter's datatype */
00170 } Param;
00171 
00172 /*
00173  * Aggref
00174  */
00175 typedef struct Aggref
00176 {
00177         Expr            xpr;
00178         Oid                     aggfnoid;               /* pg_proc Oid of the aggregate */
00179         Oid                     aggtype;                /* type Oid of result of the aggregate */
00180         Expr       *target;                     /* expression we are aggregating on */
00181         Index           agglevelsup;    /* > 0 if agg belongs to outer query */
00182         bool            aggstar;                /* TRUE if argument was really '*' */
00183         bool            aggdistinct;    /* TRUE if it's agg(DISTINCT ...) */
00184 } Aggref;
00185 
00186 /* ----------------
00187  *      ArrayRef: describes an array subscripting operation
00188  *
00189  * An ArrayRef can describe fetching a single element from an array,
00190  * fetching a subarray (array slice), storing a single element into
00191  * an array, or storing a slice.  The "store" cases work with an
00192  * initial array value and a source value that is inserted into the
00193  * appropriate part of the array; the result of the operation is an
00194  * entire new modified array value.
00195  *
00196  * If reflowerindexpr = NIL, then we are fetching or storing a single array
00197  * element at the subscripts given by refupperindexpr.  Otherwise we are
00198  * fetching or storing an array slice, that is a rectangular subarray
00199  * with lower and upper bounds given by the index expressions.
00200  * reflowerindexpr must be the same length as refupperindexpr when it
00201  * is not NIL.
00202  *
00203  * Note: refrestype is NOT the element type, but the array type,
00204  * when doing subarray fetch or either type of store.
00205  * ----------------
00206  */
00207 typedef struct ArrayRef
00208 {
00209         Expr            xpr;
00210         Oid                     refrestype;             /* type of the result of the ArrayRef
00211                                                                  * operation */
00212         Oid                     refarraytype;   /* type of the array proper */
00213         Oid                     refelemtype;    /* type of the array elements */
00214         List       *refupperindexpr;/* expressions that evaluate to upper array
00215                                                                  * indexes */
00216         List       *reflowerindexpr;/* expressions that evaluate to lower array
00217                                                                  * indexes */
00218         Expr       *refexpr;            /* the expression that evaluates to an array
00219                                                                  * value */
00220         Expr       *refassgnexpr;       /* expression for the source value, or NULL if
00221                                                                  * fetch */
00222 } ArrayRef;
00223 
00224 /*
00225  * CoercionContext - distinguishes the allowed set of type casts
00226  *
00227  * NB: ordering of the alternatives is significant; later (larger) values
00228  * allow more casts than earlier ones.
00229  */
00230 typedef enum CoercionContext
00231 {
00232         COERCION_IMPLICIT,                      /* coercion in context of expression */
00233         COERCION_ASSIGNMENT,            /* coercion in context of assignment */
00234         COERCION_EXPLICIT                       /* explicit cast operation */
00235 } CoercionContext;
00236 
00237 /*
00238  * CoercionForm - information showing how to display a function-call node
00239  */
00240 typedef enum CoercionForm
00241 {
00242         COERCE_EXPLICIT_CALL,           /* display as a function call */
00243         COERCE_EXPLICIT_CAST,           /* display as an explicit cast */
00244         COERCE_IMPLICIT_CAST,           /* implicit cast, so hide it */
00245         COERCE_DONTCARE                         /* special case for planner */
00246 } CoercionForm;
00247 
00248 /*
00249  * FuncExpr - expression node for a function call
00250  */
00251 typedef struct FuncExpr
00252 {
00253         Expr            xpr;
00254         Oid                     funcid;                 /* PG_PROC OID of the function */
00255         Oid                     funcresulttype; /* PG_TYPE OID of result value */
00256         bool            funcretset;             /* true if function returns set */
00257         CoercionForm funcformat;        /* how to display this function call */
00258         List       *args;                       /* arguments to the function */
00259 } FuncExpr;
00260 
00261 /*
00262  * OpExpr - expression node for an operator invocation
00263  *
00264  * Semantically, this is essentially the same as a function call.
00265  *
00266  * Note that opfuncid is not necessarily filled in immediately on creation
00267  * of the node.  The planner makes sure it is valid before passing the node
00268  * tree to the executor, but during parsing/planning opfuncid is typically 0.
00269  */
00270 typedef struct OpExpr
00271 {
00272         Expr            xpr;
00273         Oid                     opno;                   /* PG_OPERATOR OID of the operator */
00274         Oid                     opfuncid;               /* PG_PROC OID of underlying function */
00275         Oid                     opresulttype;   /* PG_TYPE OID of result value */
00276         bool            opretset;               /* true if operator returns set */
00277         List       *args;                       /* arguments to the operator (1 or 2) */
00278 } OpExpr;
00279 
00280 /*
00281  * DistinctExpr - expression node for "x IS DISTINCT FROM y"
00282  *
00283  * Except for the nodetag, this is represented identically to an OpExpr
00284  * referencing the "=" operator for x and y.
00285  * We use "=", not the more obvious "<>", because more datatypes have "="
00286  * than "<>".  This means the executor must invert the operator result.
00287  * Note that the operator function won't be called at all if either input
00288  * is NULL, since then the result can be determined directly.
00289  */
00290 typedef OpExpr DistinctExpr;
00291 
00292 /*
00293  * ScalarArrayOpExpr - expression node for "scalar op ANY/ALL (array)"
00294  *
00295  * The operator must yield boolean.  It is applied to the left operand
00296  * and each element of the righthand array, and the results are combined
00297  * with OR or AND (for ANY or ALL respectively).  The node representation
00298  * is almost the same as for the underlying operator, but we need a useOr
00299  * flag to remember whether it's ANY or ALL, and we don't have to store
00300  * the result type because it must be boolean.
00301  */
00302 typedef struct ScalarArrayOpExpr
00303 {
00304         Expr            xpr;
00305         Oid                     opno;                   /* PG_OPERATOR OID of the operator */
00306         Oid                     opfuncid;               /* PG_PROC OID of underlying function */
00307         bool            useOr;                  /* true for ANY, false for ALL */
00308         List       *args;                       /* the scalar and array operands */
00309 } ScalarArrayOpExpr;
00310 
00311 /*
00312  * BoolExpr - expression node for the basic Boolean operators AND, OR, NOT
00313  *
00314  * Notice the arguments are given as a List.  For NOT, of course the list
00315  * must always have exactly one element.  For AND and OR, the executor can
00316  * handle any number of arguments.      The parser treats AND and OR as binary
00317  * and so it only produces two-element lists, but the optimizer will flatten
00318  * trees of AND and OR nodes to produce longer lists when possible.
00319  */
00320 typedef enum BoolExprType
00321 {
00322         AND_EXPR, OR_EXPR, NOT_EXPR
00323 } BoolExprType;
00324 
00325 typedef struct BoolExpr
00326 {
00327         Expr            xpr;
00328         BoolExprType boolop;
00329         List       *args;                       /* arguments to this expression */
00330 } BoolExpr;
00331 
00332 /* ----------------
00333  * SubLink
00334  *
00335  * A SubLink represents a subselect appearing in an expression, and in some
00336  * cases also the combining operator(s) just above it.  The subLinkType
00337  * indicates the form of the expression represented:
00338  *      EXISTS_SUBLINK          EXISTS(SELECT ...)
00339  *      ALL_SUBLINK                     (lefthand) op ALL (SELECT ...)
00340  *      ANY_SUBLINK                     (lefthand) op ANY (SELECT ...)
00341  *      MULTIEXPR_SUBLINK       (lefthand) op (SELECT ...)
00342  *      EXPR_SUBLINK            (SELECT with single targetlist item ...)
00343  *      ARRAY_SUBLINK           ARRAY(SELECT with single targetlist item ...)
00344  * For ALL, ANY, and MULTIEXPR, the lefthand is a list of expressions of the
00345  * same length as the subselect's targetlist.  MULTIEXPR will *always* have
00346  * a list with more than one entry; if the subselect has just one target
00347  * then the parser will create an EXPR_SUBLINK instead (and any operator
00348  * above the subselect will be represented separately).  Note that both
00349  * MULTIEXPR and EXPR require the subselect to deliver only one row.
00350  * ARRAY requires just one target column, and creates an array of the target
00351  * column's type using one or more rows resulting from the subselect.
00352  * ALL, ANY, and MULTIEXPR require the combining operators to deliver boolean
00353  * results.  These are reduced to one result per row using OR or AND semantics
00354  * depending on the "useOr" flag.  ALL and ANY combine the per-row results
00355  * using AND and OR semantics respectively.
00356  *
00357  * SubLink is classed as an Expr node, but it is not actually executable;
00358  * it must be replaced in the expression tree by a SubPlan node during
00359  * planning.
00360  *
00361  * NOTE: in the raw output of gram.y, lefthand contains a list of raw
00362  * expressions; useOr and operOids are not filled in yet.  Also, subselect
00363  * is a raw parsetree.  During parse analysis, the parser transforms the
00364  * lefthand expression list using normal expression transformation rules.
00365  * It fills operOids with the OIDs representing the specific operator(s)
00366  * to apply to each pair of lefthand and targetlist expressions.
00367  * And subselect is transformed to a Query.  This is the representation
00368  * seen in saved rules and in the rewriter.
00369  *
00370  * In EXISTS, EXPR, and ARRAY SubLinks, lefthand, operName, and operOids are
00371  * unused and are always NIL.  useOr is not significant either for these
00372  * sublink types.
00373  * ----------------
00374  */
00375 typedef enum SubLinkType
00376 {
00377         EXISTS_SUBLINK,
00378         ALL_SUBLINK,
00379         ANY_SUBLINK,
00380         MULTIEXPR_SUBLINK,
00381         EXPR_SUBLINK,
00382         ARRAY_SUBLINK
00383 } SubLinkType;
00384 
00385 
00386 typedef struct SubLink
00387 {
00388         Expr            xpr;
00389         SubLinkType subLinkType;        /* EXISTS, ALL, ANY, MULTIEXPR, EXPR */
00390         bool            useOr;                  /* TRUE to combine column results with "OR"
00391                                                                  * not "AND" */
00392         List       *lefthand;           /* list of outer-query expressions on the left */
00393         List       *operName;           /* originally specified operator name */
00394         List       *operOids;           /* OIDs of actual combining operators */
00395         Node       *subselect;          /* subselect as Query* or parsetree */
00396 } SubLink;
00397 
00398 /*
00399  * SubPlan - executable expression node for a subplan (sub-SELECT)
00400  *
00401  * The planner replaces SubLink nodes in expression trees with SubPlan
00402  * nodes after it has finished planning the subquery.  SubPlan contains
00403  * a sub-plantree and rtable instead of a sub-Query.
00404  *
00405  * In an ordinary subplan, "exprs" points to a list of executable expressions
00406  * (OpExpr trees) for the combining operators; their left-hand arguments are
00407  * the original lefthand expressions, and their right-hand arguments are
00408  * PARAM_EXEC Param nodes representing the outputs of the sub-select.
00409  * (NOTE: runtime coercion functions may be inserted as well.)  But if the
00410  * sub-select becomes an initplan rather than a subplan, these executable
00411  * expressions are part of the outer plan's expression tree (and the SubPlan
00412  * node itself is not).  In this case "exprs" is NIL to avoid duplication.
00413  *
00414  * The planner also derives lists of the values that need to be passed into
00415  * and out of the subplan.      Input values are represented as a list "args" of
00416  * expressions to be evaluated in the outer-query context (currently these
00417  * args are always just Vars, but in principle they could be any expression).
00418  * The values are assigned to the global PARAM_EXEC params indexed by parParam
00419  * (the parParam and args lists must have the same ordering).  setParam is a
00420  * list of the PARAM_EXEC params that are computed by the sub-select, if it
00421  * is an initplan; they are listed in order by sub-select output column
00422  * position.  (parParam and setParam are integer Lists, not Bitmapsets,
00423  * because their ordering is significant.)
00424  */
00425 typedef struct SubPlan
00426 {
00427         Expr            xpr;
00428         /* Fields copied from original SubLink: */
00429         SubLinkType subLinkType;        /* EXISTS, ALL, ANY, MULTIEXPR, EXPR */
00430         bool            useOr;                  /* TRUE to combine column results with "OR"
00431                                                                  * not "AND" */
00432         /* The combining operators, transformed to executable expressions: */
00433         List       *exprs;                      /* list of OpExpr expression trees */
00434         List       *paramIds;           /* IDs of Params embedded in the above */
00435         /* Note: paramIds has a one-to-one correspondence to the exprs list */
00436         /* The subselect, transformed to a Plan: */
00437         struct Plan *plan;                      /* subselect plan itself */
00438         int                     plan_id;                /* dummy thing because of we haven't equal
00439                                                                  * funcs for plan nodes... actually, we could
00440                                                                  * put *plan itself somewhere else (TopPlan
00441                                                                  * node ?)... */
00442         List       *rtable;                     /* range table for subselect */
00443         /* Information about execution strategy: */
00444         bool            useHashTable;   /* TRUE to store subselect output in a hash
00445                                                                  * table (implies we are doing "IN") */
00446         bool            unknownEqFalse; /* TRUE if it's okay to return FALSE when the
00447                                                                  * spec result is UNKNOWN; this allows much
00448                                                                  * simpler handling of null values */
00449         /* Information for passing params into and out of the subselect: */
00450         /* setParam and parParam are lists of integers (param IDs) */
00451         List       *setParam;           /* initplan subqueries have to set these
00452                                                                  * Params for parent plan */
00453         List       *parParam;           /* indices of input Params from parent plan */
00454         List       *args;                       /* exprs to pass as parParam values */
00455 } SubPlan;
00456 
00457 /* ----------------
00458  * FieldSelect
00459  *
00460  * FieldSelect represents the operation of extracting one field from a tuple
00461  * value.  At runtime, the input expression is expected to yield a rowtype
00462  * Datum.  The specified field number is extracted and returned as a Datum.
00463  * ----------------
00464  */
00465 
00466 typedef struct FieldSelect
00467 {
00468         Expr            xpr;
00469         Expr       *arg;                        /* input expression */
00470         AttrNumber      fieldnum;               /* attribute number of field to extract */
00471         Oid                     resulttype;             /* type of the field (result type of this
00472                                                                  * node) */
00473         int32           resulttypmod;   /* output typmod (usually -1) */
00474 } FieldSelect;
00475 
00476 /* ----------------
00477  * FieldStore
00478  *
00479  * FieldStore represents the operation of modifying one field in a tuple
00480  * value, yielding a new tuple value (the input is not touched!).  Like
00481  * the assign case of ArrayRef, this is used to implement UPDATE of a
00482  * portion of a column.
00483  *
00484  * A single FieldStore can actually represent updates of several different
00485  * fields.      The parser only generates FieldStores with single-element lists,
00486  * but the planner will collapse multiple updates of the same base column
00487  * into one FieldStore.
00488  * ----------------
00489  */
00490 
00491 typedef struct FieldStore
00492 {
00493         Expr            xpr;
00494         Expr       *arg;                        /* input tuple value */
00495         List       *newvals;            /* new value(s) for field(s) */
00496         List       *fieldnums;          /* integer list of field attnums */
00497         Oid                     resulttype;             /* type of result (same as type of arg) */
00498         /* Like RowExpr, we deliberately omit a typmod here */
00499 } FieldStore;
00500 
00501 /* ----------------
00502  * RelabelType
00503  *
00504  * RelabelType represents a "dummy" type coercion between two binary-
00505  * compatible datatypes, such as reinterpreting the result of an OID
00506  * expression as an int4.  It is a no-op at runtime; we only need it
00507  * to provide a place to store the correct type to be attributed to
00508  * the expression result during type resolution.  (We can't get away
00509  * with just overwriting the type field of the input expression node,
00510  * so we need a separate node to show the coercion's result type.)
00511  * ----------------
00512  */
00513 
00514 typedef struct RelabelType
00515 {
00516         Expr            xpr;
00517         Expr       *arg;                        /* input expression */
00518         Oid                     resulttype;             /* output type of coercion expression */
00519         int32           resulttypmod;   /* output typmod (usually -1) */
00520         CoercionForm relabelformat; /* how to display this node */
00521 } RelabelType;
00522 
00523 /* ----------------
00524  * ConvertRowtypeExpr
00525  *
00526  * ConvertRowtypeExpr represents a type coercion from one composite type
00527  * to another, where the source type is guaranteed to contain all the columns
00528  * needed for the destination type plus possibly others; the columns need not
00529  * be in the same positions, but are matched up by name.  This is primarily
00530  * used to convert a whole-row value of an inheritance child table into a
00531  * valid whole-row value of its parent table's rowtype.
00532  * ----------------
00533  */
00534 
00535 typedef struct ConvertRowtypeExpr
00536 {
00537         Expr            xpr;
00538         Expr       *arg;                        /* input expression */
00539         Oid                     resulttype;             /* output type (always a composite type) */
00540         /* result typmod is not stored, but must be -1; see RowExpr comments */
00541         CoercionForm convertformat; /* how to display this node */
00542 } ConvertRowtypeExpr;
00543 
00544 /*----------
00545  * CaseExpr - a CASE expression
00546  *
00547  * We support two distinct forms of CASE expression:
00548  *              CASE WHEN boolexpr THEN expr [ WHEN boolexpr THEN expr ... ]
00549  *              CASE testexpr WHEN compexpr THEN expr [ WHEN compexpr THEN expr ... ]
00550  * These are distinguishable by the "arg" field being NULL in the first case
00551  * and the testexpr in the second case.
00552  *
00553  * In the raw grammar output for the second form, the condition expressions
00554  * of the WHEN clauses are just the comparison values.  Parse analysis
00555  * converts these to valid boolean expressions of the form
00556  *              CaseTestExpr '=' compexpr
00557  * where the CaseTestExpr node is a placeholder that emits the correct
00558  * value at runtime.  This structure is used so that the testexpr need be
00559  * evaluated only once.  Note that after parse analysis, the condition
00560  * expressions always yield boolean.
00561  *
00562  * Note: we can test whether a CaseExpr has been through parse analysis
00563  * yet by checking whether casetype is InvalidOid or not.
00564  *----------
00565  */
00566 typedef struct CaseExpr
00567 {
00568         Expr            xpr;
00569         Oid                     casetype;               /* type of expression result */
00570         Expr       *arg;                        /* implicit equality comparison argument */
00571         List       *args;                       /* the arguments (list of WHEN clauses) */
00572         Expr       *defresult;          /* the default result (ELSE clause) */
00573 } CaseExpr;
00574 
00575 /*
00576  * CaseWhen - one arm of a CASE expression
00577  */
00578 typedef struct CaseWhen
00579 {
00580         Expr            xpr;
00581         Expr       *expr;                       /* condition expression */
00582         Expr       *result;                     /* substitution result */
00583 } CaseWhen;
00584 
00585 /*
00586  * Placeholder node for the test value to be processed by a CASE expression.
00587  * This is effectively like a Param, but can be implemented more simply
00588  * since we need only one replacement value at a time.
00589  *
00590  * We also use this in nested UPDATE expressions.
00591  * See transformAssignmentIndirection().
00592  */
00593 typedef struct CaseTestExpr
00594 {
00595         Expr            xpr;
00596         Oid                     typeId;                 /* type for substituted value */
00597         int32           typeMod;                /* typemod for substituted value */
00598 } CaseTestExpr;
00599 
00600 /*
00601  * ArrayExpr - an ARRAY[] expression
00602  *
00603  * Note: if multidims is false, the constituent expressions all yield the
00604  * scalar type identified by element_typeid.  If multidims is true, the
00605  * constituent expressions all yield arrays of element_typeid (ie, the same
00606  * type as array_typeid); at runtime we must check for compatible subscripts.
00607  */
00608 typedef struct ArrayExpr
00609 {
00610         Expr            xpr;
00611         Oid                     array_typeid;   /* type of expression result */
00612         Oid                     element_typeid; /* common type of array elements */
00613         List       *elements;           /* the array elements or sub-arrays */
00614         bool            multidims;              /* true if elements are sub-arrays */
00615 } ArrayExpr;
00616 
00617 /*
00618  * RowExpr - a ROW() expression
00619  *
00620  * Note: the list of fields must have a one-for-one correspondence with
00621  * physical fields of the associated rowtype, although it is okay for it
00622  * to be shorter than the rowtype.      That is, the N'th list element must
00623  * match up with the N'th physical field.  When the N'th physical field
00624  * is a dropped column (attisdropped) then the N'th list element can just
00625  * be a NULL constant.  (This case can only occur for named composite types,
00626  * not RECORD types, since those are built from the RowExpr itself rather
00627  * than vice versa.)  It is important not to assume that length(args) is
00628  * the same as the number of columns logically present in the rowtype.
00629  */
00630 typedef struct RowExpr
00631 {
00632         Expr            xpr;
00633         List       *args;                       /* the fields */
00634         Oid                     row_typeid;             /* RECORDOID or a composite type's ID */
00635 
00636         /*
00637          * Note: we deliberately do NOT store a typmod.  Although a typmod will be
00638          * associated with specific RECORD types at runtime, it will differ for
00639          * different backends, and so cannot safely be stored in stored
00640          * parsetrees.  We must assume typmod -1 for a RowExpr node.
00641          */
00642         CoercionForm row_format;        /* how to display this node */
00643 } RowExpr;
00644 
00645 /*
00646  * CoalesceExpr - a COALESCE expression
00647  */
00648 typedef struct CoalesceExpr
00649 {
00650         Expr            xpr;
00651         Oid                     coalescetype;   /* type of expression result */
00652         List       *args;                       /* the arguments */
00653 } CoalesceExpr;
00654 
00655 /*
00656  * MinMaxExpr - a GREATEST or LEAST function
00657  */
00658 typedef enum MinMaxOp
00659 {
00660         IS_GREATEST,
00661         IS_LEAST
00662 } MinMaxOp;
00663 
00664 typedef struct MinMaxExpr
00665 {
00666         Expr            xpr;
00667         Oid                     minmaxtype;             /* common type of arguments and result */
00668         MinMaxOp        op;                             /* function to execute */
00669         List       *args;                       /* the arguments */
00670 } MinMaxExpr;
00671 
00672 /*
00673  * NullIfExpr - a NULLIF expression
00674  *
00675  * Like DistinctExpr, this is represented the same as an OpExpr referencing
00676  * the "=" operator for x and y.
00677  */
00678 typedef OpExpr NullIfExpr;
00679 
00680 /* ----------------
00681  * NullTest
00682  *
00683  * NullTest represents the operation of testing a value for NULLness.
00684  * Currently, we only support scalar input values, but eventually a
00685  * row-constructor input should be supported.
00686  * The appropriate test is performed and returned as a boolean Datum.
00687  * ----------------
00688  */
00689 
00690 typedef enum NullTestType
00691 {
00692         IS_NULL, IS_NOT_NULL
00693 } NullTestType;
00694 
00695 typedef struct NullTest
00696 {
00697         Expr            xpr;
00698         Expr       *arg;                        /* input expression */
00699         NullTestType nulltesttype;      /* IS NULL, IS NOT NULL */
00700 } NullTest;
00701 
00702 /*
00703  * BooleanTest
00704  *
00705  * BooleanTest represents the operation of determining whether a boolean
00706  * is TRUE, FALSE, or UNKNOWN (ie, NULL).  All six meaningful combinations
00707  * are supported.  Note that a NULL input does *not* cause a NULL result.
00708  * The appropriate test is performed and returned as a boolean Datum.
00709  */
00710 
00711 typedef enum BoolTestType
00712 {
00713         IS_TRUE, IS_NOT_TRUE, IS_FALSE, IS_NOT_FALSE, IS_UNKNOWN, IS_NOT_UNKNOWN
00714 } BoolTestType;
00715 
00716 typedef struct BooleanTest
00717 {
00718         Expr            xpr;
00719         Expr       *arg;                        /* input expression */
00720         BoolTestType booltesttype;      /* test type */
00721 } BooleanTest;
00722 
00723 /*
00724  * CoerceToDomain
00725  *
00726  * CoerceToDomain represents the operation of coercing a value to a domain
00727  * type.  At runtime (and not before) the precise set of constraints to be
00728  * checked will be determined.  If the value passes, it is returned as the
00729  * result; if not, an error is raised.  Note that this is equivalent to
00730  * RelabelType in the scenario where no constraints are applied.
00731  */
00732 typedef struct CoerceToDomain
00733 {
00734         Expr            xpr;
00735         Expr       *arg;                        /* input expression */
00736         Oid                     resulttype;             /* domain type ID (result type) */
00737         int32           resulttypmod;   /* output typmod (currently always -1) */
00738         CoercionForm coercionformat;    /* how to display this node */
00739 } CoerceToDomain;
00740 
00741 /*
00742  * Placeholder node for the value to be processed by a domain's check
00743  * constraint.  This is effectively like a Param, but can be implemented more
00744  * simply since we need only one replacement value at a time.
00745  *
00746  * Note: the typeId/typeMod will be set from the domain's base type, not
00747  * the domain itself.  This is because we shouldn't consider the value to
00748  * be a member of the domain if we haven't yet checked its constraints.
00749  */
00750 typedef struct CoerceToDomainValue
00751 {
00752         Expr            xpr;
00753         Oid                     typeId;                 /* type for substituted value */
00754         int32           typeMod;                /* typemod for substituted value */
00755 } CoerceToDomainValue;
00756 
00757 /*
00758  * Placeholder node for a DEFAULT marker in an INSERT or UPDATE command.
00759  *
00760  * This is not an executable expression: it must be replaced by the actual
00761  * column default expression during rewriting.  But it is convenient to
00762  * treat it as an expression node during parsing and rewriting.
00763  */
00764 typedef struct SetToDefault
00765 {
00766         Expr            xpr;
00767         Oid                     typeId;                 /* type for substituted value */
00768         int32           typeMod;                /* typemod for substituted value */
00769 } SetToDefault;
00770 
00771 /*--------------------
00772  * TargetEntry -
00773  *         a target entry (used in query target lists)
00774  *
00775  * Strictly speaking, a TargetEntry isn't an expression node (since it can't
00776  * be evaluated by ExecEvalExpr).  But we treat it as one anyway, since in
00777  * very many places it's convenient to process a whole query targetlist as a
00778  * single expression tree.
00779  *
00780  * In a SELECT's targetlist, resno should always be equal to the item's
00781  * ordinal position (counting from 1).  However, in an INSERT or UPDATE
00782  * targetlist, resno represents the attribute number of the destination
00783  * column for the item; so there may be missing or out-of-order resnos.
00784  * It is even legal to have duplicated resnos; consider
00785  *              UPDATE table SET arraycol[1] = ..., arraycol[2] = ..., ...
00786  * The two meanings come together in the executor, because the planner
00787  * transforms INSERT/UPDATE tlists into a normalized form with exactly
00788  * one entry for each column of the destination table.  Before that's
00789  * happened, however, it is risky to assume that resno == position.
00790  * Generally get_tle_by_resno() should be used rather than list_nth()
00791  * to fetch tlist entries by resno, and only in SELECT should you assume
00792  * that resno is a unique identifier.
00793  *
00794  * resname is required to represent the correct column name in non-resjunk
00795  * entries of top-level SELECT targetlists, since it will be used as the
00796  * column title sent to the frontend.  In most other contexts it is only
00797  * a debugging aid, and may be wrong or even NULL.      (In particular, it may
00798  * be wrong in a tlist from a stored rule, if the referenced column has been
00799  * renamed by ALTER TABLE since the rule was made.      Also, the planner tends
00800  * to store NULL rather than look up a valid name for tlist entries in
00801  * non-toplevel plan nodes.)  In resjunk entries, resname should be either
00802  * a specific system-generated name (such as "ctid") or NULL; anything else
00803  * risks confusing ExecGetJunkAttribute!
00804  *
00805  * ressortgroupref is used in the representation of ORDER BY and
00806  * GROUP BY items.      Targetlist entries with ressortgroupref=0 are not
00807  * sort/group items.  If ressortgroupref>0, then this item is an ORDER BY or
00808  * GROUP BY value.      No two entries in a targetlist may have the same nonzero
00809  * ressortgroupref --- but there is no particular meaning to the nonzero
00810  * values, except as tags.      (For example, one must not assume that lower
00811  * ressortgroupref means a more significant sort key.)  The order of the
00812  * associated SortClause or GroupClause lists determine the semantics.
00813  *
00814  * resorigtbl/resorigcol identify the source of the column, if it is a
00815  * simple reference to a column of a base table (or view).      If it is not
00816  * a simple reference, these fields are zeroes.
00817  *
00818  * If resjunk is true then the column is a working column (such as a sort key)
00819  * that should be removed from the final output of the query.  Resjunk columns
00820  * must have resnos that cannot duplicate any regular column's resno.  Also
00821  * note that there are places that assume resjunk columns come after non-junk
00822  * columns.
00823  *--------------------
00824  */
00825 typedef struct TargetEntry
00826 {
00827         Expr            xpr;
00828         Expr       *expr;                       /* expression to evaluate */
00829         AttrNumber      resno;                  /* attribute number (see notes above) */
00830         char       *resname;            /* name of the column (could be NULL) */
00831         Index           ressortgroupref;/* nonzero if referenced by a sort/group
00832                                                                  * clause */
00833         Oid                     resorigtbl;             /* OID of column's source table */
00834         AttrNumber      resorigcol;             /* column's number in source table */
00835         bool            resjunk;                /* set to true to eliminate the attribute from
00836                                                                  * final target list */
00837 } TargetEntry;
00838 
00839 
00840 /* ----------------------------------------------------------------
00841  *                                      node types for join trees
00842  *
00843  * The leaves of a join tree structure are RangeTblRef nodes.  Above
00844  * these, JoinExpr nodes can appear to denote a specific kind of join
00845  * or qualified join.  Also, FromExpr nodes can appear to denote an
00846  * ordinary cross-product join ("FROM foo, bar, baz WHERE ...").
00847  * FromExpr is like a JoinExpr of jointype JOIN_INNER, except that it
00848  * may have any number of child nodes, not just two.  Also, there is an
00849  * implementation-defined difference: the planner is allowed to join the
00850  * children of a FromExpr using whatever join order seems good to it.
00851  * At present, JoinExpr nodes are always joined in exactly the order
00852  * implied by the jointree structure (except the planner may choose to
00853  * swap inner and outer members of a join pair).
00854  *
00855  * NOTE: the top level of a Query's jointree is always a FromExpr.
00856  * Even if the jointree contains no rels, there will be a FromExpr.
00857  *
00858  * NOTE: the qualification expressions present in JoinExpr nodes are
00859  * *in addition to* the query's main WHERE clause, which appears as the
00860  * qual of the top-level FromExpr.      The reason for associating quals with
00861  * specific nodes in the jointree is that the position of a qual is critical
00862  * when outer joins are present.  (If we enforce a qual too soon or too late,
00863  * that may cause the outer join to produce the wrong set of NULL-extended
00864  * rows.)  If all joins are inner joins then all the qual positions are
00865  * semantically interchangeable.
00866  *
00867  * NOTE: in the raw output of gram.y, a join tree contains RangeVar,
00868  * RangeSubselect, and RangeFunction nodes, which are all replaced by
00869  * RangeTblRef nodes during the parse analysis phase.  Also, the top-level
00870  * FromExpr is added during parse analysis; the grammar regards FROM and
00871  * WHERE as separate.
00872  * ----------------------------------------------------------------
00873  */
00874 
00875 /*
00876  * RangeTblRef - reference to an entry in the query's rangetable
00877  *
00878  * We could use direct pointers to the RT entries and skip having these
00879  * nodes, but multiple pointers to the same node in a querytree cause
00880  * lots of headaches, so it seems better to store an index into the RT.
00881  */
00882 typedef struct RangeTblRef
00883 {
00884         NodeTag         type;
00885         int                     rtindex;
00886 } RangeTblRef;
00887 
00888 /*----------
00889  * JoinExpr - for SQL JOIN expressions
00890  *
00891  * isNatural, using, and quals are interdependent.      The user can write only
00892  * one of NATURAL, USING(), or ON() (this is enforced by the grammar).
00893  * If he writes NATURAL then parse analysis generates the equivalent USING()
00894  * list, and from that fills in "quals" with the right equality comparisons.
00895  * If he writes USING() then "quals" is filled with equality comparisons.
00896  * If he writes ON() then only "quals" is set.  Note that NATURAL/USING
00897  * are not equivalent to ON() since they also affect the output column list.
00898  *
00899  * alias is an Alias node representing the AS alias-clause attached to the
00900  * join expression, or NULL if no clause.  NB: presence or absence of the
00901  * alias has a critical impact on semantics, because a join with an alias
00902  * restricts visibility of the tables/columns inside it.
00903  *
00904  * During parse analysis, an RTE is created for the Join, and its index
00905  * is filled into rtindex.      This RTE is present mainly so that Vars can
00906  * be created that refer to the outputs of the join.
00907  *----------
00908  */
00909 typedef struct JoinExpr
00910 {
00911         NodeTag         type;
00912         JoinType        jointype;               /* type of join */
00913         bool            isNatural;              /* Natural join? Will need to shape table */
00914         Node       *larg;                       /* left subtree */
00915         Node       *rarg;                       /* right subtree */
00916         List       *using;                      /* USING clause, if any (list of String) */
00917         Node       *quals;                      /* qualifiers on join, if any */
00918         Alias      *alias;                      /* user-written alias clause, if any */
00919         int                     rtindex;                /* RT index assigned for join */
00920 } JoinExpr;
00921 
00922 /*----------
00923  * FromExpr - represents a FROM ... WHERE ... construct
00924  *
00925  * This is both more flexible than a JoinExpr (it can have any number of
00926  * children, including zero) and less so --- we don't need to deal with
00927  * aliases and so on.  The output column set is implicitly just the union
00928  * of the outputs of the children.
00929  *----------
00930  */
00931 typedef struct FromExpr
00932 {
00933         NodeTag         type;
00934         List       *fromlist;           /* List of join subtrees */
00935         Node       *quals;                      /* qualifiers on join, if any */
00936 } FromExpr;
00937 
00938 #endif   /* PRIMNODES_H */
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'