1 /*-------------------------------------------------------------------------
4 * definitions for parse tree nodes
7 * Copyright (c) 1994, Regents of the University of California
9 * $Id: parsenodes.h,v 1.83 1999/10/03 23:55:36 tgl Exp $
11 *-------------------------------------------------------------------------
16 #include "nodes/primnodes.h"
18 /*****************************************************************************
20 *****************************************************************************/
24 * all statments are turned into a Query tree (via transformStmt)
25 * for further processing by the optimizer
26 * utility statements (i.e. non-optimizable statements)
27 * have the *utilityStmt field set.
29 * we need the isPortal flag because portal names can be null too; can
30 * get rid of it if we support CURSOR as a commandType.
37 CmdType commandType; /* select|insert|update|delete|utility */
39 Node *utilityStmt; /* non-null if this is a non-optimizable
42 int resultRelation; /* target relation (index to rtable) */
43 char *into; /* portal (cursor) name */
44 bool isPortal; /* is this a retrieve into portal? */
45 bool isBinary; /* binary portal? */
46 bool isTemp; /* is 'into' a temp table? */
47 bool unionall; /* union without unique sort */
48 bool hasAggs; /* has aggregates in target list */
49 bool hasSubLinks; /* has subquery SubLink */
51 List *rtable; /* list of range table entries */
52 List *targetList; /* target list (of TargetEntry) */
53 Node *qual; /* qualifications applied to tuples */
54 List *rowMark; /* list of RowMark entries */
56 char *uniqueFlag; /* NULL, '*', or Unique attribute name */
57 List *sortClause; /* a list of SortClause's */
59 List *groupClause; /* a list of GroupClause's */
61 Node *havingQual; /* qualifications applied to groups */
63 List *intersectClause;
64 List *unionClause; /* unions are linked under the previous
67 Node *limitOffset; /* # of result tuples to skip */
68 Node *limitCount; /* # of result tuples to return */
70 /* internal to planner */
71 List *base_rel_list; /* list of base-relation RelOptInfos */
72 List *join_rel_list; /* list of join-relation RelOptInfos */
73 List *query_pathkeys; /* pathkeys for query_planner()'s result */
77 /*****************************************************************************
78 * Other Statements (no optimizations required)
80 * Some of them require a little bit of transformation (which is also
81 * done by transformStmt). The whole structure is then passed on to
82 * ProcessUtility (by-passing the optimization step) as the utilityStmt
84 *****************************************************************************/
86 /* ----------------------
87 * Add Column Statement
88 * ----------------------
90 typedef struct AddAttrStmt
93 char *relname; /* the relation to add attr */
94 bool inh; /* add recursively to children? */
95 Node *colDef; /* the attribute definition */
98 /* ----------------------
99 * Change ACL Statement
100 * ----------------------
102 typedef struct ChangeACLStmt
105 struct AclItem *aclitem;
110 /* ----------------------
111 * Close Portal Statement
112 * ----------------------
114 typedef struct ClosePortalStmt
117 char *portalname; /* name of the portal (cursor) */
120 /* ----------------------
122 * ----------------------
124 typedef struct CopyStmt
127 bool binary; /* is a binary copy? */
128 char *relname; /* the relation to copy */
129 bool oids; /* copy oid's? */
130 int direction; /* TO or FROM */
131 char *filename; /* if NULL, use stdin/stdout */
132 char *delimiter; /* delimiter character, \t by default */
135 /* ----------------------
136 * Create Table Statement
137 * ----------------------
139 typedef struct CreateStmt
142 bool istemp; /* is this a temp table? */
143 char *relname; /* name of relation to create */
144 List *tableElts; /* column definitions (list of ColumnDef) */
145 List *inhRelnames; /* relations to inherit from (list of
146 * T_String Values) */
147 List *constraints; /* list of constraints (Constraint nodes) */
150 typedef enum ConstrType /* types of constraints */
152 CONSTR_NULL, CONSTR_NOTNULL, CONSTR_DEFAULT, CONSTR_CHECK,
153 CONSTR_PRIMARY, CONSTR_UNIQUE
157 * For constraints that use expressions (CONSTR_DEFAULT, CONSTR_CHECK)
158 * we may have the expression in either "raw" form (an untransformed
159 * parse tree) or "cooked" form (the nodeToString representation of
160 * an executable expression tree), depending on how this Constraint
161 * node was created (by parsing, or by inheritance from an existing
162 * relation). We should never have both in the same node!
165 typedef struct Constraint
169 char *name; /* name */
170 Node *raw_expr; /* untransformed parse tree */
171 char *cooked_expr; /* nodeToString representation */
172 List *keys; /* list of primary keys */
175 /* ----------------------
176 * Create/Drop TRIGGER Statements
177 * ----------------------
180 typedef struct CreateTrigStmt
183 char *trigname; /* TRIGGER' name */
184 char *relname; /* triggered relation */
185 char *funcname; /* function to call (or NULL) */
186 List *args; /* list of (T_String) Values or NULL */
187 bool before; /* BEFORE/AFTER */
188 bool row; /* ROW/STATEMENT */
189 char actions[4]; /* Insert, Update, Delete */
190 char *lang; /* NULL (which means Clanguage) */
191 char *text; /* AS 'text' */
192 List *attr; /* UPDATE OF a, b,... (NI) or NULL */
193 char *when; /* WHEN 'a > 10 ...' (NI) or NULL */
195 /* The following are used for referential */
196 /* integrity constraint triggers */
197 bool isconstraint; /* This is an RI trigger */
198 bool deferrable; /* [NOT] DEFERRABLE */
199 bool initdeferred; /* INITIALLY {DEFERRED|IMMEDIATE} */
200 char *constrrelname; /* opposite relation */
203 typedef struct DropTrigStmt
206 char *trigname; /* TRIGGER' name */
207 char *relname; /* triggered relation */
211 /* ----------------------
212 * Create/Drop PROCEDURAL LANGUAGE Statement
213 * ----------------------
215 typedef struct CreatePLangStmt
218 char *plname; /* PL name */
219 char *plhandler; /* PL call handler function */
220 char *plcompiler; /* lancompiler text */
221 bool pltrusted; /* PL is trusted */
224 typedef struct DropPLangStmt
227 char *plname; /* PL name */
231 /* ----------------------
232 * Create/Alter/Drop User Statements
233 * ----------------------
235 typedef struct CreateUserStmt
238 char *user; /* PostgreSQL user login */
239 char *password; /* PostgreSQL user password */
240 bool *createdb; /* Can the user create databases? */
241 bool *createuser; /* Can this user create users? */
242 List *groupElts; /* The groups the user is a member of */
243 char *validUntil; /* The time the login is valid until */
246 typedef CreateUserStmt AlterUserStmt;
248 typedef struct DropUserStmt
251 char *user; /* PostgreSQL user login */
255 /* ----------------------
256 * Create SEQUENCE Statement
257 * ----------------------
260 typedef struct CreateSeqStmt
263 char *seqname; /* the relation to create */
267 /* ----------------------
268 * Create Version Statement
269 * ----------------------
271 typedef struct VersionStmt
274 char *relname; /* the new relation */
275 int direction; /* FORWARD | BACKWARD */
276 char *fromRelname; /* relation to create a version */
277 char *date; /* date of the snapshot */
280 /* ----------------------
281 * Create {Operator|Type|Aggregate} Statement
282 * ----------------------
284 typedef struct DefineStmt
287 int defType; /* OPERATOR|P_TYPE|AGGREGATE */
289 List *definition; /* a list of DefElem */
292 /* ----------------------
293 * Drop Table Statement
294 * ----------------------
296 typedef struct DestroyStmt
299 List *relNames; /* relations to be dropped */
303 /* ----------------------
304 * Truncate Table Statement
305 * ----------------------
307 typedef struct TruncateStmt
310 char *relName; /* relation to be truncated */
313 /* ----------------------
314 * Extend Index Statement
315 * ----------------------
317 typedef struct ExtendStmt
320 char *idxname; /* name of the index */
321 Node *whereClause; /* qualifications */
322 List *rangetable; /* range table, filled in by
326 /* ----------------------
327 * Begin Recipe Statement
328 * ----------------------
330 typedef struct RecipeStmt
333 char *recipeName; /* name of the recipe */
336 /* ----------------------
338 * ----------------------
340 typedef struct FetchStmt
343 int direction; /* FORWARD or BACKWARD */
344 int howMany; /* amount to fetch ("ALL" --> 0) */
345 char *portalname; /* name of portal (cursor) */
346 bool ismove; /* TRUE if MOVE */
349 /* ----------------------
350 * Create Index Statement
351 * ----------------------
353 typedef struct IndexStmt
356 char *idxname; /* name of the index */
357 char *relname; /* name of relation to index on */
358 char *accessMethod; /* name of acess methood (eg. btree) */
359 List *indexParams; /* a list of IndexElem */
360 List *withClause; /* a list of DefElem */
361 Node *whereClause; /* qualifications */
362 List *rangetable; /* range table, filled in by
364 bool *lossy; /* is index lossy? */
365 bool unique; /* is index unique? */
366 bool primary; /* is index on primary key? */
369 /* ----------------------
370 * Create Function Statement
371 * ----------------------
373 typedef struct ProcedureStmt
376 char *funcname; /* name of function to create */
377 List *defArgs; /* list of definitions a list of strings
379 Node *returnType; /* the return type (as a string or a
380 * TypeName (ie.setof) */
381 List *withClause; /* a list of DefElem */
382 List *as; /* the SQL statement or filename */
383 char *language; /* C or SQL */
386 /* ----------------------
387 * Drop Aggregate Statement
388 * ----------------------
390 typedef struct RemoveAggrStmt
393 char *aggname; /* aggregate to drop */
394 char *aggtype; /* for this type */
397 /* ----------------------
398 * Drop Function Statement
399 * ----------------------
401 typedef struct RemoveFuncStmt
404 char *funcname; /* function to drop */
405 List *args; /* types of the arguments */
408 /* ----------------------
409 * Drop Operator Statement
410 * ----------------------
412 typedef struct RemoveOperStmt
415 char *opname; /* operator to drop */
416 List *args; /* types of the arguments */
419 /* ----------------------
420 * Drop {Type|Index|Rule|View} Statement
421 * ----------------------
423 typedef struct RemoveStmt
426 int removeType; /* P_TYPE|INDEX|RULE|VIEW */
427 char *name; /* name to drop */
430 /* ----------------------
431 * Alter Table Statement
432 * ----------------------
434 typedef struct RenameStmt
437 char *relname; /* relation to be altered */
438 bool inh; /* recursively alter children? */
439 char *column; /* if NULL, rename the relation name to
440 * the new name. Otherwise, rename this
442 char *newname; /* the new name */
445 /* ----------------------
446 * Create Rule Statement
447 * ----------------------
449 typedef struct RuleStmt
452 char *rulename; /* name of the rule */
453 Node *whereClause; /* qualifications */
454 CmdType event; /* RETRIEVE */
455 struct Attr *object; /* object affected */
456 bool instead; /* is a 'do instead'? */
457 List *actions; /* the action statements */
460 /* ----------------------
462 * ----------------------
464 typedef struct NotifyStmt
467 char *relname; /* relation to notify */
470 /* ----------------------
472 * ----------------------
474 typedef struct ListenStmt
477 char *relname; /* relation to listen on */
480 /* ----------------------
482 * ----------------------
484 typedef struct UnlistenStmt
487 char *relname; /* relation to unlisten on */
490 /* ----------------------
491 * {Begin|Abort|End} Transaction Statement
492 * ----------------------
494 typedef struct TransactionStmt
497 int command; /* BEGIN|END|ABORT */
500 /* ----------------------
501 * Create View Statement
502 * ----------------------
504 typedef struct ViewStmt
507 char *viewname; /* name of the view */
508 Query *query; /* the SQL statement */
511 /* ----------------------
513 * ----------------------
515 typedef struct LoadStmt
518 char *filename; /* file to load */
521 /* ----------------------
523 * ----------------------
525 typedef struct CreatedbStmt
528 char *dbname; /* database to create */
529 char *dbpath; /* location of database */
530 int encoding; /* default encoding (see regex/pg_wchar.h) */
533 /* ----------------------
534 * Destroydb Statement
535 * ----------------------
537 typedef struct DestroydbStmt
540 char *dbname; /* database to drop */
543 /* ----------------------
544 * Cluster Statement (support pbrown's cluster index implementation)
545 * ----------------------
547 typedef struct ClusterStmt
550 char *relname; /* relation being indexed */
551 char *indexname; /* original index defined */
554 /* ----------------------
556 * ----------------------
558 typedef struct VacuumStmt
561 bool verbose; /* print status info */
562 bool analyze; /* analyze data */
563 char *vacrel; /* table to vacuum */
564 List *va_spec; /* columns to analyse */
567 /* ----------------------
569 * ----------------------
571 typedef struct ExplainStmt
574 Query *query; /* the query */
575 bool verbose; /* print plan info */
578 /* ----------------------
580 * ----------------------
583 typedef struct VariableSetStmt
590 /* ----------------------
592 * ----------------------
595 typedef struct VariableShowStmt
601 /* ----------------------
603 * ----------------------
606 typedef struct VariableResetStmt
612 /* ----------------------
614 * ----------------------
616 typedef struct LockStmt
619 char *relname; /* relation to lock */
620 int mode; /* lock mode */
624 /* ----------------------
625 * SET CONSTRAINTS Statement
626 * ----------------------
628 typedef struct ConstraintsSetStmt
633 } ConstraintsSetStmt;
636 /*****************************************************************************
637 * Optimizable Statements
638 *****************************************************************************/
640 /* ----------------------
642 * ----------------------
644 typedef struct InsertStmt
647 char *relname; /* relation to insert into */
648 char *unique; /* NULL, '*', or unique attribute name */
649 List *cols; /* names of the columns */
650 List *targetList; /* the target list (of ResTarget) */
651 List *fromClause; /* the from clause */
652 Node *whereClause; /* qualifications */
653 List *groupClause; /* GROUP BY clauses */
654 Node *havingClause; /* having conditional-expression */
655 List *unionClause; /* union subselect parameters */
656 bool unionall; /* union without unique sort */
657 List *intersectClause;
658 List *forUpdate; /* FOR UPDATE clause */
661 /* ----------------------
663 * ----------------------
665 typedef struct DeleteStmt
668 char *relname; /* relation to delete from */
669 Node *whereClause; /* qualifications */
672 /* ----------------------
674 * ----------------------
676 typedef struct UpdateStmt
679 char *relname; /* relation to update */
680 List *targetList; /* the target list (of ResTarget) */
681 Node *whereClause; /* qualifications */
682 List *fromClause; /* the from clause */
685 /* ----------------------
687 * ----------------------
689 typedef struct SelectStmt
692 char *unique; /* NULL, '*', or unique attribute name */
693 char *into; /* name of table (for select into table) */
694 List *targetList; /* the target list (of ResTarget) */
695 List *fromClause; /* the from clause */
696 Node *whereClause; /* qualifications */
697 List *groupClause; /* GROUP BY clauses */
698 Node *havingClause; /* having conditional-expression */
699 List *intersectClause;
702 List *unionClause; /* union subselect parameters */
703 List *sortClause; /* sort clause (a list of SortGroupBy's) */
704 char *portalname; /* the portal (cursor) to create */
705 bool binary; /* a binary (internal) portal? */
706 bool istemp; /* into is a temp table */
707 bool unionall; /* union without unique sort */
708 Node *limitOffset; /* # of result tuples to skip */
709 Node *limitCount; /* # of result tuples to return */
710 List *forUpdate; /* FOR UPDATE clause */
713 /****************************************************************************
714 * Supporting data structures for Parse Trees
715 ****************************************************************************/
718 * TypeName - specifies a type in definitions
720 typedef struct TypeName
723 char *name; /* name of the type */
724 bool timezone; /* timezone specified? */
725 bool setof; /* is a set? */
726 int32 typmod; /* type modifier */
727 List *arrayBounds; /* array bounds */
731 * ParamNo - specifies a parameter reference
733 typedef struct ParamNo
736 int number; /* the number of the parameter */
737 TypeName *typename; /* the typecast */
738 List *indirection; /* array references */
742 * A_Expr - binary expressions
744 typedef struct A_Expr
747 int oper; /* type of operation
748 * {OP,OR,AND,NOT,ISNULL,NOTNULL} */
749 char *opname; /* name of operator/function */
750 Node *lexpr; /* left argument */
751 Node *rexpr; /* right argument */
756 * specifies an Attribute (ie. a Column); could have nested dots or
763 char *relname; /* name of relation (can be "*") */
764 ParamNo *paramNo; /* or a parameter */
765 List *attrs; /* attributes (possibly nested); list of
766 * Values (strings) */
767 List *indirection; /* array refs (list of A_Indices') */
771 * A_Const - a constant expression
773 typedef struct A_Const
776 Value val; /* the value (with the tag) */
777 TypeName *typename; /* typecast */
781 * CaseExpr - a CASE expression
783 typedef struct CaseExpr
787 Node *arg; /* implicit equality comparison argument */
788 List *args; /* the arguments (list of WHEN clauses) */
789 Node *defresult; /* the default result (ELSE clause) */
793 * CaseWhen - an argument to a CASE expression
795 typedef struct CaseWhen
798 Node *expr; /* comparison expression */
799 Node *result; /* substitution result */
803 * ColumnDef - column definition (used in various creates)
805 * If the column has a default value, we may have the value expression
806 * in either "raw" form (an untransformed parse tree) or "cooked" form
807 * (the nodeToString representation of an executable expression tree),
808 * depending on how this ColumnDef node was created (by parsing, or by
809 * inheritance from an existing relation). We should never have both
812 * The constraints list may contain a CONSTR_DEFAULT item in a raw
813 * parsetree produced by gram.y, but transformCreateStmt will remove
814 * the item and set raw_default instead. CONSTR_DEFAULT items
815 * should not appear in any subsequent processing.
817 typedef struct ColumnDef
820 char *colname; /* name of column */
821 TypeName *typename; /* type of column */
822 bool is_not_null; /* flag to NOT NULL constraint */
823 bool is_sequence; /* is a sequence? */
824 Node *raw_default; /* default value (untransformed parse tree) */
825 char *cooked_default; /* nodeToString representation */
826 List *constraints; /* other constraints on column */
831 * an identifier (could be an attribute or a relation name). Depending
832 * on the context at transformStmt time, the identifier is treated as
833 * either a relation name (in which case, isRel will be set) or an
834 * attribute (in which case, it will be transformed into an Attr).
839 char *name; /* its name */
840 List *indirection; /* array references */
841 bool isRel; /* is a relation - filled in by
846 * FuncCall - a function/aggregate invocation
848 typedef struct FuncCall
851 char *funcname; /* name of function */
852 List *args; /* the arguments (list of exprs) */
856 * A_Indices - array reference or bounds ([lidx:uidx] or [uidx])
858 typedef struct A_Indices
861 Node *lidx; /* could be NULL */
867 * result target (used in target list of pre-transformed Parse trees)
869 * In a SELECT or INSERT target list, 'name' is either NULL or
870 * the column name assigned to the value. (If there is an 'AS ColumnLabel'
871 * clause, the grammar sets 'name' from it; otherwise 'name' is initially NULL
872 * and is filled in during the parse analysis phase.)
873 * The 'indirection' field is not used at all.
875 * In an UPDATE target list, 'name' is the name of the destination column,
876 * and 'indirection' stores any subscripts attached to the destination.
877 * That is, our representation is UPDATE table SET name [indirection] = val.
879 typedef struct ResTarget
882 char *name; /* column name or NULL */
883 List *indirection; /* subscripts for destination column, or
885 Node *val; /* the value expression to compute or
890 * RelExpr - relation expressions
892 typedef struct RelExpr
895 char *relname; /* the relation name */
896 bool inh; /* inheritance query */
900 * SortGroupBy - for ORDER BY clause
902 typedef struct SortGroupBy
905 char *useOp; /* operator to use */
906 Node *node; /* Expression */
910 * RangeVar - range variable, used in FROM clauses
912 typedef struct RangeVar
915 RelExpr *relExpr; /* the relation expression */
916 char *name; /* the name to be referenced (optional) */
920 * IndexElem - index parameters (used in CREATE INDEX)
922 typedef struct IndexElem
925 char *name; /* name of index */
926 List *args; /* if not NULL, function index */
928 TypeName *typename; /* type of index's keys (optional) */
933 * a definition (used in definition lists in the form of defname = arg)
935 typedef struct DefElem
939 Node *arg; /* a (Value *) or a (TypeName *) */
943 * JoinExpr - for JOIN expressions
945 typedef struct JoinExpr
955 /****************************************************************************
956 * Nodes for a Query tree
957 ****************************************************************************/
961 * a target entry (used in the transformed target list)
963 * one of resdom or fjoin is not NULL. a target list is
964 * ((<resdom | fjoin> expr) (<resdom | fjoin> expr) ...)
966 typedef struct TargetEntry
969 Resdom *resdom; /* fjoin overload this to be a list?? */
971 Node *expr; /* can be a list too */
976 * used in range tables. Some of the following are only used in one of
977 * the parsing, optimizing, execution stages.
979 * inFromCl marks those range variables that are listed in the from clause.
980 * In SQL, the targetlist can only refer to range variables listed in the
981 * from clause but POSTQUEL allows you to refer to tables not specified, in
982 * which case a range table entry will be generated. We use POSTQUEL
983 * semantics which is more powerful. However, we need SQL semantics in
984 * some cases (eg. when expanding a '*')
986 typedef struct RangeTblEntry
989 char *relname; /* real name of the relation */
990 char *refname; /* the reference name (specified in the
993 bool inh; /* inheritance? */
994 bool inFromCl; /* comes from From Clause */
995 bool skipAcl; /* skip ACL check in executor */
1000 * representation of ORDER BY clauses
1002 * tleSortGroupRef must match ressortgroupref of exactly one Resdom of the
1003 * associated targetlist; that is the expression to be sorted (or grouped) by.
1004 * sortop is the OID of the ordering operator.
1006 typedef struct SortClause
1009 Index tleSortGroupRef;/* reference into targetlist */
1010 Oid sortop; /* the sort operator to use */
1015 * representation of GROUP BY clauses
1017 * GroupClause is exactly like SortClause except for the nodetag value
1018 * (and it's probably not even really necessary to have two different
1019 * nodetags...). We have routines that operate interchangeably on both.
1021 typedef SortClause GroupClause;
1023 #define ROW_MARK_FOR_UPDATE (1 << 0)
1024 #define ROW_ACL_FOR_UPDATE (1 << 1)
1026 typedef struct RowMark
1029 Index rti; /* index in Query->rtable */
1030 bits8 info; /* as above */
1033 #endif /* PARSENODES_H */