]> granicus.if.org Git - postgresql/blobdiff - src/include/nodes/parsenodes.h
Teach the system how to use hashing for UNION. (INTERSECT/EXCEPT will follow,
[postgresql] / src / include / nodes / parsenodes.h
index a108759b76041f6168bb6923370c88d21d76964f..65c3698a841995ee793c6e72c75e3eb2b9750ca3 100644 (file)
@@ -4,10 +4,10 @@
  *       definitions for parse tree nodes
  *
  *
- * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.350 2007/07/17 05:02:02 neilc Exp $
+ * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.371 2008/08/07 01:11:51 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -108,6 +108,7 @@ typedef struct Query
 
        bool            hasAggs;                /* has aggregates in tlist or havingQual */
        bool            hasSubLinks;    /* has subquery SubLink */
+       bool            hasDistinctOn;  /* distinctClause is from DISTINCT ON */
 
        List       *rtable;                     /* list of range table entries */
        FromExpr   *jointree;           /* table join tree (FROM and WHERE clauses) */
@@ -116,13 +117,13 @@ typedef struct Query
 
        List       *returningList;      /* return-values list (of TargetEntry) */
 
-       List       *groupClause;        /* a list of GroupClause's */
+       List       *groupClause;        /* a list of SortGroupClause's */
 
        Node       *havingQual;         /* qualifications applied to groups */
 
-       List       *distinctClause; /* a list of SortClause's */
+       List       *distinctClause; /* a list of SortGroupClause's */
 
-       List       *sortClause;         /* a list of SortClause's */
+       List       *sortClause;         /* a list of SortGroupClause's */
 
        Node       *limitOffset;        /* # of result tuples to skip (int8 expr) */
        Node       *limitCount;         /* # of result tuples to return (int8 expr) */
@@ -165,7 +166,6 @@ 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? */
        List       *typmods;            /* type modifier expression(s) */
@@ -229,23 +229,16 @@ typedef struct A_Expr
 } A_Expr;
 
 /*
- * A_Const - a constant expression
+ * A_Const - a literal constant
  */
 typedef struct A_Const
 {
        NodeTag         type;
-       Value           val;                    /* the value (with the tag) */
-       TypeName   *typename;           /* typecast, or NULL if none */
+       Value           val;                    /* value (includes type info, see value.h) */
 } 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 the combined representation saves a bit of code in many
- * productions in gram.y.
  */
 typedef struct TypeCast
 {
@@ -269,6 +262,7 @@ typedef struct FuncCall
        List       *args;                       /* the arguments (list of exprs) */
        bool            agg_star;               /* argument was really '*' */
        bool            agg_distinct;   /* arguments were labeled DISTINCT */
+       bool            func_variadic;  /* last argument was labeled VARIADIC */
        int                     location;               /* token location, or -1 if unknown */
 } FuncCall;
 
@@ -304,6 +298,15 @@ typedef struct A_Indirection
        List       *indirection;        /* subscripts and/or field names */
 } A_Indirection;
 
+/*
+ * A_ArrayExpr - an ARRAY[] construct
+ */
+typedef struct A_ArrayExpr
+{
+       NodeTag         type;
+       List       *elements;           /* array element expressions */
+} A_ArrayExpr;
+
 /*
  * ResTarget -
  *       result target (used in target list of pre-transformed parse trees)
@@ -338,7 +341,7 @@ typedef struct SortBy
 {
        NodeTag         type;
        SortByDir       sortby_dir;             /* ASC/DESC/USING */
-       SortByNulls     sortby_nulls;   /* NULLS FIRST/LAST */
+       SortByNulls sortby_nulls;       /* NULLS FIRST/LAST */
        List       *useOp;                      /* name of op to use, if SORTBY_USING */
        Node       *node;                       /* expression to sort on */
 } SortBy;
@@ -427,7 +430,7 @@ typedef struct IndexElem
        Node       *expr;                       /* expression to index, or NULL */
        List       *opclass;            /* name of desired opclass; NIL = default */
        SortByDir       ordering;               /* ASC/DESC/default */
-       SortByNulls     nulls_ordering; /* FIRST/LAST/default */
+       SortByNulls nulls_ordering; /* FIRST/LAST/default */
 } IndexElem;
 
 /*
@@ -605,42 +608,58 @@ typedef struct RangeTblEntry
 } RangeTblEntry;
 
 /*
- * SortClause -
- *        representation of ORDER BY clauses
+ * SortGroupClause -
+ *        representation of ORDER BY, GROUP BY, DISTINCT, DISTINCT ON items
+ *
+ * You might think that ORDER BY is only interested in defining ordering,
+ * and GROUP/DISTINCT are only interested in defining equality.  However,
+ * one way to implement grouping is to sort and then apply a "uniq"-like
+ * filter.  So it's also interesting to keep track of possible sort operators
+ * for GROUP/DISTINCT, and in particular to try to sort for the grouping
+ * in a way that will also yield a requested ORDER BY ordering.  So we need
+ * to be able to compare ORDER BY and GROUP/DISTINCT lists, which motivates
+ * the decision to give them the same representation.
  *
  * tleSortGroupRef must match ressortgroupref of exactly one entry of the
- * associated targetlist; that is the expression to be sorted (or grouped) by.
- * sortop is the OID of the ordering operator (a "<" or ">" operator).
- * nulls_first does about what you'd expect.
+ *             query's targetlist; that is the expression to be sorted or grouped by.
+ * eqop is the OID of the equality operator.
+ * sortop is the OID of the ordering operator (a "<" or ">" operator),
+ *             or InvalidOid if not available.
+ * nulls_first means about what you'd expect.  If sortop is InvalidOid
+ *             then nulls_first is meaningless and should be set to false.
+ *
+ * In an ORDER BY item, all fields must be valid.  (The eqop isn't essential
+ * here, but it's cheap to get it along with the sortop, and requiring it
+ * to be valid eases comparisons to grouping items.)
+ *
+ * In a grouping item, eqop must be valid.  If the eqop is a btree equality
+ * operator, then sortop should be set to a compatible ordering operator.
+ * We prefer to set eqop/sortop/nulls_first to match any ORDER BY item that
+ * the query presents for the same tlist item.  If there is none, we just
+ * use the default ordering op for the datatype.
+ *
+ * If the tlist item's type has a hash opclass but no btree opclass, then
+ * we will set eqop to the hash equality operator, sortop to InvalidOid,
+ * and nulls_first to false.  A grouping item of this kind can only be
+ * implemented by hashing, and of course it'll never match an ORDER BY item.
  *
- * SortClauses are also used to identify targets that we will do a "Unique"
- * filter step on (for SELECT DISTINCT and SELECT DISTINCT ON).  The
- * distinctClause list is simply a copy of the relevant members of the
- * sortClause list.  Note that distinctClause can be a subset of sortClause,
- * but cannot have members not present in sortClause; and the members that
- * do appear must be in the same order as in sortClause.
+ * A query might have both ORDER BY and DISTINCT (or DISTINCT ON) clauses.
+ * In SELECT DISTINCT, the distinctClause list is as long or longer than the
+ * sortClause list, while in SELECT DISTINCT ON it's typically shorter.
+ * The two lists must match up to the end of the shorter one --- the parser
+ * rearranges the distinctClause if necessary to make this true.  (This
+ * restriction ensures that only one sort step is needed to both satisfy the
+ * ORDER BY and set up for the Unique step.  This is semantically necessary
+ * for DISTINCT ON, and presents no real drawback for DISTINCT.)
  */
-typedef struct SortClause
+typedef struct SortGroupClause
 {
        NodeTag         type;
        Index           tleSortGroupRef;        /* reference into targetlist */
-       Oid                     sortop;                         /* the ordering operator ('<' op) */
+       Oid                     eqop;                           /* the equality operator ('=' op) */
+       Oid                     sortop;                         /* the ordering operator ('<' op), or 0 */
        bool            nulls_first;            /* do NULLs come before normal values? */
-} SortClause;
-
-/*
- * GroupClause -
- *        representation of GROUP BY clauses
- *
- * GroupClause is exactly like SortClause except for the nodetag value.
- * We have routines that operate interchangeably on both.
- *
- * XXX SortClause overspecifies the semantics so far as GROUP BY is concerned
- * (ditto for DISTINCT).  It'd be better to specify an equality operator not
- * an ordering operator.  However, the two implementations are tightly entwined
- * at the moment ... breaking them apart is work for another day.
- */
-typedef SortClause GroupClause;
+} SortGroupClause;
 
 /*
  * RowMarkClause -
@@ -778,7 +797,12 @@ typedef struct SelectStmt
  * top-level Query node containing the leaf SELECTs as subqueries in its
  * range table.  Its setOperations field shows the tree of set operations,
  * with leaf SelectStmt nodes replaced by RangeTblRef nodes, and internal
- * nodes replaced by SetOperationStmt nodes.
+ * nodes replaced by SetOperationStmt nodes.  Information about the output
+ * column types is added, too.  (Note that the child nodes do not necessarily
+ * produce these types directly, but we've checked that their output types
+ * can be coerced to the output column type.)  Also, if it's not UNION ALL,
+ * information about the types' sort/group semantics is provided in the form
+ * of a SortGroupClause list (same representation as, eg, DISTINCT).
  * ----------------------
  */
 typedef struct SetOperationStmt
@@ -793,6 +817,8 @@ typedef struct SetOperationStmt
        /* Fields derived during parse analysis: */
        List       *colTypes;           /* OID list of output column type OIDs */
        List       *colTypmods;         /* integer list of output column typmods */
+       List       *groupClauses;       /* a list of SortGroupClause's */
+       /* groupClauses is NIL if UNION ALL, but must be set otherwise */
 } SetOperationStmt;
 
 
@@ -836,6 +862,10 @@ typedef enum ObjectType
        OBJECT_TABLE,
        OBJECT_TABLESPACE,
        OBJECT_TRIGGER,
+       OBJECT_TSCONFIGURATION,
+       OBJECT_TSDICTIONARY,
+       OBJECT_TSPARSER,
+       OBJECT_TSTEMPLATE,
        OBJECT_TYPE,
        OBJECT_VIEW
 } ObjectType;
@@ -887,11 +917,11 @@ typedef enum AlterTableType
        AT_AddIndex,                            /* add index */
        AT_ReAddIndex,                          /* internal to commands/tablecmds.c */
        AT_AddConstraint,                       /* add constraint */
+       AT_AddConstraintRecurse,        /* internal to commands/tablecmds.c */
        AT_ProcessedConstraint,         /* pre-processed add constraint (local in
                                                                 * parser/parse_utilcmd.c) */
        AT_DropConstraint,                      /* drop constraint */
-       AT_DropConstraintQuietly,       /* drop constraint, no error/warning (local in
-                                                                * commands/tablecmds.c) */
+       AT_DropConstraintRecurse,       /* internal to commands/tablecmds.c */
        AT_AlterColumnType,                     /* alter column type */
        AT_ChangeOwner,                         /* change owner */
        AT_ClusterOn,                           /* CLUSTER ON */
@@ -1046,6 +1076,42 @@ typedef struct CopyStmt
        List       *options;            /* List of DefElem nodes */
 } CopyStmt;
 
+/* ----------------------
+ * SET Statement (includes RESET)
+ *
+ * "SET var TO DEFAULT" and "RESET var" are semantically equivalent, but we
+ * preserve the distinction in VariableSetKind for CreateCommandTag().
+ * ----------------------
+ */
+typedef enum
+{
+       VAR_SET_VALUE,                          /* SET var = value */
+       VAR_SET_DEFAULT,                        /* SET var TO DEFAULT */
+       VAR_SET_CURRENT,                        /* SET var FROM CURRENT */
+       VAR_SET_MULTI,                          /* special case for SET TRANSACTION ... */
+       VAR_RESET,                                      /* RESET var */
+       VAR_RESET_ALL                           /* RESET ALL */
+} VariableSetKind;
+
+typedef struct VariableSetStmt
+{
+       NodeTag         type;
+       VariableSetKind kind;
+       char       *name;                       /* variable to be set */
+       List       *args;                       /* List of A_Const nodes */
+       bool            is_local;               /* SET LOCAL? */
+} VariableSetStmt;
+
+/* ----------------------
+ * Show Statement
+ * ----------------------
+ */
+typedef struct VariableShowStmt
+{
+       NodeTag         type;
+       char       *name;
+} VariableShowStmt;
+
 /* ----------------------
  *             Create Table Statement
  *
@@ -1260,8 +1326,7 @@ typedef struct AlterRoleSetStmt
 {
        NodeTag         type;
        char       *role;                       /* role name */
-       char       *variable;           /* GUC variable name */
-       List       *value;                      /* value for variable, or NIL for Reset */
+       VariableSetStmt *setstmt;       /* SET or RESET subcommand */
 } AlterRoleSetStmt;
 
 typedef struct DropRoleStmt
@@ -1343,7 +1408,6 @@ typedef struct CreateOpClassItem
        List       *name;                       /* operator or function name */
        List       *args;                       /* argument types */
        int                     number;                 /* strategy num or support proc num */
-       bool            recheck;                /* only used for operators */
        List       *class_args;         /* only used for functions */
        /* fields used for a storagetype item: */
        TypeName   *storedtype;         /* datatype stored in index */
@@ -1413,6 +1477,7 @@ typedef struct TruncateStmt
 {
        NodeTag         type;
        List       *relations;          /* relations (RangeVars) to be truncated */
+       bool            restart_seqs;   /* restart owned sequences? */
        DropBehavior behavior;          /* RESTRICT or CASCADE behavior */
 } TruncateStmt;
 
@@ -1433,16 +1498,16 @@ typedef struct CommentStmt
  *             Declare Cursor Statement
  *
  * Note: the "query" field of DeclareCursorStmt is only used in the raw grammar
- * output.  After parse analysis it's set to null, and the Query points to the
+ * output.     After parse analysis it's set to null, and the Query points to the
  * DeclareCursorStmt, not vice versa.
  * ----------------------
  */
-#define CURSOR_OPT_BINARY              0x0001          /* BINARY */
-#define CURSOR_OPT_SCROLL              0x0002          /* SCROLL explicitly given */
-#define CURSOR_OPT_NO_SCROLL   0x0004          /* NO SCROLL explicitly given */
-#define CURSOR_OPT_INSENSITIVE 0x0008          /* INSENSITIVE (unimplemented) */
-#define CURSOR_OPT_HOLD                        0x0010          /* WITH HOLD */
-#define CURSOR_OPT_FAST_PLAN   0x0020          /* prefer fast-start plan */
+#define CURSOR_OPT_BINARY              0x0001  /* BINARY */
+#define CURSOR_OPT_SCROLL              0x0002  /* SCROLL explicitly given */
+#define CURSOR_OPT_NO_SCROLL   0x0004  /* NO SCROLL explicitly given */
+#define CURSOR_OPT_INSENSITIVE 0x0008  /* INSENSITIVE */
+#define CURSOR_OPT_HOLD                        0x0010  /* WITH HOLD */
+#define CURSOR_OPT_FAST_PLAN   0x0020  /* prefer fast-start plan */
 
 typedef struct DeclareCursorStmt
 {
@@ -1460,7 +1525,7 @@ typedef struct ClosePortalStmt
 {
        NodeTag         type;
        char       *portalname;         /* name of the portal (cursor) */
-                                                               /* NULL means CLOSE ALL */
+       /* NULL means CLOSE ALL */
 } ClosePortalStmt;
 
 /* ----------------------
@@ -1498,10 +1563,9 @@ typedef struct IndexStmt
        char       *idxname;            /* name of new index, or NULL for default */
        RangeVar   *relation;           /* relation to build index on */
        char       *accessMethod;       /* name of access method (eg. btree) */
-       char       *tableSpace;         /* tablespace, or NULL to use parent's */
+       char       *tableSpace;         /* tablespace, or NULL for default */
        List       *indexParams;        /* a list of IndexElem */
        List       *options;            /* options from WITH clause */
-       char       *src_options;        /* relopts inherited from source index */
        Node       *whereClause;        /* qualification (partial-index predicate) */
        bool            unique;                 /* is index unique? */
        bool            primary;                /* is index on primary key? */
@@ -1529,7 +1593,9 @@ typedef enum FunctionParameterMode
        /* the assigned enum values appear in pg_proc, don't change 'em! */
        FUNC_PARAM_IN = 'i',            /* input only */
        FUNC_PARAM_OUT = 'o',           /* output only */
-       FUNC_PARAM_INOUT = 'b'          /* both */
+       FUNC_PARAM_INOUT = 'b',         /* both */
+       FUNC_PARAM_VARIADIC = 'v',      /* variadic */
+       FUNC_PARAM_TABLE = 't'          /* table function output column */
 } FunctionParameterMode;
 
 typedef struct FunctionParameter
@@ -1777,9 +1843,8 @@ typedef struct AlterDatabaseStmt
 typedef struct AlterDatabaseSetStmt
 {
        NodeTag         type;
-       char       *dbname;
-       char       *variable;
-       List       *value;
+       char       *dbname;                     /* database name */
+       VariableSetStmt *setstmt;       /* SET or RESET subcommand */
 } AlterDatabaseSetStmt;
 
 /* ----------------------
@@ -1818,7 +1883,7 @@ typedef struct VacuumStmt
        bool            full;                   /* do FULL (non-concurrent) vacuum */
        bool            analyze;                /* do ANALYZE step */
        bool            verbose;                /* print progress info */
-       int                     freeze_min_age; /* min freeze age, or -1 to use default */
+       int                     freeze_min_age; /* min freeze age, or -1 to use default */
        RangeVar   *relation;           /* single table to process, or NULL */
        List       *va_cols;            /* list of column names, or NIL for all */
 } VacuumStmt;
@@ -1844,41 +1909,6 @@ typedef struct CheckPointStmt
        NodeTag         type;
 } CheckPointStmt;
 
-/* ----------------------
- * Set Statement
- * ----------------------
- */
-
-typedef struct VariableSetStmt
-{
-       NodeTag         type;
-       char       *name;
-       List       *args;
-       bool            is_local;               /* SET LOCAL */
-} VariableSetStmt;
-
-/* ----------------------
- * Show Statement
- * ----------------------
- */
-
-typedef struct VariableShowStmt
-{
-       NodeTag         type;
-       char       *name;
-} VariableShowStmt;
-
-/* ----------------------
- * Reset Statement
- * ----------------------
- */
-
-typedef struct VariableResetStmt
-{
-       NodeTag         type;
-       char       *name;
-} VariableResetStmt;
-
 /* ----------------------
  * Discard Statement
  * ----------------------
@@ -1894,7 +1924,7 @@ typedef enum DiscardMode
 typedef struct DiscardStmt
 {
        NodeTag         type;
-       DiscardMode     target;
+       DiscardMode target;
 } DiscardStmt;
 
 /* ----------------------
@@ -2010,7 +2040,7 @@ typedef struct DeallocateStmt
 {
        NodeTag         type;
        char       *name;                       /* The name of the plan to remove */
-                                                               /* NULL means DEALLOCATE ALL */
+       /* NULL means DEALLOCATE ALL */
 } DeallocateStmt;
 
 /*
@@ -2033,4 +2063,33 @@ typedef struct ReassignOwnedStmt
        char       *newrole;
 } ReassignOwnedStmt;
 
+/*
+ * TS Dictionary stmts: DefineStmt, RenameStmt and DropStmt are default
+ */
+typedef struct AlterTSDictionaryStmt
+{
+       NodeTag         type;
+       List       *dictname;           /* qualified name (list of Value strings) */
+       List       *options;            /* List of DefElem nodes */
+} AlterTSDictionaryStmt;
+
+/*
+ * TS Configuration stmts: DefineStmt, RenameStmt and DropStmt are default
+ */
+typedef struct AlterTSConfigurationStmt
+{
+       NodeTag         type;
+       List       *cfgname;            /* qualified name (list of Value strings) */
+
+       /*
+        * dicts will be non-NIL if ADD/ALTER MAPPING was specified. If dicts is
+        * NIL, but tokentype isn't, DROP MAPPING was specified.
+        */
+       List       *tokentype;          /* list of Value strings */
+       List       *dicts;                      /* list of list of Value strings */
+       bool            override;               /* if true - remove old variant */
+       bool            replace;                /* if true - replace dictionary by another */
+       bool            missing_ok;             /* for DROP - skip error if missing? */
+} AlterTSConfigurationStmt;
+
 #endif   /* PARSENODES_H */