1 /*-------------------------------------------------------------------------
4 * definitions for parse tree nodes
7 * Copyright (c) 1994, Regents of the University of California
9 * $Id: parsenodes.h,v 1.35 1997/11/24 05:09:50 momjian 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? */
47 char *uniqueFlag; /* NULL, '*', or Unique attribute name */
48 List *sortClause; /* a list of SortClause's */
50 List *rtable; /* list of range table entries */
51 List *targetList; /* target list (of TargetEntry) */
52 Node *qual; /* qualifications */
54 List *groupClause; /* list of columns to specified in GROUP
56 Node *havingQual; /* qualification of each group */
58 int qry_numAgg; /* number of aggregates in the target list */
59 Aggreg **qry_aggs; /* the aggregates */
61 /* internal to planner */
62 List *base_relation_list_; /* base relation list */
63 List *join_relation_list_; /* list of relations */
67 /*****************************************************************************
68 * Other Statements (no optimizations required)
70 * Some of them require a little bit of transformation (which is also
71 * done by transformStmt). The whole structure is then passed on to
72 * ProcessUtility (by-passing the optimization step) as the utilityStmt
74 *****************************************************************************/
76 /* ----------------------
77 * Add Column Statement
78 * ----------------------
80 typedef struct AddAttrStmt
83 char *relname; /* the relation to add attr */
84 bool inh; /* add recursively to children? */
85 struct ColumnDef *colDef; /* the attribute definition */
88 /* ----------------------
89 * Change ACL Statement
90 * ----------------------
92 typedef struct ChangeACLStmt
95 struct AclItem *aclitem;
100 /* ----------------------
101 * Close Portal Statement
102 * ----------------------
104 typedef struct ClosePortalStmt
107 char *portalname; /* name of the portal (cursor) */
110 /* ----------------------
112 * ----------------------
114 typedef struct CopyStmt
117 bool binary; /* is a binary copy? */
118 char *relname; /* the relation to copy */
119 bool oids; /* copy oid's? */
120 int direction; /* TO or FROM */
121 char *filename; /* if NULL, use stdin/stdout */
122 char *delimiter; /* delimiter character, \t by default */
125 /* ----------------------
126 * Create Table Statement
127 * ----------------------
129 typedef struct CreateStmt
132 char *relname; /* the relation to create */
133 List *tableElts; /* column definitions list of ColumnDef */
134 List *inhRelnames; /* relations to inherit from list of Value
136 List *constraints; /* list of constraints (ConstaintDef) */
139 typedef enum ConstrType
141 CONSTR_NONE, CONSTR_CHECK /* type of constaints */
144 typedef struct ConstraintDef
147 char *name; /* name */
148 void *def; /* definition */
151 /* ----------------------
152 * Create/Drop TRIGGER Statements
153 * ----------------------
156 typedef struct CreateTrigStmt
159 char *trigname; /* TRIGGER' name */
160 char *relname; /* triggered relation */
161 char *funcname; /* function to call (or NULL) */
162 List *args; /* list of (T_String) Values or NULL */
163 bool before; /* BEFORE/AFTER */
164 bool row; /* ROW/STATEMENT */
165 char actions[4]; /* Insert, Update, Delete */
166 char *lang; /* NULL (which means Clanguage) */
167 char *text; /* AS 'text' */
168 List *attr; /* UPDATE OF a, b,... (NI) or NULL */
169 char *when; /* WHEN 'a > 10 ...' (NI) or NULL */
172 typedef struct DropTrigStmt
175 char *trigname; /* TRIGGER' name */
176 char *relname; /* triggered relation */
180 /* ----------------------
181 * Create/Drop PROCEDURAL LANGUAGE Statement
182 * ----------------------
184 typedef struct CreatePLangStmt
187 char *plname; /* PL name */
188 char *plhandler; /* PL call handler function */
189 char *plcompiler; /* lancompiler text */
190 bool pltrusted; /* PL is trusted */
193 typedef struct DropPLangStmt
196 char *plname; /* PL name */
200 /* ----------------------
201 * Create SEQUENCE Statement
202 * ----------------------
205 typedef struct CreateSeqStmt
208 char *seqname; /* the relation to create */
212 /* ----------------------
213 * Create Version Statement
214 * ----------------------
216 typedef struct VersionStmt
219 char *relname; /* the new relation */
220 int direction; /* FORWARD | BACKWARD */
221 char *fromRelname; /* relation to create a version */
222 char *date; /* date of the snapshot */
225 /* ----------------------
226 * Create {Operator|Type|Aggregate} Statement
227 * ----------------------
229 typedef struct DefineStmt
232 int defType; /* OPERATOR|P_TYPE|AGGREGATE */
234 List *definition; /* a list of DefElem */
237 /* ----------------------
238 * Drop Table Statement
239 * ----------------------
241 typedef struct DestroyStmt
244 List *relNames; /* relations to be dropped */
248 /* ----------------------
249 * Extend Index Statement
250 * ----------------------
252 typedef struct ExtendStmt
255 char *idxname; /* name of the index */
256 Node *whereClause; /* qualifications */
257 List *rangetable; /* range table, filled in by
261 /* ----------------------
262 * Begin Recipe Statement
263 * ----------------------
265 typedef struct RecipeStmt
268 char *recipeName; /* name of the recipe */
271 /* ----------------------
273 * ----------------------
275 typedef struct FetchStmt
278 int direction; /* FORWARD or BACKWARD */
279 int howMany; /* amount to fetch ("ALL" --> 0) */
280 char *portalname; /* name of portal (cursor) */
281 bool ismove; /* TRUE if MOVE */
284 /* ----------------------
285 * Create Index Statement
286 * ----------------------
288 typedef struct IndexStmt
291 char *idxname; /* name of the index */
292 char *relname; /* name of relation to index on */
293 char *accessMethod; /* name of acess methood (eg. btree) */
294 List *indexParams; /* a list of IndexElem */
295 List *withClause; /* a list of ParamString */
296 Node *whereClause; /* qualifications */
297 List *rangetable; /* range table, filled in by
299 bool *lossy; /* is index lossy? */
300 bool unique; /* is index unique? */
303 /* ----------------------
304 * Create Function Statement
305 * ----------------------
307 typedef struct ProcedureStmt
310 char *funcname; /* name of function to create */
311 List *defArgs; /* list of definitions a list of strings
313 Node *returnType; /* the return type (as a string or a
314 * TypeName (ie.setof) */
315 List *withClause; /* a list of ParamString */
316 char *as; /* the SQL statement or filename */
317 char *language; /* C or SQL */
320 /* ----------------------
321 * Drop Aggregate Statement
322 * ----------------------
324 typedef struct RemoveAggrStmt
327 char *aggname; /* aggregate to drop */
328 char *aggtype; /* for this type */
331 /* ----------------------
332 * Drop Function Statement
333 * ----------------------
335 typedef struct RemoveFuncStmt
338 char *funcname; /* function to drop */
339 List *args; /* types of the arguments */
342 /* ----------------------
343 * Drop Operator Statement
344 * ----------------------
346 typedef struct RemoveOperStmt
349 char *opname; /* operator to drop */
350 List *args; /* types of the arguments */
353 /* ----------------------
354 * Drop {Type|Index|Rule|View} Statement
355 * ----------------------
357 typedef struct RemoveStmt
360 int removeType; /* P_TYPE|INDEX|RULE|VIEW */
361 char *name; /* name to drop */
364 /* ----------------------
365 * Alter Table Statement
366 * ----------------------
368 typedef struct RenameStmt
371 char *relname; /* relation to be altered */
372 bool inh; /* recursively alter children? */
373 char *column; /* if NULL, rename the relation name to
374 * the new name. Otherwise, rename this
376 char *newname; /* the new name */
379 /* ----------------------
380 * Create Rule Statement
381 * ----------------------
383 typedef struct RuleStmt
386 char *rulename; /* name of the rule */
387 Node *whereClause; /* qualifications */
388 CmdType event; /* RETRIEVE */
389 struct Attr *object; /* object affected */
390 bool instead; /* is a 'do instead'? */
391 List *actions; /* the action statements */
394 /* ----------------------
396 * ----------------------
398 typedef struct NotifyStmt
401 char *relname; /* relation to notify */
404 /* ----------------------
406 * ----------------------
408 typedef struct ListenStmt
411 char *relname; /* relation to listen on */
414 /* ----------------------
415 * {Begin|Abort|End} Transaction Statement
416 * ----------------------
418 typedef struct TransactionStmt
421 int command; /* BEGIN|END|ABORT */
424 /* ----------------------
425 * Create View Statement
426 * ----------------------
428 typedef struct ViewStmt
431 char *viewname; /* name of the view */
432 Query *query; /* the SQL statement */
435 /* ----------------------
437 * ----------------------
439 typedef struct LoadStmt
442 char *filename; /* file to load */
445 /* ----------------------
447 * ----------------------
449 typedef struct CreatedbStmt
452 char *dbname; /* database to create */
453 char *dbpath; /* location of database */
456 /* ----------------------
457 * Destroydb Statement
458 * ----------------------
460 typedef struct DestroydbStmt
463 char *dbname; /* database to drop */
466 /* ----------------------
467 * Cluster Statement (support pbrown's cluster index implementation)
468 * ----------------------
470 typedef struct ClusterStmt
473 char *relname; /* relation being indexed */
474 char *indexname; /* original index defined */
477 /* ----------------------
479 * ----------------------
481 typedef struct VacuumStmt
484 bool verbose; /* print status info */
485 bool analyze; /* analyze data */
486 char *vacrel; /* table to vacuum */
487 List *va_spec; /* columns to analyse */
490 /* ----------------------
492 * ----------------------
494 typedef struct ExplainStmt
497 Query *query; /* the query */
498 bool verbose; /* print plan info */
501 /* ----------------------
503 * ----------------------
506 typedef struct VariableSetStmt
513 /* ----------------------
515 * ----------------------
518 typedef struct VariableShowStmt
524 /* ----------------------
526 * ----------------------
529 typedef struct VariableResetStmt
536 /*****************************************************************************
537 * Optimizable Statements
538 *****************************************************************************/
540 /* ----------------------
542 * ----------------------
544 typedef struct AppendStmt
547 char *relname; /* relation to insert into */
548 List *cols; /* names of the columns */
549 List *targetList; /* the target list (of ResTarget) */
550 List *fromClause; /* the from clause */
551 Node *whereClause; /* qualifications */
554 /* ----------------------
556 * ----------------------
558 typedef struct DeleteStmt
561 char *relname; /* relation to delete from */
562 Node *whereClause; /* qualifications */
565 /* ----------------------
567 * ----------------------
569 typedef struct ReplaceStmt
572 char *relname; /* relation to update */
573 List *targetList; /* the target list (of ResTarget) */
574 Node *whereClause; /* qualifications */
575 List *fromClause; /* the from clause */
578 /* ----------------------
579 * Create Cursor Statement
580 * ----------------------
582 typedef struct CursorStmt
585 char *portalname; /* the portal (cursor) to create */
586 bool binary; /* a binary (internal) portal? */
587 char *unique; /* NULL, "*", or unique attribute name */
588 List *targetList; /* the target list (of ResTarget) */
589 List *fromClause; /* the from clause */
590 Node *whereClause; /* qualifications */
591 List *groupClause; /* group by clause */
592 List *sortClause; /* sort clause (a list of SortGroupBy's) */
595 /* ----------------------
597 * ----------------------
599 typedef struct RetrieveStmt
602 char *unique; /* NULL, '*', or unique attribute name */
603 char *into; /* name of table (for select into table) */
604 List *targetList; /* the target list (of ResTarget) */
605 List *fromClause; /* the from clause */
606 Node *whereClause; /* qualifications */
607 List *groupClause; /* group by clause */
608 Node *havingClause; /* having conditional-expression */
609 List *selectClause; /* subselect parameters */
610 List *sortClause; /* sort clause (a list of SortGroupBy's) */
614 /****************************************************************************
615 * Supporting data structures for Parse Trees
616 ****************************************************************************/
619 * SubSelect - specifies subselect parameters
621 typedef struct SubSelect
624 char *unique; /* NULL, '*', or unique attribute name */
625 List *targetList; /* the target list (of ResTarget) */
626 List *fromClause; /* the from clause */
627 Node *whereClause; /* qualifications */
628 List *groupClause; /* group by clause */
629 Node *havingClause; /* having conditional-expression */
633 * TypeName - specifies a type in definitions
635 typedef struct TypeName
638 char *name; /* name of the type */
639 bool timezone; /* timezone specified? */
640 bool setof; /* is a set? */
641 List *arrayBounds; /* array bounds */
642 int typlen; /* length for char() and varchar() */
646 * ParamNo - specifies a parameter reference
648 typedef struct ParamNo
651 int number; /* the number of the parameter */
652 TypeName *typename; /* the typecast */
656 * A_Expr - binary expressions
658 typedef struct A_Expr
661 int oper; /* type of operation
662 * {OP,OR,AND,NOT,ISNULL,NOTNULL} */
663 char *opname; /* name of operator/function */
664 Node *lexpr; /* left argument */
665 Node *rexpr; /* right argument */
670 * specifies an Attribute (ie. a Column); could have nested dots or
677 char *relname; /* name of relation (can be "*") */
678 ParamNo *paramNo; /* or a parameter */
679 List *attrs; /* attributes (possibly nested); list of
680 * Values (strings) */
681 List *indirection; /* array refs (list of A_Indices') */
685 * A_Const - a constant expression
687 typedef struct A_Const
690 Value val; /* the value (with the tag) */
691 TypeName *typename; /* typecast */
695 * ColumnDef - column definition (used in various creates)
697 typedef struct ColumnDef
700 char *colname; /* name of column */
701 TypeName *typename; /* type of column */
702 bool is_not_null; /* flag to NOT NULL constraint */
703 char *defval; /* default value of column */
708 * an identifier (could be an attribute or a relation name). Depending
709 * on the context at transformStmt time, the identifier is treated as
710 * either a relation name (in which case, isRel will be set) or an
711 * attribute (in which case, it will be transformed into an Attr).
716 char *name; /* its name */
717 List *indirection; /* array references */
718 bool isRel; /* is a relation - filled in by
723 * FuncCall - a function/aggregate invocation
725 typedef struct FuncCall
728 char *funcname; /* name of function */
729 List *args; /* the arguments (list of exprs) */
733 * A_Indices - array reference or bounds ([lidx:uidx] or [uidx])
735 typedef struct A_Indices
738 Node *lidx; /* could be NULL */
744 * result target (used in target list of pre-transformed Parse trees)
746 typedef struct ResTarget
749 char *name; /* name of the result column */
750 List *indirection; /* array references */
751 Node *val; /* the value of the result (A_Expr or
752 * Attr) (or A_Const) */
756 * ParamString - used in with clauses
758 typedef struct ParamString
766 * RelExpr - relation expressions
768 typedef struct RelExpr
771 char *relname; /* the relation name */
772 bool inh; /* inheritance query */
776 * SortGroupBy - for order by clause
778 typedef struct SortGroupBy
781 int resno; /* target number */
783 char *name; /* name of column to sort on */
784 char *useOp; /* operator to use */
788 * RangeVar - range variable, used in from clauses
790 typedef struct RangeVar
793 RelExpr *relExpr; /* the relation expression */
794 char *name; /* the name to be referenced (optional) */
798 * IndexElem - index parameters (used in create index)
800 typedef struct IndexElem
803 char *name; /* name of index */
804 List *args; /* if not NULL, function index */
806 TypeName *tname; /* type of index's keys (optional) */
811 * a definition (used in definition lists in the form of defname = arg)
813 typedef struct DefElem
817 Node *arg; /* a (Value *) or a (TypeName *) */
821 /****************************************************************************
822 * Nodes for a Query tree
823 ****************************************************************************/
827 * a target entry (used in the transformed target list)
829 * one of resdom or fjoin is not NULL. a target list is
830 * ((<resdom | fjoin> expr) (<resdom | fjoin> expr) ...)
832 typedef struct TargetEntry
835 Resdom *resdom; /* fjoin overload this to be a list?? */
837 Node *expr; /* can be a list too */
842 * used in range tables. Some of the following are only used in one of
843 * the parsing, optimizing, execution stages.
845 * inFromCl marks those range variables that are listed in the from clause.
846 * In SQL, the targetlist can only refer to range variables listed in the
847 * from clause but POSTQUEL allows you to refer to tables not specified, in
848 * which case a range table entry will be generated. We use POSTQUEL
849 * semantics which is more powerful. However, we need SQL semantics in
850 * some cases (eg. when expanding a '*')
852 typedef struct RangeTblEntry
855 char *relname; /* real name of the relation */
856 char *refname; /* the reference name (specified in the
859 bool inh; /* inheritance? */
860 bool inFromCl; /* comes from From Clause */
865 * used in the sort clause for retrieves and cursors
867 typedef struct SortClause
870 Resdom *resdom; /* attributes in tlist to be sorted */
871 Oid opoid; /* sort operators */
876 * used in the GROUP BY clause
878 typedef struct GroupClause
881 TargetEntry *entry; /* attributes to group on */
882 Oid grpOpoid; /* the sort operator to use */
885 #endif /* PARSENODES_H */