📄 parsenodes.h
字号:
/*------------------------------------------------------------------------- * * parsenodes.h * definitions for parse tree nodes * * * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.292.2.1 2005/11/22 18:23:28 momjian Exp $ * *------------------------------------------------------------------------- */#ifndef PARSENODES_H#define PARSENODES_H#include "nodes/primnodes.h"/* Possible sources of a Query */typedef enum QuerySource{ QSRC_ORIGINAL, /* original parsetree (explicit query) */ QSRC_PARSER, /* added by parse analysis */ QSRC_INSTEAD_RULE, /* added by unconditional INSTEAD rule */ QSRC_QUAL_INSTEAD_RULE, /* added by conditional INSTEAD rule */ QSRC_NON_INSTEAD_RULE /* added by non-INSTEAD rule */} QuerySource;/* * Grantable rights are encoded so that we can OR them together in a bitmask. * The present representation of AclItem limits us to 16 distinct rights, * even though AclMode is defined as uint32. See utils/acl.h. * * Caution: changing these codes breaks stored ACLs, hence forces initdb. */typedef uint32 AclMode; /* a bitmask of privilege bits */#define ACL_INSERT (1<<0) /* for relations */#define ACL_SELECT (1<<1)#define ACL_UPDATE (1<<2)#define ACL_DELETE (1<<3)#define ACL_RULE (1<<4)#define ACL_REFERENCES (1<<5)#define ACL_TRIGGER (1<<6)#define ACL_EXECUTE (1<<7) /* for functions */#define ACL_USAGE (1<<8) /* for languages and namespaces */#define ACL_CREATE (1<<9) /* for namespaces and databases */#define ACL_CREATE_TEMP (1<<10) /* for databases */#define N_ACL_RIGHTS 11 /* 1 plus the last 1<<x */#define ACL_NO_RIGHTS 0/* Currently, SELECT ... FOR UPDATE/FOR SHARE requires UPDATE privileges */#define ACL_SELECT_FOR_UPDATE ACL_UPDATE/***************************************************************************** * Query Tree *****************************************************************************//* * Query - * all statements are turned into a Query tree (via transformStmt) * for further processing by the optimizer * * utility statements (i.e. non-optimizable statements) have the * utilityStmt field set, and the Query itself is mostly dummy. */typedef struct Query{ NodeTag type; CmdType commandType; /* select|insert|update|delete|utility */ QuerySource querySource; /* where did I come from? */ bool canSetTag; /* do I set the command result tag? */ Node *utilityStmt; /* non-null if this is a non-optimizable * statement */ int resultRelation; /* target relation (index into rtable) */ RangeVar *into; /* target relation for SELECT INTO */ bool intoHasOids; /* should target relation contain OIDs? */ bool hasAggs; /* has aggregates in tlist or havingQual */ bool hasSubLinks; /* has subquery SubLink */ List *rtable; /* list of range table entries */ FromExpr *jointree; /* table join tree (FROM and WHERE clauses) */ List *rowMarks; /* integer list of RT indexes of relations * that are selected FOR UPDATE/SHARE */ bool forUpdate; /* true if rowMarks are FOR UPDATE, false if * they are FOR SHARE */ bool rowNoWait; /* FOR UPDATE/SHARE NOWAIT option */ List *targetList; /* target list (of TargetEntry) */ List *groupClause; /* a list of GroupClause's */ Node *havingQual; /* qualifications applied to groups */ List *distinctClause; /* a list of SortClause's */ List *sortClause; /* a list of SortClause's */ Node *limitOffset; /* # of result tuples to skip */ Node *limitCount; /* # of result tuples to return */ Node *setOperations; /* set-operation tree if this is top level of * a UNION/INTERSECT/EXCEPT query */ /* * If the resultRelation turns out to be the parent of an inheritance * tree, the planner will add all the child tables to the rtable and store * a list of the rtindexes of all the result relations here. This is done * at plan time, not parse time, since we don't want to commit to the * exact set of child tables at parse time. This field ought to go in * some sort of TopPlan plan node, not in the Query. */ List *resultRelations; /* integer list of RT indexes, or NIL */} Query;/**************************************************************************** * Supporting data structures for Parse Trees * * Most of these node types appear in raw parsetrees output by the grammar, * and get transformed to something else by the analyzer. A few of them * are used as-is in transformed querytrees. ****************************************************************************//* * TypeName - specifies a type in definitions * * For TypeName structures generated internally, it is often easier to * specify the type by OID than by name. If "names" is NIL then the * actual type OID is given by typeid, otherwise typeid is unused. * * If pct_type is TRUE, then names is actually a field name and we look up * the type of that field. Otherwise (the normal case), names is a type * name possibly qualified with schema and database name. */typedef struct TypeName{ NodeTag type; List *names; /* qualified name (list of Value strings) */ Oid typeid; /* type identified by OID */ bool timezone; /* timezone specified? */ bool setof; /* is a set? */ bool pct_type; /* %TYPE specified? */ int32 typmod; /* type modifier */ List *arrayBounds; /* array bounds */} TypeName;/* * ColumnRef - specifies a reference to a column, or possibly a whole tuple * * The "fields" list must be nonempty; its last component may be "*" * instead of a regular field name. * * Note: any array subscripting or selection of fields from composite columns * is represented by an A_Indirection node above the ColumnRef. However, * for simplicity in the normal case, initial field selection from a table * name is represented within ColumnRef and not by adding A_Indirection. */typedef struct ColumnRef{ NodeTag type; List *fields; /* field names (list of Value strings) */} ColumnRef;/* * ParamRef - specifies a $n parameter reference */typedef struct ParamRef{ NodeTag type; int number; /* the number of the parameter */} ParamRef;/* * A_Expr - infix, prefix, and postfix expressions */typedef enum A_Expr_Kind{ AEXPR_OP, /* normal operator */ AEXPR_AND, /* booleans - name field is unused */ AEXPR_OR, AEXPR_NOT, AEXPR_OP_ANY, /* scalar op ANY (array) */ AEXPR_OP_ALL, /* scalar op ALL (array) */ AEXPR_DISTINCT, /* IS DISTINCT FROM - name must be "=" */ AEXPR_NULLIF, /* NULLIF - name must be "=" */ AEXPR_OF /* IS (not) OF - name must be "=" or "!=" */} A_Expr_Kind;typedef struct A_Expr{ NodeTag type; A_Expr_Kind kind; /* see above */ List *name; /* possibly-qualified name of operator */ Node *lexpr; /* left argument, or NULL if none */ Node *rexpr; /* right argument, or NULL if none */} A_Expr;/* * A_Const - a constant expression */typedef struct A_Const{ NodeTag type; Value val; /* the value (with the tag) */ TypeName *typename; /* typecast */} A_Const;/* * TypeCast - a CAST expression * * NOTE: for mostly historical reasons, A_Const parsenodes contain * room for a TypeName; we only generate a separate TypeCast node if the * argument to be casted is not a constant. In theory either representation * would work, but it is convenient to have the target type immediately * available while resolving a constant's datatype. */typedef struct TypeCast{ NodeTag type; Node *arg; /* the expression being casted */ TypeName *typename; /* the target type */} TypeCast;/* * FuncCall - a function or aggregate invocation * * agg_star indicates we saw a 'foo(*)' construct, while agg_distinct * indicates we saw 'foo(DISTINCT ...)'. In either case, the construct * *must* be an aggregate call. Otherwise, it might be either an * aggregate or some other kind of function. */typedef struct FuncCall{ NodeTag type; List *funcname; /* qualified name of function */ List *args; /* the arguments (list of exprs) */ bool agg_star; /* argument was really '*' */ bool agg_distinct; /* arguments were labeled DISTINCT */} FuncCall;/* * A_Indices - array reference or bounds ([lidx:uidx] or [uidx]) */typedef struct A_Indices{ NodeTag type; Node *lidx; /* could be NULL */ Node *uidx;} A_Indices;/* * A_Indirection - select a field and/or array element from an expression * * The indirection list can contain both A_Indices nodes (representing * subscripting) and string Value nodes (representing field selection * --- the string value is the name of the field to select). For example, * a complex selection operation like * (foo).field1[42][7].field2 * would be represented with a single A_Indirection node having a 4-element * indirection list. * * Note: as of Postgres 8.0, we don't support arrays of composite values, * so cases in which a field select follows a subscript aren't actually * semantically legal. However the parser is prepared to handle such. */typedef struct A_Indirection{ NodeTag type; Node *arg; /* the thing being selected from */ List *indirection; /* subscripts and/or field names */} A_Indirection;/* * ResTarget - * result target (used in target list of pre-transformed parse trees) * * In a SELECT or INSERT target list, 'name' is the column label from an * 'AS ColumnLabel' clause, or NULL if there was none, and 'val' is the * value expression itself. The 'indirection' field is not used. * * INSERT has a second ResTarget list which is the target-column-names list. * Here, 'val' is not used, 'name' is the name of the destination column, * and 'indirection' stores any subscripts attached to the destination. * * In an UPDATE target list, 'name' is the name of the destination column, * 'indirection' stores any subscripts attached to the destination, and * 'val' is the expression to assign. * * See A_Indirection for more info about what can appear in 'indirection'. */typedef struct ResTarget{ NodeTag type; char *name; /* column name or NULL */ List *indirection; /* subscripts and field names, or NIL */ Node *val; /* the value expression to compute or assign */} ResTarget;/* * SortBy - for ORDER BY clause */#define SORTBY_ASC 1#define SORTBY_DESC 2#define SORTBY_USING 3typedef struct SortBy{ NodeTag type; int sortby_kind; /* see codes above */ List *useOp; /* name of op to use, if SORTBY_USING */ Node *node; /* expression to sort on */} SortBy;/* * RangeSubselect - subquery appearing in a FROM clause */typedef struct RangeSubselect{ NodeTag type; Node *subquery; /* the untransformed sub-select clause */ Alias *alias; /* table alias & optional column aliases */} RangeSubselect;/* * RangeFunction - function call appearing in a FROM clause */typedef struct RangeFunction{ NodeTag type; Node *funccallnode; /* untransformed function call tree */ Alias *alias; /* table alias & optional column aliases */ List *coldeflist; /* list of ColumnDef nodes for runtime * assignment of RECORD TupleDesc */} RangeFunction;/* * ColumnDef - column definition (used in various creates) * * If the column has a default value, we may have the value expression * in either "raw" form (an untransformed parse tree) or "cooked" form * (the nodeToString representation of an executable expression tree), * depending on how this ColumnDef node was created (by parsing, or by * inheritance from an existing relation). We should never have both * in the same node! * * The constraints list may contain a CONSTR_DEFAULT item in a raw * parsetree produced by gram.y, but transformCreateStmt will remove * the item and set raw_default instead. CONSTR_DEFAULT items * should not appear in any subsequent processing. * * The "support" field, if not null, denotes a supporting relation that * should be linked by an internal dependency to the column. Currently * this is only used to link a SERIAL column's sequence to the column. */typedef struct ColumnDef{ NodeTag type; char *colname; /* name of column */ TypeName *typename; /* type of column */ int inhcount; /* number of times column is inherited */ bool is_local; /* column has local (non-inherited) def'n */ bool is_not_null; /* NOT NULL constraint specified? */ Node *raw_default; /* default value (untransformed parse tree) */ char *cooked_default; /* nodeToString representation */ List *constraints; /* other constraints on column */ RangeVar *support; /* supporting relation, if any */} ColumnDef;/* * inhRelation - Relations a CREATE TABLE is to inherit attributes of */typedef struct InhRelation{ NodeTag type; RangeVar *relation; bool including_defaults;} InhRelation;/* * IndexElem - index parameters (used in CREATE INDEX) * * For a plain index attribute, 'name' is the name of the table column to * index, and 'expr' is NULL. For an index expression, 'name' is NULL and * 'expr' is the expression tree. */typedef struct IndexElem{ NodeTag type; char *name; /* name of attribute to index, or NULL */ Node *expr; /* expression to index, or NULL */ List *opclass; /* name of desired opclass; NIL = default */} IndexElem;/* * DefElem - * a definition (used in definition lists in the form of defname = arg) */typedef struct DefElem{ NodeTag type; char *defname; Node *arg; /* a (Value *) or a (TypeName *) */} DefElem;/* * LockingClause - raw representation of FOR UPDATE/SHARE options * * Note: lockedRels == NIL means "all relations in query". Otherwise it * is a list of String nodes giving relation eref names. */typedef struct LockingClause{ NodeTag type; List *lockedRels; /* FOR UPDATE or FOR SHARE relations */ bool forUpdate; /* true = FOR UPDATE, false = FOR SHARE */ bool nowait; /* NOWAIT option */} LockingClause;/**************************************************************************** * Nodes for a Query tree ****************************************************************************//*-------------------- * RangeTblEntry - * A range table is a List of RangeTblEntry nodes. * * A range table entry may represent a plain relation, a sub-select in * FROM, or the result of a JOIN clause. (Only explicit JOIN syntax * produces an RTE, not the implicit join resulting from multiple FROM * items. This is because we only need the RTE to deal with SQL features * like outer joins and join-output-column aliasing.) Other special * RTE types also exist, as indicated by RTEKind. * * alias is an Alias node representing the AS alias-clause attached to the * FROM expression, or NULL if no clause. * * eref is the table reference name and column reference names (either * real or aliases). Note that system columns (OID etc) are not included * in the column list. * eref->aliasname is required to be present, and should generally be used * to identify the RTE for error messages etc. * * In RELATION RTEs, the colnames in both alias and eref are indexed by * physical attribute number; this means there must be colname entries for * dropped columns. When building an RTE we insert empty strings ("") for * dropped columns. Note however that a stored rule may have nonempty * colnames for columns dropped since the rule was created (and for that * matter the colnames might be out of date due to column renamings). * The same comments apply to FUNCTION RTEs when the function's return type * is a named composite type. * * In JOIN RTEs, the colnames in both alias and eref are one-to-one with * joinaliasvars entries. A JOIN RTE will omit columns of its inputs when * those columns are known to be dropped at parse time. Again, however, * a stored rule might contain entries for columns dropped since the rule * was created. (This is only possible for columns not actually referenced * in the rule.) When loading a stored rule, we replace the joinaliasvars * items for any such columns with NULL Consts. (We can't simply delete
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -