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-2013, PostgreSQL Global Development Group 00011 * Portions Copyright (c) 1994, Regents of the University of California 00012 * 00013 * src/include/nodes/primnodes.h 00014 * 00015 *------------------------------------------------------------------------- 00016 */ 00017 #ifndef PRIMNODES_H 00018 #define PRIMNODES_H 00019 00020 #include "access/attnum.h" 00021 #include "nodes/pg_list.h" 00022 00023 00024 /* ---------------------------------------------------------------- 00025 * node definitions 00026 * ---------------------------------------------------------------- 00027 */ 00028 00029 /* 00030 * Alias - 00031 * specifies an alias for a range variable; the alias might also 00032 * specify renaming of columns within the table. 00033 * 00034 * Note: colnames is a list of Value nodes (always strings). In Alias structs 00035 * associated with RTEs, there may be entries corresponding to dropped 00036 * columns; these are normally empty strings (""). See parsenodes.h for info. 00037 */ 00038 typedef struct Alias 00039 { 00040 NodeTag type; 00041 char *aliasname; /* aliased rel name (never qualified) */ 00042 List *colnames; /* optional list of column aliases */ 00043 } Alias; 00044 00045 typedef enum InhOption 00046 { 00047 INH_NO, /* Do NOT scan child tables */ 00048 INH_YES, /* DO scan child tables */ 00049 INH_DEFAULT /* Use current SQL_inheritance option */ 00050 } InhOption; 00051 00052 /* What to do at commit time for temporary relations */ 00053 typedef enum OnCommitAction 00054 { 00055 ONCOMMIT_NOOP, /* No ON COMMIT clause (do nothing) */ 00056 ONCOMMIT_PRESERVE_ROWS, /* ON COMMIT PRESERVE ROWS (do nothing) */ 00057 ONCOMMIT_DELETE_ROWS, /* ON COMMIT DELETE ROWS */ 00058 ONCOMMIT_DROP /* ON COMMIT DROP */ 00059 } OnCommitAction; 00060 00061 /* 00062 * RangeVar - range variable, used in FROM clauses 00063 * 00064 * Also used to represent table names in utility statements; there, the alias 00065 * field is not used, and inhOpt shows whether to apply the operation 00066 * recursively to child tables. In some contexts it is also useful to carry 00067 * a TEMP table indication here. 00068 */ 00069 typedef struct RangeVar 00070 { 00071 NodeTag type; 00072 char *catalogname; /* the catalog (database) name, or NULL */ 00073 char *schemaname; /* the schema name, or NULL */ 00074 char *relname; /* the relation/sequence name */ 00075 InhOption inhOpt; /* expand rel by inheritance? recursively act 00076 * on children? */ 00077 char relpersistence; /* see RELPERSISTENCE_* in pg_class.h */ 00078 Alias *alias; /* table alias & optional column aliases */ 00079 int location; /* token location, or -1 if unknown */ 00080 } RangeVar; 00081 00082 /* 00083 * IntoClause - target information for SELECT INTO, CREATE TABLE AS, and 00084 * CREATE MATERIALIZED VIEW 00085 * 00086 * For CREATE MATERIALIZED VIEW, viewQuery is the parsed-but-not-rewritten 00087 * SELECT Query for the view; otherwise it's NULL. (Although it's actually 00088 * Query*, we declare it as Node* to avoid a forward reference.) 00089 */ 00090 typedef struct IntoClause 00091 { 00092 NodeTag type; 00093 00094 RangeVar *rel; /* target relation name */ 00095 List *colNames; /* column names to assign, or NIL */ 00096 List *options; /* options from WITH clause */ 00097 OnCommitAction onCommit; /* what do we do at COMMIT? */ 00098 char *tableSpaceName; /* table space to use, or NULL */ 00099 Node *viewQuery; /* materialized view's SELECT query */ 00100 bool skipData; /* true for WITH NO DATA */ 00101 } IntoClause; 00102 00103 00104 /* ---------------------------------------------------------------- 00105 * node types for executable expressions 00106 * ---------------------------------------------------------------- 00107 */ 00108 00109 /* 00110 * Expr - generic superclass for executable-expression nodes 00111 * 00112 * All node types that are used in executable expression trees should derive 00113 * from Expr (that is, have Expr as their first field). Since Expr only 00114 * contains NodeTag, this is a formality, but it is an easy form of 00115 * documentation. See also the ExprState node types in execnodes.h. 00116 */ 00117 typedef struct Expr 00118 { 00119 NodeTag type; 00120 } Expr; 00121 00122 /* 00123 * Var - expression node representing a variable (ie, a table column) 00124 * 00125 * Note: during parsing/planning, varnoold/varoattno are always just copies 00126 * of varno/varattno. At the tail end of planning, Var nodes appearing in 00127 * upper-level plan nodes are reassigned to point to the outputs of their 00128 * subplans; for example, in a join node varno becomes INNER_VAR or OUTER_VAR 00129 * and varattno becomes the index of the proper element of that subplan's 00130 * target list. But varnoold/varoattno continue to hold the original values. 00131 * The code doesn't really need varnoold/varoattno, but they are very useful 00132 * for debugging and interpreting completed plans, so we keep them around. 00133 */ 00134 #define INNER_VAR 65000 /* reference to inner subplan */ 00135 #define OUTER_VAR 65001 /* reference to outer subplan */ 00136 #define INDEX_VAR 65002 /* reference to index column */ 00137 00138 #define IS_SPECIAL_VARNO(varno) ((varno) >= INNER_VAR) 00139 00140 /* Symbols for the indexes of the special RTE entries in rules */ 00141 #define PRS2_OLD_VARNO 1 00142 #define PRS2_NEW_VARNO 2 00143 00144 typedef struct Var 00145 { 00146 Expr xpr; 00147 Index varno; /* index of this var's relation in the range 00148 * table, or INNER_VAR/OUTER_VAR/INDEX_VAR */ 00149 AttrNumber varattno; /* attribute number of this var, or zero for 00150 * all */ 00151 Oid vartype; /* pg_type OID for the type of this var */ 00152 int32 vartypmod; /* pg_attribute typmod value */ 00153 Oid varcollid; /* OID of collation, or InvalidOid if none */ 00154 Index varlevelsup; /* for subquery variables referencing outer 00155 * relations; 0 in a normal var, >0 means N 00156 * levels up */ 00157 Index varnoold; /* original value of varno, for debugging */ 00158 AttrNumber varoattno; /* original value of varattno */ 00159 int location; /* token location, or -1 if unknown */ 00160 } Var; 00161 00162 /* 00163 * Const 00164 */ 00165 typedef struct Const 00166 { 00167 Expr xpr; 00168 Oid consttype; /* pg_type OID of the constant's datatype */ 00169 int32 consttypmod; /* typmod value, if any */ 00170 Oid constcollid; /* OID of collation, or InvalidOid if none */ 00171 int constlen; /* typlen of the constant's datatype */ 00172 Datum constvalue; /* the constant's value */ 00173 bool constisnull; /* whether the constant is null (if true, 00174 * constvalue is undefined) */ 00175 bool constbyval; /* whether this datatype is passed by value. 00176 * If true, then all the information is stored 00177 * in the Datum. If false, then the Datum 00178 * contains a pointer to the information. */ 00179 int location; /* token location, or -1 if unknown */ 00180 } Const; 00181 00182 /* ---------------- 00183 * Param 00184 * paramkind - specifies the kind of parameter. The possible values 00185 * for this field are: 00186 * 00187 * PARAM_EXTERN: The parameter value is supplied from outside the plan. 00188 * Such parameters are numbered from 1 to n. 00189 * 00190 * PARAM_EXEC: The parameter is an internal executor parameter, used 00191 * for passing values into and out of sub-queries or from 00192 * nestloop joins to their inner scans. 00193 * For historical reasons, such parameters are numbered from 0. 00194 * These numbers are independent of PARAM_EXTERN numbers. 00195 * 00196 * PARAM_SUBLINK: The parameter represents an output column of a SubLink 00197 * node's sub-select. The column number is contained in the 00198 * `paramid' field. (This type of Param is converted to 00199 * PARAM_EXEC during planning.) 00200 * 00201 * Note: currently, paramtypmod is valid for PARAM_SUBLINK Params, and for 00202 * PARAM_EXEC Params generated from them; it is always -1 for PARAM_EXTERN 00203 * params, since the APIs that supply values for such parameters don't carry 00204 * any typmod info. 00205 * ---------------- 00206 */ 00207 typedef enum ParamKind 00208 { 00209 PARAM_EXTERN, 00210 PARAM_EXEC, 00211 PARAM_SUBLINK 00212 } ParamKind; 00213 00214 typedef struct Param 00215 { 00216 Expr xpr; 00217 ParamKind paramkind; /* kind of parameter. See above */ 00218 int paramid; /* numeric ID for parameter */ 00219 Oid paramtype; /* pg_type OID of parameter's datatype */ 00220 int32 paramtypmod; /* typmod value, if known */ 00221 Oid paramcollid; /* OID of collation, or InvalidOid if none */ 00222 int location; /* token location, or -1 if unknown */ 00223 } Param; 00224 00225 /* 00226 * Aggref 00227 * 00228 * The aggregate's args list is a targetlist, ie, a list of TargetEntry nodes 00229 * (before Postgres 9.0 it was just bare expressions). The non-resjunk TLEs 00230 * represent the aggregate's regular arguments (if any) and resjunk TLEs can 00231 * be added at the end to represent ORDER BY expressions that are not also 00232 * arguments. As in a top-level Query, the TLEs can be marked with 00233 * ressortgroupref indexes to let them be referenced by SortGroupClause 00234 * entries in the aggorder and/or aggdistinct lists. This represents ORDER BY 00235 * and DISTINCT operations to be applied to the aggregate input rows before 00236 * they are passed to the transition function. The grammar only allows a 00237 * simple "DISTINCT" specifier for the arguments, but we use the full 00238 * query-level representation to allow more code sharing. 00239 */ 00240 typedef struct Aggref 00241 { 00242 Expr xpr; 00243 Oid aggfnoid; /* pg_proc Oid of the aggregate */ 00244 Oid aggtype; /* type Oid of result of the aggregate */ 00245 Oid aggcollid; /* OID of collation of result */ 00246 Oid inputcollid; /* OID of collation that function should use */ 00247 List *args; /* arguments and sort expressions */ 00248 List *aggorder; /* ORDER BY (list of SortGroupClause) */ 00249 List *aggdistinct; /* DISTINCT (list of SortGroupClause) */ 00250 bool aggstar; /* TRUE if argument list was really '*' */ 00251 Index agglevelsup; /* > 0 if agg belongs to outer query */ 00252 int location; /* token location, or -1 if unknown */ 00253 } Aggref; 00254 00255 /* 00256 * WindowFunc 00257 */ 00258 typedef struct WindowFunc 00259 { 00260 Expr xpr; 00261 Oid winfnoid; /* pg_proc Oid of the function */ 00262 Oid wintype; /* type Oid of result of the window function */ 00263 Oid wincollid; /* OID of collation of result */ 00264 Oid inputcollid; /* OID of collation that function should use */ 00265 List *args; /* arguments to the window function */ 00266 Index winref; /* index of associated WindowClause */ 00267 bool winstar; /* TRUE if argument list was really '*' */ 00268 bool winagg; /* is function a simple aggregate? */ 00269 int location; /* token location, or -1 if unknown */ 00270 } WindowFunc; 00271 00272 /* ---------------- 00273 * ArrayRef: describes an array subscripting operation 00274 * 00275 * An ArrayRef can describe fetching a single element from an array, 00276 * fetching a subarray (array slice), storing a single element into 00277 * an array, or storing a slice. The "store" cases work with an 00278 * initial array value and a source value that is inserted into the 00279 * appropriate part of the array; the result of the operation is an 00280 * entire new modified array value. 00281 * 00282 * If reflowerindexpr = NIL, then we are fetching or storing a single array 00283 * element at the subscripts given by refupperindexpr. Otherwise we are 00284 * fetching or storing an array slice, that is a rectangular subarray 00285 * with lower and upper bounds given by the index expressions. 00286 * reflowerindexpr must be the same length as refupperindexpr when it 00287 * is not NIL. 00288 * 00289 * Note: the result datatype is the element type when fetching a single 00290 * element; but it is the array type when doing subarray fetch or either 00291 * type of store. 00292 * ---------------- 00293 */ 00294 typedef struct ArrayRef 00295 { 00296 Expr xpr; 00297 Oid refarraytype; /* type of the array proper */ 00298 Oid refelemtype; /* type of the array elements */ 00299 int32 reftypmod; /* typmod of the array (and elements too) */ 00300 Oid refcollid; /* OID of collation, or InvalidOid if none */ 00301 List *refupperindexpr;/* expressions that evaluate to upper array 00302 * indexes */ 00303 List *reflowerindexpr;/* expressions that evaluate to lower array 00304 * indexes */ 00305 Expr *refexpr; /* the expression that evaluates to an array 00306 * value */ 00307 Expr *refassgnexpr; /* expression for the source value, or NULL if 00308 * fetch */ 00309 } ArrayRef; 00310 00311 /* 00312 * CoercionContext - distinguishes the allowed set of type casts 00313 * 00314 * NB: ordering of the alternatives is significant; later (larger) values 00315 * allow more casts than earlier ones. 00316 */ 00317 typedef enum CoercionContext 00318 { 00319 COERCION_IMPLICIT, /* coercion in context of expression */ 00320 COERCION_ASSIGNMENT, /* coercion in context of assignment */ 00321 COERCION_EXPLICIT /* explicit cast operation */ 00322 } CoercionContext; 00323 00324 /* 00325 * CoercionForm - how to display a node that could have come from a cast 00326 * 00327 * NB: equal() ignores CoercionForm fields, therefore this *must* not carry 00328 * any semantically significant information. We need that behavior so that 00329 * the planner will consider equivalent implicit and explicit casts to be 00330 * equivalent. In cases where those actually behave differently, the coercion 00331 * function's arguments will be different. 00332 */ 00333 typedef enum CoercionForm 00334 { 00335 COERCE_EXPLICIT_CALL, /* display as a function call */ 00336 COERCE_EXPLICIT_CAST, /* display as an explicit cast */ 00337 COERCE_IMPLICIT_CAST /* implicit cast, so hide it */ 00338 } CoercionForm; 00339 00340 /* 00341 * FuncExpr - expression node for a function call 00342 */ 00343 typedef struct FuncExpr 00344 { 00345 Expr xpr; 00346 Oid funcid; /* PG_PROC OID of the function */ 00347 Oid funcresulttype; /* PG_TYPE OID of result value */ 00348 bool funcretset; /* true if function returns set */ 00349 bool funcvariadic; /* true if VARIADIC was used in call */ 00350 CoercionForm funcformat; /* how to display this function call */ 00351 Oid funccollid; /* OID of collation of result */ 00352 Oid inputcollid; /* OID of collation that function should use */ 00353 List *args; /* arguments to the function */ 00354 int location; /* token location, or -1 if unknown */ 00355 } FuncExpr; 00356 00357 /* 00358 * NamedArgExpr - a named argument of a function 00359 * 00360 * This node type can only appear in the args list of a FuncCall or FuncExpr 00361 * node. We support pure positional call notation (no named arguments), 00362 * named notation (all arguments are named), and mixed notation (unnamed 00363 * arguments followed by named ones). 00364 * 00365 * Parse analysis sets argnumber to the positional index of the argument, 00366 * but doesn't rearrange the argument list. 00367 * 00368 * The planner will convert argument lists to pure positional notation 00369 * during expression preprocessing, so execution never sees a NamedArgExpr. 00370 */ 00371 typedef struct NamedArgExpr 00372 { 00373 Expr xpr; 00374 Expr *arg; /* the argument expression */ 00375 char *name; /* the name */ 00376 int argnumber; /* argument's number in positional notation */ 00377 int location; /* argument name location, or -1 if unknown */ 00378 } NamedArgExpr; 00379 00380 /* 00381 * OpExpr - expression node for an operator invocation 00382 * 00383 * Semantically, this is essentially the same as a function call. 00384 * 00385 * Note that opfuncid is not necessarily filled in immediately on creation 00386 * of the node. The planner makes sure it is valid before passing the node 00387 * tree to the executor, but during parsing/planning opfuncid can be 0. 00388 */ 00389 typedef struct OpExpr 00390 { 00391 Expr xpr; 00392 Oid opno; /* PG_OPERATOR OID of the operator */ 00393 Oid opfuncid; /* PG_PROC OID of underlying function */ 00394 Oid opresulttype; /* PG_TYPE OID of result value */ 00395 bool opretset; /* true if operator returns set */ 00396 Oid opcollid; /* OID of collation of result */ 00397 Oid inputcollid; /* OID of collation that operator should use */ 00398 List *args; /* arguments to the operator (1 or 2) */ 00399 int location; /* token location, or -1 if unknown */ 00400 } OpExpr; 00401 00402 /* 00403 * DistinctExpr - expression node for "x IS DISTINCT FROM y" 00404 * 00405 * Except for the nodetag, this is represented identically to an OpExpr 00406 * referencing the "=" operator for x and y. 00407 * We use "=", not the more obvious "<>", because more datatypes have "=" 00408 * than "<>". This means the executor must invert the operator result. 00409 * Note that the operator function won't be called at all if either input 00410 * is NULL, since then the result can be determined directly. 00411 */ 00412 typedef OpExpr DistinctExpr; 00413 00414 /* 00415 * NullIfExpr - a NULLIF expression 00416 * 00417 * Like DistinctExpr, this is represented the same as an OpExpr referencing 00418 * the "=" operator for x and y. 00419 */ 00420 typedef OpExpr NullIfExpr; 00421 00422 /* 00423 * ScalarArrayOpExpr - expression node for "scalar op ANY/ALL (array)" 00424 * 00425 * The operator must yield boolean. It is applied to the left operand 00426 * and each element of the righthand array, and the results are combined 00427 * with OR or AND (for ANY or ALL respectively). The node representation 00428 * is almost the same as for the underlying operator, but we need a useOr 00429 * flag to remember whether it's ANY or ALL, and we don't have to store 00430 * the result type (or the collation) because it must be boolean. 00431 */ 00432 typedef struct ScalarArrayOpExpr 00433 { 00434 Expr xpr; 00435 Oid opno; /* PG_OPERATOR OID of the operator */ 00436 Oid opfuncid; /* PG_PROC OID of underlying function */ 00437 bool useOr; /* true for ANY, false for ALL */ 00438 Oid inputcollid; /* OID of collation that operator should use */ 00439 List *args; /* the scalar and array operands */ 00440 int location; /* token location, or -1 if unknown */ 00441 } ScalarArrayOpExpr; 00442 00443 /* 00444 * BoolExpr - expression node for the basic Boolean operators AND, OR, NOT 00445 * 00446 * Notice the arguments are given as a List. For NOT, of course the list 00447 * must always have exactly one element. For AND and OR, the executor can 00448 * handle any number of arguments. The parser generally treats AND and OR 00449 * as binary and so it typically only produces two-element lists, but the 00450 * optimizer will flatten trees of AND and OR nodes to produce longer lists 00451 * when possible. There are also a few special cases where more arguments 00452 * can appear before optimization. 00453 */ 00454 typedef enum BoolExprType 00455 { 00456 AND_EXPR, OR_EXPR, NOT_EXPR 00457 } BoolExprType; 00458 00459 typedef struct BoolExpr 00460 { 00461 Expr xpr; 00462 BoolExprType boolop; 00463 List *args; /* arguments to this expression */ 00464 int location; /* token location, or -1 if unknown */ 00465 } BoolExpr; 00466 00467 /* 00468 * SubLink 00469 * 00470 * A SubLink represents a subselect appearing in an expression, and in some 00471 * cases also the combining operator(s) just above it. The subLinkType 00472 * indicates the form of the expression represented: 00473 * EXISTS_SUBLINK EXISTS(SELECT ...) 00474 * ALL_SUBLINK (lefthand) op ALL (SELECT ...) 00475 * ANY_SUBLINK (lefthand) op ANY (SELECT ...) 00476 * ROWCOMPARE_SUBLINK (lefthand) op (SELECT ...) 00477 * EXPR_SUBLINK (SELECT with single targetlist item ...) 00478 * ARRAY_SUBLINK ARRAY(SELECT with single targetlist item ...) 00479 * CTE_SUBLINK WITH query (never actually part of an expression) 00480 * For ALL, ANY, and ROWCOMPARE, the lefthand is a list of expressions of the 00481 * same length as the subselect's targetlist. ROWCOMPARE will *always* have 00482 * a list with more than one entry; if the subselect has just one target 00483 * then the parser will create an EXPR_SUBLINK instead (and any operator 00484 * above the subselect will be represented separately). Note that both 00485 * ROWCOMPARE and EXPR require the subselect to deliver only one row. 00486 * ALL, ANY, and ROWCOMPARE require the combining operators to deliver boolean 00487 * results. ALL and ANY combine the per-row results using AND and OR 00488 * semantics respectively. 00489 * ARRAY requires just one target column, and creates an array of the target 00490 * column's type using any number of rows resulting from the subselect. 00491 * 00492 * SubLink is classed as an Expr node, but it is not actually executable; 00493 * it must be replaced in the expression tree by a SubPlan node during 00494 * planning. 00495 * 00496 * NOTE: in the raw output of gram.y, testexpr contains just the raw form 00497 * of the lefthand expression (if any), and operName is the String name of 00498 * the combining operator. Also, subselect is a raw parsetree. During parse 00499 * analysis, the parser transforms testexpr into a complete boolean expression 00500 * that compares the lefthand value(s) to PARAM_SUBLINK nodes representing the 00501 * output columns of the subselect. And subselect is transformed to a Query. 00502 * This is the representation seen in saved rules and in the rewriter. 00503 * 00504 * In EXISTS, EXPR, and ARRAY SubLinks, testexpr and operName are unused and 00505 * are always null. 00506 * 00507 * The CTE_SUBLINK case never occurs in actual SubLink nodes, but it is used 00508 * in SubPlans generated for WITH subqueries. 00509 */ 00510 typedef enum SubLinkType 00511 { 00512 EXISTS_SUBLINK, 00513 ALL_SUBLINK, 00514 ANY_SUBLINK, 00515 ROWCOMPARE_SUBLINK, 00516 EXPR_SUBLINK, 00517 ARRAY_SUBLINK, 00518 CTE_SUBLINK /* for SubPlans only */ 00519 } SubLinkType; 00520 00521 00522 typedef struct SubLink 00523 { 00524 Expr xpr; 00525 SubLinkType subLinkType; /* see above */ 00526 Node *testexpr; /* outer-query test for ALL/ANY/ROWCOMPARE */ 00527 List *operName; /* originally specified operator name */ 00528 Node *subselect; /* subselect as Query* or parsetree */ 00529 int location; /* token location, or -1 if unknown */ 00530 } SubLink; 00531 00532 /* 00533 * SubPlan - executable expression node for a subplan (sub-SELECT) 00534 * 00535 * The planner replaces SubLink nodes in expression trees with SubPlan 00536 * nodes after it has finished planning the subquery. SubPlan references 00537 * a sub-plantree stored in the subplans list of the toplevel PlannedStmt. 00538 * (We avoid a direct link to make it easier to copy expression trees 00539 * without causing multiple processing of the subplan.) 00540 * 00541 * In an ordinary subplan, testexpr points to an executable expression 00542 * (OpExpr, an AND/OR tree of OpExprs, or RowCompareExpr) for the combining 00543 * operator(s); the left-hand arguments are the original lefthand expressions, 00544 * and the right-hand arguments are PARAM_EXEC Param nodes representing the 00545 * outputs of the sub-select. (NOTE: runtime coercion functions may be 00546 * inserted as well.) This is just the same expression tree as testexpr in 00547 * the original SubLink node, but the PARAM_SUBLINK nodes are replaced by 00548 * suitably numbered PARAM_EXEC nodes. 00549 * 00550 * If the sub-select becomes an initplan rather than a subplan, the executable 00551 * expression is part of the outer plan's expression tree (and the SubPlan 00552 * node itself is not, but rather is found in the outer plan's initPlan 00553 * list). In this case testexpr is NULL to avoid duplication. 00554 * 00555 * The planner also derives lists of the values that need to be passed into 00556 * and out of the subplan. Input values are represented as a list "args" of 00557 * expressions to be evaluated in the outer-query context (currently these 00558 * args are always just Vars, but in principle they could be any expression). 00559 * The values are assigned to the global PARAM_EXEC params indexed by parParam 00560 * (the parParam and args lists must have the same ordering). setParam is a 00561 * list of the PARAM_EXEC params that are computed by the sub-select, if it 00562 * is an initplan; they are listed in order by sub-select output column 00563 * position. (parParam and setParam are integer Lists, not Bitmapsets, 00564 * because their ordering is significant.) 00565 * 00566 * Also, the planner computes startup and per-call costs for use of the 00567 * SubPlan. Note that these include the cost of the subquery proper, 00568 * evaluation of the testexpr if any, and any hashtable management overhead. 00569 */ 00570 typedef struct SubPlan 00571 { 00572 Expr xpr; 00573 /* Fields copied from original SubLink: */ 00574 SubLinkType subLinkType; /* see above */ 00575 /* The combining operators, transformed to an executable expression: */ 00576 Node *testexpr; /* OpExpr or RowCompareExpr expression tree */ 00577 List *paramIds; /* IDs of Params embedded in the above */ 00578 /* Identification of the Plan tree to use: */ 00579 int plan_id; /* Index (from 1) in PlannedStmt.subplans */ 00580 /* Identification of the SubPlan for EXPLAIN and debugging purposes: */ 00581 char *plan_name; /* A name assigned during planning */ 00582 /* Extra data useful for determining subplan's output type: */ 00583 Oid firstColType; /* Type of first column of subplan result */ 00584 int32 firstColTypmod; /* Typmod of first column of subplan result */ 00585 Oid firstColCollation; /* Collation of first column of 00586 * subplan result */ 00587 /* Information about execution strategy: */ 00588 bool useHashTable; /* TRUE to store subselect output in a hash 00589 * table (implies we are doing "IN") */ 00590 bool unknownEqFalse; /* TRUE if it's okay to return FALSE when the 00591 * spec result is UNKNOWN; this allows much 00592 * simpler handling of null values */ 00593 /* Information for passing params into and out of the subselect: */ 00594 /* setParam and parParam are lists of integers (param IDs) */ 00595 List *setParam; /* initplan subqueries have to set these 00596 * Params for parent plan */ 00597 List *parParam; /* indices of input Params from parent plan */ 00598 List *args; /* exprs to pass as parParam values */ 00599 /* Estimated execution costs: */ 00600 Cost startup_cost; /* one-time setup cost */ 00601 Cost per_call_cost; /* cost for each subplan evaluation */ 00602 } SubPlan; 00603 00604 /* 00605 * AlternativeSubPlan - expression node for a choice among SubPlans 00606 * 00607 * The subplans are given as a List so that the node definition need not 00608 * change if there's ever more than two alternatives. For the moment, 00609 * though, there are always exactly two; and the first one is the fast-start 00610 * plan. 00611 */ 00612 typedef struct AlternativeSubPlan 00613 { 00614 Expr xpr; 00615 List *subplans; /* SubPlan(s) with equivalent results */ 00616 } AlternativeSubPlan; 00617 00618 /* ---------------- 00619 * FieldSelect 00620 * 00621 * FieldSelect represents the operation of extracting one field from a tuple 00622 * value. At runtime, the input expression is expected to yield a rowtype 00623 * Datum. The specified field number is extracted and returned as a Datum. 00624 * ---------------- 00625 */ 00626 00627 typedef struct FieldSelect 00628 { 00629 Expr xpr; 00630 Expr *arg; /* input expression */ 00631 AttrNumber fieldnum; /* attribute number of field to extract */ 00632 Oid resulttype; /* type of the field (result type of this 00633 * node) */ 00634 int32 resulttypmod; /* output typmod (usually -1) */ 00635 Oid resultcollid; /* OID of collation of the field */ 00636 } FieldSelect; 00637 00638 /* ---------------- 00639 * FieldStore 00640 * 00641 * FieldStore represents the operation of modifying one field in a tuple 00642 * value, yielding a new tuple value (the input is not touched!). Like 00643 * the assign case of ArrayRef, this is used to implement UPDATE of a 00644 * portion of a column. 00645 * 00646 * A single FieldStore can actually represent updates of several different 00647 * fields. The parser only generates FieldStores with single-element lists, 00648 * but the planner will collapse multiple updates of the same base column 00649 * into one FieldStore. 00650 * ---------------- 00651 */ 00652 00653 typedef struct FieldStore 00654 { 00655 Expr xpr; 00656 Expr *arg; /* input tuple value */ 00657 List *newvals; /* new value(s) for field(s) */ 00658 List *fieldnums; /* integer list of field attnums */ 00659 Oid resulttype; /* type of result (same as type of arg) */ 00660 /* Like RowExpr, we deliberately omit a typmod and collation here */ 00661 } FieldStore; 00662 00663 /* ---------------- 00664 * RelabelType 00665 * 00666 * RelabelType represents a "dummy" type coercion between two binary- 00667 * compatible datatypes, such as reinterpreting the result of an OID 00668 * expression as an int4. It is a no-op at runtime; we only need it 00669 * to provide a place to store the correct type to be attributed to 00670 * the expression result during type resolution. (We can't get away 00671 * with just overwriting the type field of the input expression node, 00672 * so we need a separate node to show the coercion's result type.) 00673 * ---------------- 00674 */ 00675 00676 typedef struct RelabelType 00677 { 00678 Expr xpr; 00679 Expr *arg; /* input expression */ 00680 Oid resulttype; /* output type of coercion expression */ 00681 int32 resulttypmod; /* output typmod (usually -1) */ 00682 Oid resultcollid; /* OID of collation, or InvalidOid if none */ 00683 CoercionForm relabelformat; /* how to display this node */ 00684 int location; /* token location, or -1 if unknown */ 00685 } RelabelType; 00686 00687 /* ---------------- 00688 * CoerceViaIO 00689 * 00690 * CoerceViaIO represents a type coercion between two types whose textual 00691 * representations are compatible, implemented by invoking the source type's 00692 * typoutput function then the destination type's typinput function. 00693 * ---------------- 00694 */ 00695 00696 typedef struct CoerceViaIO 00697 { 00698 Expr xpr; 00699 Expr *arg; /* input expression */ 00700 Oid resulttype; /* output type of coercion */ 00701 /* output typmod is not stored, but is presumed -1 */ 00702 Oid resultcollid; /* OID of collation, or InvalidOid if none */ 00703 CoercionForm coerceformat; /* how to display this node */ 00704 int location; /* token location, or -1 if unknown */ 00705 } CoerceViaIO; 00706 00707 /* ---------------- 00708 * ArrayCoerceExpr 00709 * 00710 * ArrayCoerceExpr represents a type coercion from one array type to another, 00711 * which is implemented by applying the indicated element-type coercion 00712 * function to each element of the source array. If elemfuncid is InvalidOid 00713 * then the element types are binary-compatible, but the coercion still 00714 * requires some effort (we have to fix the element type ID stored in the 00715 * array header). 00716 * ---------------- 00717 */ 00718 00719 typedef struct ArrayCoerceExpr 00720 { 00721 Expr xpr; 00722 Expr *arg; /* input expression (yields an array) */ 00723 Oid elemfuncid; /* OID of element coercion function, or 0 */ 00724 Oid resulttype; /* output type of coercion (an array type) */ 00725 int32 resulttypmod; /* output typmod (also element typmod) */ 00726 Oid resultcollid; /* OID of collation, or InvalidOid if none */ 00727 bool isExplicit; /* conversion semantics flag to pass to func */ 00728 CoercionForm coerceformat; /* how to display this node */ 00729 int location; /* token location, or -1 if unknown */ 00730 } ArrayCoerceExpr; 00731 00732 /* ---------------- 00733 * ConvertRowtypeExpr 00734 * 00735 * ConvertRowtypeExpr represents a type coercion from one composite type 00736 * to another, where the source type is guaranteed to contain all the columns 00737 * needed for the destination type plus possibly others; the columns need not 00738 * be in the same positions, but are matched up by name. This is primarily 00739 * used to convert a whole-row value of an inheritance child table into a 00740 * valid whole-row value of its parent table's rowtype. 00741 * ---------------- 00742 */ 00743 00744 typedef struct ConvertRowtypeExpr 00745 { 00746 Expr xpr; 00747 Expr *arg; /* input expression */ 00748 Oid resulttype; /* output type (always a composite type) */ 00749 /* Like RowExpr, we deliberately omit a typmod and collation here */ 00750 CoercionForm convertformat; /* how to display this node */ 00751 int location; /* token location, or -1 if unknown */ 00752 } ConvertRowtypeExpr; 00753 00754 /*---------- 00755 * CollateExpr - COLLATE 00756 * 00757 * The planner replaces CollateExpr with RelabelType during expression 00758 * preprocessing, so execution never sees a CollateExpr. 00759 *---------- 00760 */ 00761 typedef struct CollateExpr 00762 { 00763 Expr xpr; 00764 Expr *arg; /* input expression */ 00765 Oid collOid; /* collation's OID */ 00766 int location; /* token location, or -1 if unknown */ 00767 } CollateExpr; 00768 00769 /*---------- 00770 * CaseExpr - a CASE expression 00771 * 00772 * We support two distinct forms of CASE expression: 00773 * CASE WHEN boolexpr THEN expr [ WHEN boolexpr THEN expr ... ] 00774 * CASE testexpr WHEN compexpr THEN expr [ WHEN compexpr THEN expr ... ] 00775 * These are distinguishable by the "arg" field being NULL in the first case 00776 * and the testexpr in the second case. 00777 * 00778 * In the raw grammar output for the second form, the condition expressions 00779 * of the WHEN clauses are just the comparison values. Parse analysis 00780 * converts these to valid boolean expressions of the form 00781 * CaseTestExpr '=' compexpr 00782 * where the CaseTestExpr node is a placeholder that emits the correct 00783 * value at runtime. This structure is used so that the testexpr need be 00784 * evaluated only once. Note that after parse analysis, the condition 00785 * expressions always yield boolean. 00786 * 00787 * Note: we can test whether a CaseExpr has been through parse analysis 00788 * yet by checking whether casetype is InvalidOid or not. 00789 *---------- 00790 */ 00791 typedef struct CaseExpr 00792 { 00793 Expr xpr; 00794 Oid casetype; /* type of expression result */ 00795 Oid casecollid; /* OID of collation, or InvalidOid if none */ 00796 Expr *arg; /* implicit equality comparison argument */ 00797 List *args; /* the arguments (list of WHEN clauses) */ 00798 Expr *defresult; /* the default result (ELSE clause) */ 00799 int location; /* token location, or -1 if unknown */ 00800 } CaseExpr; 00801 00802 /* 00803 * CaseWhen - one arm of a CASE expression 00804 */ 00805 typedef struct CaseWhen 00806 { 00807 Expr xpr; 00808 Expr *expr; /* condition expression */ 00809 Expr *result; /* substitution result */ 00810 int location; /* token location, or -1 if unknown */ 00811 } CaseWhen; 00812 00813 /* 00814 * Placeholder node for the test value to be processed by a CASE expression. 00815 * This is effectively like a Param, but can be implemented more simply 00816 * since we need only one replacement value at a time. 00817 * 00818 * We also use this in nested UPDATE expressions. 00819 * See transformAssignmentIndirection(). 00820 */ 00821 typedef struct CaseTestExpr 00822 { 00823 Expr xpr; 00824 Oid typeId; /* type for substituted value */ 00825 int32 typeMod; /* typemod for substituted value */ 00826 Oid collation; /* collation for the substituted value */ 00827 } CaseTestExpr; 00828 00829 /* 00830 * ArrayExpr - an ARRAY[] expression 00831 * 00832 * Note: if multidims is false, the constituent expressions all yield the 00833 * scalar type identified by element_typeid. If multidims is true, the 00834 * constituent expressions all yield arrays of element_typeid (ie, the same 00835 * type as array_typeid); at runtime we must check for compatible subscripts. 00836 */ 00837 typedef struct ArrayExpr 00838 { 00839 Expr xpr; 00840 Oid array_typeid; /* type of expression result */ 00841 Oid array_collid; /* OID of collation, or InvalidOid if none */ 00842 Oid element_typeid; /* common type of array elements */ 00843 List *elements; /* the array elements or sub-arrays */ 00844 bool multidims; /* true if elements are sub-arrays */ 00845 int location; /* token location, or -1 if unknown */ 00846 } ArrayExpr; 00847 00848 /* 00849 * RowExpr - a ROW() expression 00850 * 00851 * Note: the list of fields must have a one-for-one correspondence with 00852 * physical fields of the associated rowtype, although it is okay for it 00853 * to be shorter than the rowtype. That is, the N'th list element must 00854 * match up with the N'th physical field. When the N'th physical field 00855 * is a dropped column (attisdropped) then the N'th list element can just 00856 * be a NULL constant. (This case can only occur for named composite types, 00857 * not RECORD types, since those are built from the RowExpr itself rather 00858 * than vice versa.) It is important not to assume that length(args) is 00859 * the same as the number of columns logically present in the rowtype. 00860 * 00861 * colnames provides field names in cases where the names can't easily be 00862 * obtained otherwise. Names *must* be provided if row_typeid is RECORDOID. 00863 * If row_typeid identifies a known composite type, colnames can be NIL to 00864 * indicate the type's cataloged field names apply. Note that colnames can 00865 * be non-NIL even for a composite type, and typically is when the RowExpr 00866 * was created by expanding a whole-row Var. This is so that we can retain 00867 * the column alias names of the RTE that the Var referenced (which would 00868 * otherwise be very difficult to extract from the parsetree). Like the 00869 * args list, colnames is one-for-one with physical fields of the rowtype. 00870 */ 00871 typedef struct RowExpr 00872 { 00873 Expr xpr; 00874 List *args; /* the fields */ 00875 Oid row_typeid; /* RECORDOID or a composite type's ID */ 00876 00877 /* 00878 * Note: we deliberately do NOT store a typmod. Although a typmod will be 00879 * associated with specific RECORD types at runtime, it will differ for 00880 * different backends, and so cannot safely be stored in stored 00881 * parsetrees. We must assume typmod -1 for a RowExpr node. 00882 * 00883 * We don't need to store a collation either. The result type is 00884 * necessarily composite, and composite types never have a collation. 00885 */ 00886 CoercionForm row_format; /* how to display this node */ 00887 List *colnames; /* list of String, or NIL */ 00888 int location; /* token location, or -1 if unknown */ 00889 } RowExpr; 00890 00891 /* 00892 * RowCompareExpr - row-wise comparison, such as (a, b) <= (1, 2) 00893 * 00894 * We support row comparison for any operator that can be determined to 00895 * act like =, <>, <, <=, >, or >= (we determine this by looking for the 00896 * operator in btree opfamilies). Note that the same operator name might 00897 * map to a different operator for each pair of row elements, since the 00898 * element datatypes can vary. 00899 * 00900 * A RowCompareExpr node is only generated for the < <= > >= cases; 00901 * the = and <> cases are translated to simple AND or OR combinations 00902 * of the pairwise comparisons. However, we include = and <> in the 00903 * RowCompareType enum for the convenience of parser logic. 00904 */ 00905 typedef enum RowCompareType 00906 { 00907 /* Values of this enum are chosen to match btree strategy numbers */ 00908 ROWCOMPARE_LT = 1, /* BTLessStrategyNumber */ 00909 ROWCOMPARE_LE = 2, /* BTLessEqualStrategyNumber */ 00910 ROWCOMPARE_EQ = 3, /* BTEqualStrategyNumber */ 00911 ROWCOMPARE_GE = 4, /* BTGreaterEqualStrategyNumber */ 00912 ROWCOMPARE_GT = 5, /* BTGreaterStrategyNumber */ 00913 ROWCOMPARE_NE = 6 /* no such btree strategy */ 00914 } RowCompareType; 00915 00916 typedef struct RowCompareExpr 00917 { 00918 Expr xpr; 00919 RowCompareType rctype; /* LT LE GE or GT, never EQ or NE */ 00920 List *opnos; /* OID list of pairwise comparison ops */ 00921 List *opfamilies; /* OID list of containing operator families */ 00922 List *inputcollids; /* OID list of collations for comparisons */ 00923 List *largs; /* the left-hand input arguments */ 00924 List *rargs; /* the right-hand input arguments */ 00925 } RowCompareExpr; 00926 00927 /* 00928 * CoalesceExpr - a COALESCE expression 00929 */ 00930 typedef struct CoalesceExpr 00931 { 00932 Expr xpr; 00933 Oid coalescetype; /* type of expression result */ 00934 Oid coalescecollid; /* OID of collation, or InvalidOid if none */ 00935 List *args; /* the arguments */ 00936 int location; /* token location, or -1 if unknown */ 00937 } CoalesceExpr; 00938 00939 /* 00940 * MinMaxExpr - a GREATEST or LEAST function 00941 */ 00942 typedef enum MinMaxOp 00943 { 00944 IS_GREATEST, 00945 IS_LEAST 00946 } MinMaxOp; 00947 00948 typedef struct MinMaxExpr 00949 { 00950 Expr xpr; 00951 Oid minmaxtype; /* common type of arguments and result */ 00952 Oid minmaxcollid; /* OID of collation of result */ 00953 Oid inputcollid; /* OID of collation that function should use */ 00954 MinMaxOp op; /* function to execute */ 00955 List *args; /* the arguments */ 00956 int location; /* token location, or -1 if unknown */ 00957 } MinMaxExpr; 00958 00959 /* 00960 * XmlExpr - various SQL/XML functions requiring special grammar productions 00961 * 00962 * 'name' carries the "NAME foo" argument (already XML-escaped). 00963 * 'named_args' and 'arg_names' represent an xml_attribute list. 00964 * 'args' carries all other arguments. 00965 * 00966 * Note: result type/typmod/collation are not stored, but can be deduced 00967 * from the XmlExprOp. The type/typmod fields are just used for display 00968 * purposes, and are NOT necessarily the true result type of the node. 00969 * (We also use type == InvalidOid to mark a not-yet-parse-analyzed XmlExpr.) 00970 */ 00971 typedef enum XmlExprOp 00972 { 00973 IS_XMLCONCAT, /* XMLCONCAT(args) */ 00974 IS_XMLELEMENT, /* XMLELEMENT(name, xml_attributes, args) */ 00975 IS_XMLFOREST, /* XMLFOREST(xml_attributes) */ 00976 IS_XMLPARSE, /* XMLPARSE(text, is_doc, preserve_ws) */ 00977 IS_XMLPI, /* XMLPI(name [, args]) */ 00978 IS_XMLROOT, /* XMLROOT(xml, version, standalone) */ 00979 IS_XMLSERIALIZE, /* XMLSERIALIZE(is_document, xmlval) */ 00980 IS_DOCUMENT /* xmlval IS DOCUMENT */ 00981 } XmlExprOp; 00982 00983 typedef enum 00984 { 00985 XMLOPTION_DOCUMENT, 00986 XMLOPTION_CONTENT 00987 } XmlOptionType; 00988 00989 typedef struct XmlExpr 00990 { 00991 Expr xpr; 00992 XmlExprOp op; /* xml function ID */ 00993 char *name; /* name in xml(NAME foo ...) syntaxes */ 00994 List *named_args; /* non-XML expressions for xml_attributes */ 00995 List *arg_names; /* parallel list of Value strings */ 00996 List *args; /* list of expressions */ 00997 XmlOptionType xmloption; /* DOCUMENT or CONTENT */ 00998 Oid type; /* target type/typmod for XMLSERIALIZE */ 00999 int32 typmod; 01000 int location; /* token location, or -1 if unknown */ 01001 } XmlExpr; 01002 01003 /* ---------------- 01004 * NullTest 01005 * 01006 * NullTest represents the operation of testing a value for NULLness. 01007 * The appropriate test is performed and returned as a boolean Datum. 01008 * 01009 * NOTE: the semantics of this for rowtype inputs are noticeably different 01010 * from the scalar case. We provide an "argisrow" flag to reflect that. 01011 * ---------------- 01012 */ 01013 01014 typedef enum NullTestType 01015 { 01016 IS_NULL, IS_NOT_NULL 01017 } NullTestType; 01018 01019 typedef struct NullTest 01020 { 01021 Expr xpr; 01022 Expr *arg; /* input expression */ 01023 NullTestType nulltesttype; /* IS NULL, IS NOT NULL */ 01024 bool argisrow; /* T if input is of a composite type */ 01025 } NullTest; 01026 01027 /* 01028 * BooleanTest 01029 * 01030 * BooleanTest represents the operation of determining whether a boolean 01031 * is TRUE, FALSE, or UNKNOWN (ie, NULL). All six meaningful combinations 01032 * are supported. Note that a NULL input does *not* cause a NULL result. 01033 * The appropriate test is performed and returned as a boolean Datum. 01034 */ 01035 01036 typedef enum BoolTestType 01037 { 01038 IS_TRUE, IS_NOT_TRUE, IS_FALSE, IS_NOT_FALSE, IS_UNKNOWN, IS_NOT_UNKNOWN 01039 } BoolTestType; 01040 01041 typedef struct BooleanTest 01042 { 01043 Expr xpr; 01044 Expr *arg; /* input expression */ 01045 BoolTestType booltesttype; /* test type */ 01046 } BooleanTest; 01047 01048 /* 01049 * CoerceToDomain 01050 * 01051 * CoerceToDomain represents the operation of coercing a value to a domain 01052 * type. At runtime (and not before) the precise set of constraints to be 01053 * checked will be determined. If the value passes, it is returned as the 01054 * result; if not, an error is raised. Note that this is equivalent to 01055 * RelabelType in the scenario where no constraints are applied. 01056 */ 01057 typedef struct CoerceToDomain 01058 { 01059 Expr xpr; 01060 Expr *arg; /* input expression */ 01061 Oid resulttype; /* domain type ID (result type) */ 01062 int32 resulttypmod; /* output typmod (currently always -1) */ 01063 Oid resultcollid; /* OID of collation, or InvalidOid if none */ 01064 CoercionForm coercionformat; /* how to display this node */ 01065 int location; /* token location, or -1 if unknown */ 01066 } CoerceToDomain; 01067 01068 /* 01069 * Placeholder node for the value to be processed by a domain's check 01070 * constraint. This is effectively like a Param, but can be implemented more 01071 * simply since we need only one replacement value at a time. 01072 * 01073 * Note: the typeId/typeMod/collation will be set from the domain's base type, 01074 * not the domain itself. This is because we shouldn't consider the value 01075 * to be a member of the domain if we haven't yet checked its constraints. 01076 */ 01077 typedef struct CoerceToDomainValue 01078 { 01079 Expr xpr; 01080 Oid typeId; /* type for substituted value */ 01081 int32 typeMod; /* typemod for substituted value */ 01082 Oid collation; /* collation for the substituted value */ 01083 int location; /* token location, or -1 if unknown */ 01084 } CoerceToDomainValue; 01085 01086 /* 01087 * Placeholder node for a DEFAULT marker in an INSERT or UPDATE command. 01088 * 01089 * This is not an executable expression: it must be replaced by the actual 01090 * column default expression during rewriting. But it is convenient to 01091 * treat it as an expression node during parsing and rewriting. 01092 */ 01093 typedef struct SetToDefault 01094 { 01095 Expr xpr; 01096 Oid typeId; /* type for substituted value */ 01097 int32 typeMod; /* typemod for substituted value */ 01098 Oid collation; /* collation for the substituted value */ 01099 int location; /* token location, or -1 if unknown */ 01100 } SetToDefault; 01101 01102 /* 01103 * Node representing [WHERE] CURRENT OF cursor_name 01104 * 01105 * CURRENT OF is a bit like a Var, in that it carries the rangetable index 01106 * of the target relation being constrained; this aids placing the expression 01107 * correctly during planning. We can assume however that its "levelsup" is 01108 * always zero, due to the syntactic constraints on where it can appear. 01109 * 01110 * The referenced cursor can be represented either as a hardwired string 01111 * or as a reference to a run-time parameter of type REFCURSOR. The latter 01112 * case is for the convenience of plpgsql. 01113 */ 01114 typedef struct CurrentOfExpr 01115 { 01116 Expr xpr; 01117 Index cvarno; /* RT index of target relation */ 01118 char *cursor_name; /* name of referenced cursor, or NULL */ 01119 int cursor_param; /* refcursor parameter number, or 0 */ 01120 } CurrentOfExpr; 01121 01122 /*-------------------- 01123 * TargetEntry - 01124 * a target entry (used in query target lists) 01125 * 01126 * Strictly speaking, a TargetEntry isn't an expression node (since it can't 01127 * be evaluated by ExecEvalExpr). But we treat it as one anyway, since in 01128 * very many places it's convenient to process a whole query targetlist as a 01129 * single expression tree. 01130 * 01131 * In a SELECT's targetlist, resno should always be equal to the item's 01132 * ordinal position (counting from 1). However, in an INSERT or UPDATE 01133 * targetlist, resno represents the attribute number of the destination 01134 * column for the item; so there may be missing or out-of-order resnos. 01135 * It is even legal to have duplicated resnos; consider 01136 * UPDATE table SET arraycol[1] = ..., arraycol[2] = ..., ... 01137 * The two meanings come together in the executor, because the planner 01138 * transforms INSERT/UPDATE tlists into a normalized form with exactly 01139 * one entry for each column of the destination table. Before that's 01140 * happened, however, it is risky to assume that resno == position. 01141 * Generally get_tle_by_resno() should be used rather than list_nth() 01142 * to fetch tlist entries by resno, and only in SELECT should you assume 01143 * that resno is a unique identifier. 01144 * 01145 * resname is required to represent the correct column name in non-resjunk 01146 * entries of top-level SELECT targetlists, since it will be used as the 01147 * column title sent to the frontend. In most other contexts it is only 01148 * a debugging aid, and may be wrong or even NULL. (In particular, it may 01149 * be wrong in a tlist from a stored rule, if the referenced column has been 01150 * renamed by ALTER TABLE since the rule was made. Also, the planner tends 01151 * to store NULL rather than look up a valid name for tlist entries in 01152 * non-toplevel plan nodes.) In resjunk entries, resname should be either 01153 * a specific system-generated name (such as "ctid") or NULL; anything else 01154 * risks confusing ExecGetJunkAttribute! 01155 * 01156 * ressortgroupref is used in the representation of ORDER BY, GROUP BY, and 01157 * DISTINCT items. Targetlist entries with ressortgroupref=0 are not 01158 * sort/group items. If ressortgroupref>0, then this item is an ORDER BY, 01159 * GROUP BY, and/or DISTINCT target value. No two entries in a targetlist 01160 * may have the same nonzero ressortgroupref --- but there is no particular 01161 * meaning to the nonzero values, except as tags. (For example, one must 01162 * not assume that lower ressortgroupref means a more significant sort key.) 01163 * The order of the associated SortGroupClause lists determine the semantics. 01164 * 01165 * resorigtbl/resorigcol identify the source of the column, if it is a 01166 * simple reference to a column of a base table (or view). If it is not 01167 * a simple reference, these fields are zeroes. 01168 * 01169 * If resjunk is true then the column is a working column (such as a sort key) 01170 * that should be removed from the final output of the query. Resjunk columns 01171 * must have resnos that cannot duplicate any regular column's resno. Also 01172 * note that there are places that assume resjunk columns come after non-junk 01173 * columns. 01174 *-------------------- 01175 */ 01176 typedef struct TargetEntry 01177 { 01178 Expr xpr; 01179 Expr *expr; /* expression to evaluate */ 01180 AttrNumber resno; /* attribute number (see notes above) */ 01181 char *resname; /* name of the column (could be NULL) */ 01182 Index ressortgroupref;/* nonzero if referenced by a sort/group 01183 * clause */ 01184 Oid resorigtbl; /* OID of column's source table */ 01185 AttrNumber resorigcol; /* column's number in source table */ 01186 bool resjunk; /* set to true to eliminate the attribute from 01187 * final target list */ 01188 } TargetEntry; 01189 01190 01191 /* ---------------------------------------------------------------- 01192 * node types for join trees 01193 * 01194 * The leaves of a join tree structure are RangeTblRef nodes. Above 01195 * these, JoinExpr nodes can appear to denote a specific kind of join 01196 * or qualified join. Also, FromExpr nodes can appear to denote an 01197 * ordinary cross-product join ("FROM foo, bar, baz WHERE ..."). 01198 * FromExpr is like a JoinExpr of jointype JOIN_INNER, except that it 01199 * may have any number of child nodes, not just two. 01200 * 01201 * NOTE: the top level of a Query's jointree is always a FromExpr. 01202 * Even if the jointree contains no rels, there will be a FromExpr. 01203 * 01204 * NOTE: the qualification expressions present in JoinExpr nodes are 01205 * *in addition to* the query's main WHERE clause, which appears as the 01206 * qual of the top-level FromExpr. The reason for associating quals with 01207 * specific nodes in the jointree is that the position of a qual is critical 01208 * when outer joins are present. (If we enforce a qual too soon or too late, 01209 * that may cause the outer join to produce the wrong set of NULL-extended 01210 * rows.) If all joins are inner joins then all the qual positions are 01211 * semantically interchangeable. 01212 * 01213 * NOTE: in the raw output of gram.y, a join tree contains RangeVar, 01214 * RangeSubselect, and RangeFunction nodes, which are all replaced by 01215 * RangeTblRef nodes during the parse analysis phase. Also, the top-level 01216 * FromExpr is added during parse analysis; the grammar regards FROM and 01217 * WHERE as separate. 01218 * ---------------------------------------------------------------- 01219 */ 01220 01221 /* 01222 * RangeTblRef - reference to an entry in the query's rangetable 01223 * 01224 * We could use direct pointers to the RT entries and skip having these 01225 * nodes, but multiple pointers to the same node in a querytree cause 01226 * lots of headaches, so it seems better to store an index into the RT. 01227 */ 01228 typedef struct RangeTblRef 01229 { 01230 NodeTag type; 01231 int rtindex; 01232 } RangeTblRef; 01233 01234 /*---------- 01235 * JoinExpr - for SQL JOIN expressions 01236 * 01237 * isNatural, usingClause, and quals are interdependent. The user can write 01238 * only one of NATURAL, USING(), or ON() (this is enforced by the grammar). 01239 * If he writes NATURAL then parse analysis generates the equivalent USING() 01240 * list, and from that fills in "quals" with the right equality comparisons. 01241 * If he writes USING() then "quals" is filled with equality comparisons. 01242 * If he writes ON() then only "quals" is set. Note that NATURAL/USING 01243 * are not equivalent to ON() since they also affect the output column list. 01244 * 01245 * alias is an Alias node representing the AS alias-clause attached to the 01246 * join expression, or NULL if no clause. NB: presence or absence of the 01247 * alias has a critical impact on semantics, because a join with an alias 01248 * restricts visibility of the tables/columns inside it. 01249 * 01250 * During parse analysis, an RTE is created for the Join, and its index 01251 * is filled into rtindex. This RTE is present mainly so that Vars can 01252 * be created that refer to the outputs of the join. The planner sometimes 01253 * generates JoinExprs internally; these can have rtindex = 0 if there are 01254 * no join alias variables referencing such joins. 01255 *---------- 01256 */ 01257 typedef struct JoinExpr 01258 { 01259 NodeTag type; 01260 JoinType jointype; /* type of join */ 01261 bool isNatural; /* Natural join? Will need to shape table */ 01262 Node *larg; /* left subtree */ 01263 Node *rarg; /* right subtree */ 01264 List *usingClause; /* USING clause, if any (list of String) */ 01265 Node *quals; /* qualifiers on join, if any */ 01266 Alias *alias; /* user-written alias clause, if any */ 01267 int rtindex; /* RT index assigned for join, or 0 */ 01268 } JoinExpr; 01269 01270 /*---------- 01271 * FromExpr - represents a FROM ... WHERE ... construct 01272 * 01273 * This is both more flexible than a JoinExpr (it can have any number of 01274 * children, including zero) and less so --- we don't need to deal with 01275 * aliases and so on. The output column set is implicitly just the union 01276 * of the outputs of the children. 01277 *---------- 01278 */ 01279 typedef struct FromExpr 01280 { 01281 NodeTag type; 01282 List *fromlist; /* List of join subtrees */ 01283 Node *quals; /* qualifiers on join, if any */ 01284 } FromExpr; 01285 01286 #endif /* PRIMNODES_H */