From cf68a686a6368ebd6e9e37ded4481bf1bd4a8b8e Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 8 Mar 2002 04:37:18 +0000 Subject: [PATCH] Fix copying/equality-check bugs in GrantStmt and ConstraintsSetStmt, per reports from Fernando Nasser. Also, rearrange order of declarations in parsenodes.h as suggested by Fernando. --- src/backend/commands/trigger.c | 11 +- src/backend/nodes/copyfuncs.c | 6 +- src/backend/nodes/equalfuncs.c | 4 +- src/backend/parser/gram.y | 36 +- src/include/nodes/parsenodes.h | 1761 ++++++++++++++++---------------- 5 files changed, 893 insertions(+), 925 deletions(-) diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c index 61a4eacbac..e25b83b455 100644 --- a/src/backend/commands/trigger.c +++ b/src/backend/commands/trigger.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.104 2002/03/06 06:09:36 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.105 2002/03/08 04:37:14 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1781,6 +1781,7 @@ DeferredTriggerSetState(ConstraintsSetStmt *stmt) foreach(l, stmt->constraints) { + char *cname = strVal(lfirst(l)); ScanKeyData skey; SysScanDesc tgscan; HeapTuple htup; @@ -1788,7 +1789,7 @@ DeferredTriggerSetState(ConstraintsSetStmt *stmt) /* * Check that only named constraints are set explicitly */ - if (strcmp((char *) lfirst(l), "") == 0) + if (strlen(cname) == 0) elog(ERROR, "unnamed constraints cannot be set explicitly"); /* @@ -1798,7 +1799,7 @@ DeferredTriggerSetState(ConstraintsSetStmt *stmt) (bits16) 0x0, (AttrNumber) Anum_pg_trigger_tgconstrname, (RegProcedure) F_NAMEEQ, - PointerGetDatum((char *) lfirst(l))); + PointerGetDatum(cname)); tgscan = systable_beginscan(tgrel, TriggerConstrNameIndex, true, SnapshotNow, 1, &skey); @@ -1822,7 +1823,7 @@ DeferredTriggerSetState(ConstraintsSetStmt *stmt) pg_trigger->tgfoid != F_RI_FKEY_RESTRICT_UPD && pg_trigger->tgfoid != F_RI_FKEY_RESTRICT_DEL) elog(ERROR, "Constraint '%s' is not deferrable", - (char *) lfirst(l)); + cname); constr_oid = htup->t_data->t_oid; loid = lappendi(loid, constr_oid); @@ -1835,7 +1836,7 @@ DeferredTriggerSetState(ConstraintsSetStmt *stmt) * Not found ? */ if (!found) - elog(ERROR, "Constraint '%s' does not exist", (char *) lfirst(l)); + elog(ERROR, "Constraint '%s' does not exist", cname); } heap_close(tgrel, AccessShareLock); diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index 234fd95ba2..ae9ac43045 100644 --- a/src/backend/nodes/copyfuncs.c +++ b/src/backend/nodes/copyfuncs.c @@ -15,7 +15,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.167 2002/03/07 16:35:34 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.168 2002/03/08 04:37:16 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1898,7 +1898,7 @@ _copyGrantStmt(GrantStmt *from) newnode->is_grant = from->is_grant; newnode->objtype = from->objtype; Node_Copy(from, newnode, objects); - Node_Copy(from, newnode, privileges); + newnode->privileges = listCopy(from->privileges); Node_Copy(from, newnode, grantees); return newnode; @@ -1924,8 +1924,6 @@ _copyFuncWithArgs(FuncWithArgs *from) if (from->funcname) newnode->funcname = pstrdup(from->funcname); - else - newnode->funcname = NULL; Node_Copy(from, newnode, funcargs); return newnode; diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c index 03ce9510ad..b9269c5a83 100644 --- a/src/backend/nodes/equalfuncs.c +++ b/src/backend/nodes/equalfuncs.c @@ -20,7 +20,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.115 2002/03/07 16:35:34 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.116 2002/03/08 04:37:16 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -763,7 +763,7 @@ _equalGrantStmt(GrantStmt *a, GrantStmt *b) return false; if (!equal(a->objects, b->objects)) return false; - if (!equal(a->privileges, b->privileges)) + if (!equali(a->privileges, b->privileges)) return false; if (!equal(a->grantees, b->grantees)) return false; diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 2b1edd266e..c166a74459 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -11,7 +11,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.287 2002/03/07 16:35:35 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.288 2002/03/08 04:37:17 tgl Exp $ * * HISTORY * AUTHOR DATE MAJOR EVENT @@ -286,7 +286,6 @@ static void doNegateFloat(Value *v); ConstraintTimeSpec %type constraints_set_list -%type constraints_set_namelist %type constraints_set_mode /* @@ -1034,37 +1033,12 @@ ConstraintsSetStmt: SET CONSTRAINTS constraints_set_list constraints_set_mode } ; - -constraints_set_list: ALL - { - $$ = NIL; - } - | constraints_set_namelist - { - $$ = $1; - } +constraints_set_list: ALL { $$ = NIL; } + | name_list { $$ = $1; } ; - -constraints_set_namelist: ColId - { - $$ = makeList1($1); - } - | constraints_set_namelist ',' ColId - { - $$ = lappend($1, $3); - } - ; - - -constraints_set_mode: DEFERRED - { - $$ = TRUE; - } - | IMMEDIATE - { - $$ = FALSE; - } +constraints_set_mode: DEFERRED { $$ = TRUE; } + | IMMEDIATE { $$ = FALSE; } ; diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index c154913c2b..996c2b9c73 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: parsenodes.h,v 1.158 2002/03/07 16:35:40 momjian Exp $ + * $Id: parsenodes.h,v 1.159 2002/03/08 04:37:18 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -16,6 +16,15 @@ #include "nodes/primnodes.h" + +typedef enum InhOption +{ + INH_NO, /* Do NOT scan child tables */ + INH_YES, /* DO scan child tables */ + INH_DEFAULT /* Use current SQL_inheritance option */ +} InhOption; + + /***************************************************************************** * Query Tree *****************************************************************************/ @@ -93,888 +102,6 @@ typedef struct Query } Query; -typedef enum InhOption -{ - INH_NO, /* Do NOT scan child tables */ - INH_YES, /* DO scan child tables */ - INH_DEFAULT /* Use current SQL_inheritance option */ -} InhOption; - -/***************************************************************************** - * Other Statements (no optimizations required) - * - * Some of them require a little bit of transformation (which is also - * done by transformStmt). The whole structure is then passed on to - * ProcessUtility (by-passing the optimization step) as the utilityStmt - * field in Query. - *****************************************************************************/ - -/* ---------------------- - * Alter Table - * - * The fields are used in different ways by the different variants of - * this command. - * ---------------------- - */ -typedef struct AlterTableStmt -{ - NodeTag type; - char subtype; /*------------ - * A = add column - * T = alter column default - * S = alter column statistics - * M = alter column storage - * D = drop column - * C = add constraint - * X = drop constraint - * E = create toast table - * U = change owner - *------------ - */ - char *relname; /* table to work on */ - InhOption inhOpt; /* recursively act on children? */ - char *name; /* column or constraint name to act on, or - * new owner */ - Node *def; /* definition of new column or constraint */ - int behavior; /* CASCADE or RESTRICT drop behavior */ -} AlterTableStmt; - -/* ---------------------- - * Grant Statement - * ---------------------- - */ - -typedef struct GrantStmt -{ - NodeTag type; - bool is_grant; /* not revoke */ - int objtype; - List *objects; - List *privileges; - List *grantees; -} GrantStmt; - - -typedef struct PrivGrantee -{ - NodeTag type; - char *username; /* if both are NULL then PUBLIC */ - char *groupname; -} PrivGrantee; - - -typedef struct FuncWithArgs -{ - NodeTag type; - char *funcname; - List *funcargs; -} FuncWithArgs; - - -/* This is only used internally in gram.y. */ -typedef struct PrivTarget -{ - NodeTag type; - int objtype; - List *objs; -} PrivTarget; - - -/* ---------------------- - * Close Portal Statement - * ---------------------- - */ -typedef struct ClosePortalStmt -{ - NodeTag type; - char *portalname; /* name of the portal (cursor) */ -} ClosePortalStmt; - -/* ---------------------- - * Copy Statement - * ---------------------- - */ -typedef struct CopyStmt -{ - NodeTag type; - bool binary; /* is a binary copy? */ - char *relname; /* the relation to copy */ - bool oids; /* copy oid's? */ - int direction; /* TO or FROM */ - char *filename; /* if NULL, use stdin/stdout */ - char *delimiter; /* delimiter character, \t by default */ - char *null_print; /* how to print NULLs, `\N' by default */ -} CopyStmt; - -/* ---------------------- - * Create Table Statement - * - * NOTE: in the raw gram.y output, ColumnDef, Constraint, and FkConstraint - * nodes are intermixed in tableElts, and constraints is NIL. After parse - * analysis, tableElts contains just ColumnDefs, and constraints contains - * just Constraint nodes (in fact, only CONSTR_CHECK nodes, in the present - * implementation). - * ---------------------- - */ -typedef struct CreateStmt -{ - NodeTag type; - char *relname; /* name of relation to create */ - List *tableElts; /* column definitions (list of ColumnDef) */ - List *inhRelnames; /* relations to inherit from (list of - * T_String Values) */ - List *constraints; /* constraints (list of Constraint nodes) */ - bool istemp; /* is this a temp table? */ - bool hasoids; /* should it have OIDs? */ -} CreateStmt; - -/* ---------- - * Definitions for plain (non-FOREIGN KEY) constraints in CreateStmt - * - * XXX probably these ought to be unified with FkConstraints at some point? - * - * For constraints that use expressions (CONSTR_DEFAULT, CONSTR_CHECK) - * we may have the expression in either "raw" form (an untransformed - * parse tree) or "cooked" form (the nodeToString representation of - * an executable expression tree), depending on how this Constraint - * node was created (by parsing, or by inheritance from an existing - * relation). We should never have both in the same node! - * - * Constraint attributes (DEFERRABLE etc) are initially represented as - * separate Constraint nodes for simplicity of parsing. analyze.c makes - * a pass through the constraints list to attach the info to the appropriate - * FkConstraint node (and, perhaps, someday to other kinds of constraints). - * ---------- - */ - -typedef enum ConstrType /* types of constraints */ -{ - CONSTR_NULL, /* not SQL92, but a lot of people expect - * it */ - CONSTR_NOTNULL, - CONSTR_DEFAULT, - CONSTR_CHECK, - CONSTR_PRIMARY, - CONSTR_UNIQUE, - CONSTR_ATTR_DEFERRABLE, /* attributes for previous constraint node */ - CONSTR_ATTR_NOT_DEFERRABLE, - CONSTR_ATTR_DEFERRED, - CONSTR_ATTR_IMMEDIATE -} ConstrType; - -typedef struct Constraint -{ - NodeTag type; - ConstrType contype; - char *name; /* name, or NULL if unnamed */ - Node *raw_expr; /* expr, as untransformed parse tree */ - char *cooked_expr; /* expr, as nodeToString representation */ - List *keys; /* Ident nodes naming referenced column(s) */ -} Constraint; - - -/* ---------- - * Definitions for FOREIGN KEY constraints in CreateStmt - * ---------- - */ -#define FKCONSTR_ON_KEY_NOACTION 0x0000 -#define FKCONSTR_ON_KEY_RESTRICT 0x0001 -#define FKCONSTR_ON_KEY_CASCADE 0x0002 -#define FKCONSTR_ON_KEY_SETNULL 0x0004 -#define FKCONSTR_ON_KEY_SETDEFAULT 0x0008 - -#define FKCONSTR_ON_DELETE_MASK 0x000F -#define FKCONSTR_ON_DELETE_SHIFT 0 - -#define FKCONSTR_ON_UPDATE_MASK 0x00F0 -#define FKCONSTR_ON_UPDATE_SHIFT 4 - -typedef struct FkConstraint -{ - NodeTag type; - char *constr_name; /* Constraint name */ - char *pktable_name; /* Primary key table name */ - List *fk_attrs; /* Attributes of foreign key */ - List *pk_attrs; /* Corresponding attrs in PK table */ - char *match_type; /* FULL or PARTIAL */ - int32 actions; /* ON DELETE/UPDATE actions */ - bool deferrable; /* DEFERRABLE */ - bool initdeferred; /* INITIALLY DEFERRED */ -} FkConstraint; - - -/* ---------------------- - * Create/Drop TRIGGER Statements - * ---------------------- - */ - -typedef struct CreateTrigStmt -{ - NodeTag type; - char *trigname; /* TRIGGER' name */ - char *relname; /* triggered relation */ - char *funcname; /* function to call (or NULL) */ - List *args; /* list of (T_String) Values or NULL */ - bool before; /* BEFORE/AFTER */ - bool row; /* ROW/STATEMENT */ - char actions[4]; /* Insert, Update, Delete */ - char *lang; /* currently not used, always NULL */ - char *text; /* AS 'text' */ - List *attr; /* UPDATE OF a, b,... (NI) or NULL */ - char *when; /* WHEN 'a > 10 ...' (NI) or NULL */ - - /* The following are used for referential */ - /* integrity constraint triggers */ - bool isconstraint; /* This is an RI trigger */ - bool deferrable; /* [NOT] DEFERRABLE */ - bool initdeferred; /* INITIALLY {DEFERRED|IMMEDIATE} */ - char *constrrelname; /* opposite relation */ -} CreateTrigStmt; - -typedef struct DropTrigStmt -{ - NodeTag type; - char *trigname; /* TRIGGER' name */ - char *relname; /* triggered relation */ -} DropTrigStmt; - - -/* ---------------------- - * Create/Drop PROCEDURAL LANGUAGE Statement - * ---------------------- - */ -typedef struct CreatePLangStmt -{ - NodeTag type; - char *plname; /* PL name */ - char *plhandler; /* PL call handler function */ - char *plcompiler; /* lancompiler text */ - bool pltrusted; /* PL is trusted */ -} CreatePLangStmt; - -typedef struct DropPLangStmt -{ - NodeTag type; - char *plname; /* PL name */ -} DropPLangStmt; - - -/* ---------------------- - * Create/Alter/Drop User Statements - * ---------------------- - */ -typedef struct CreateUserStmt -{ - NodeTag type; - char *user; /* PostgreSQL user login name */ - List *options; /* List of DefElem nodes */ -} CreateUserStmt; - -typedef struct AlterUserStmt -{ - NodeTag type; - char *user; /* PostgreSQL user login name */ - List *options; /* List of DefElem nodes */ -} AlterUserStmt; - -typedef struct AlterUserSetStmt -{ - NodeTag type; - char *user; - char *variable; - List *value; -} AlterUserSetStmt; - -typedef struct DropUserStmt -{ - NodeTag type; - List *users; /* List of users to remove */ -} DropUserStmt; - - -/* ---------------------- - * Create/Alter/Drop Group Statements - * ---------------------- - */ -typedef struct CreateGroupStmt -{ - NodeTag type; - char *name; /* name of the new group */ - List *options; /* List of DefElem nodes */ -} CreateGroupStmt; - -typedef struct AlterGroupStmt -{ - NodeTag type; - char *name; /* name of group to alter */ - int action; /* +1 = add, -1 = drop user */ - List *listUsers; /* list of users to add/drop */ -} AlterGroupStmt; - -typedef struct DropGroupStmt -{ - NodeTag type; - char *name; -} DropGroupStmt; - - -/* ---------------------- - * Create SEQUENCE Statement - * ---------------------- - */ - -typedef struct CreateSeqStmt -{ - NodeTag type; - char *seqname; /* the relation to create */ - bool istemp; /* is this a temp sequence? */ - List *options; -} CreateSeqStmt; - -/* ---------------------- - * Create Version Statement - * ---------------------- - */ -typedef struct VersionStmt -{ - NodeTag type; - char *relname; /* the new relation */ - int direction; /* FORWARD | BACKWARD */ - char *fromRelname; /* relation to create a version */ - char *date; /* date of the snapshot */ -} VersionStmt; - -/* ---------------------- - * Create {Operator|Type|Aggregate} Statement - * ---------------------- - */ -typedef struct DefineStmt -{ - NodeTag type; - int defType; /* OPERATOR|P_TYPE|AGGREGATE */ - char *defname; - List *definition; /* a list of DefElem */ -} DefineStmt; - - -/* ---------------------- - * Drop Table|Sequence|View|Index|Rule|Type Statement - * ---------------------- - */ - -#define DROP_TABLE 1 -#define DROP_SEQUENCE 2 -#define DROP_VIEW 3 -#define DROP_INDEX 4 -#define DROP_RULE 5 -#define DROP_TYPE_P 6 - -typedef struct DropStmt -{ - NodeTag type; - List *names; - int removeType; -} DropStmt; - -/* ---------------------- - * Truncate Table Statement - * ---------------------- - */ -typedef struct TruncateStmt -{ - NodeTag type; - char *relName; /* relation to be truncated */ -} TruncateStmt; - -/* ---------------------- - * Comment On Statement - * ---------------------- - */ -typedef struct CommentStmt -{ - NodeTag type; - int objtype; /* Object's type */ - char *objname; /* Name of the object */ - char *objproperty; /* Property Id (such as column) */ - List *objlist; /* Arguments for VAL objects */ - char *comment; /* The comment to insert */ -} CommentStmt; - -/* ---------------------- - * Begin Recipe Statement - * ---------------------- - */ -typedef struct RecipeStmt -{ - NodeTag type; - char *recipeName; /* name of the recipe */ -} RecipeStmt; - -/* ---------------------- - * Fetch Statement - * ---------------------- - */ -typedef struct FetchStmt -{ - NodeTag type; - int direction; /* FORWARD or BACKWARD */ - int howMany; /* amount to fetch ("ALL" --> 0) */ - char *portalname; /* name of portal (cursor) */ - bool ismove; /* TRUE if MOVE */ -} FetchStmt; - -/* ---------------------- - * Create Index Statement - * ---------------------- - */ -typedef struct IndexStmt -{ - NodeTag type; - char *idxname; /* name of the index */ - char *relname; /* name of relation to index on */ - char *accessMethod; /* name of access method (eg. btree) */ - List *indexParams; /* a list of IndexElem */ - Node *whereClause; /* qualification (partial-index predicate) */ - List *rangetable; /* range table for qual, filled in by - * transformStmt() */ - bool unique; /* is index unique? */ - bool primary; /* is index on primary key? */ -} IndexStmt; - -/* ---------------------- - * Create Function Statement - * ---------------------- - */ -typedef struct ProcedureStmt -{ - NodeTag type; - bool replace; /* T => replace if already exists */ - char *funcname; /* name of function to create */ - List *argTypes; /* list of argument types (TypeName nodes) */ - Node *returnType; /* the return type (a TypeName node) */ - List *withClause; /* a list of DefElem */ - List *as; /* definition of function body */ - char *language; /* C, SQL, etc */ -} ProcedureStmt; - -/* ---------------------- - * Drop Aggregate Statement - * ---------------------- - */ -typedef struct RemoveAggrStmt -{ - NodeTag type; - char *aggname; /* aggregate to drop */ - Node *aggtype; /* TypeName for input datatype, or NULL */ -} RemoveAggrStmt; - -/* ---------------------- - * Drop Function Statement - * ---------------------- - */ -typedef struct RemoveFuncStmt -{ - NodeTag type; - char *funcname; /* function to drop */ - List *args; /* types of the arguments */ -} RemoveFuncStmt; - -/* ---------------------- - * Drop Operator Statement - * ---------------------- - */ -typedef struct RemoveOperStmt -{ - NodeTag type; - char *opname; /* operator to drop */ - List *args; /* types of the arguments */ -} RemoveOperStmt; - -/* ---------------------- - * Alter Table Statement - * ---------------------- - */ -typedef struct RenameStmt -{ - NodeTag type; - char *relname; /* relation to be altered */ - InhOption inhOpt; /* recursively act on children? */ - char *column; /* if NULL, rename the relation name to - * the new name. Otherwise, rename this - * column name. */ - char *newname; /* the new name */ -} RenameStmt; - -/* ---------------------- - * Create Rule Statement - * ---------------------- - */ -typedef struct RuleStmt -{ - NodeTag type; - char *rulename; /* name of the rule */ - Node *whereClause; /* qualifications */ - CmdType event; /* RETRIEVE */ - struct Attr *object; /* object affected */ - bool instead; /* is a 'do instead'? */ - List *actions; /* the action statements */ -} RuleStmt; - -/* ---------------------- - * Notify Statement - * ---------------------- - */ -typedef struct NotifyStmt -{ - NodeTag type; - char *relname; /* relation to notify */ -} NotifyStmt; - -/* ---------------------- - * Listen Statement - * ---------------------- - */ -typedef struct ListenStmt -{ - NodeTag type; - char *relname; /* relation to listen on */ -} ListenStmt; - -/* ---------------------- - * Unlisten Statement - * ---------------------- - */ -typedef struct UnlistenStmt -{ - NodeTag type; - char *relname; /* relation to unlisten on */ -} UnlistenStmt; - -/* ---------------------- - * {Begin|Abort|End} Transaction Statement - * ---------------------- - */ -typedef struct TransactionStmt -{ - NodeTag type; - int command; /* BEGIN|END|ABORT */ -} TransactionStmt; - -/* ---------------------- - * Create View Statement - * ---------------------- - */ -typedef struct ViewStmt -{ - NodeTag type; - char *viewname; /* name of the view */ - List *aliases; /* target column names */ - Query *query; /* the SQL statement */ -} ViewStmt; - -/* ---------------------- - * Load Statement - * ---------------------- - */ -typedef struct LoadStmt -{ - NodeTag type; - char *filename; /* file to load */ -} LoadStmt; - -/* ---------------------- - * Createdb Statement - * ---------------------- - */ -typedef struct CreatedbStmt -{ - NodeTag type; - char *dbname; /* name of database to create */ - char *dbowner; /* name of owner (NULL = default) */ - char *dbpath; /* location of database (NULL = default) */ - char *dbtemplate; /* template to use (NULL = default) */ - int encoding; /* MULTIBYTE encoding (-1 = use default) */ -} CreatedbStmt; - -/* ---------------------- - * Alter Database - * ---------------------- - */ -typedef struct AlterDatabaseSetStmt -{ - NodeTag type; - char *dbname; - char *variable; - List *value; -} AlterDatabaseSetStmt; - -/* ---------------------- - * Dropdb Statement - * ---------------------- - */ -typedef struct DropdbStmt -{ - NodeTag type; - char *dbname; /* database to drop */ -} DropdbStmt; - -/* ---------------------- - * Cluster Statement (support pbrown's cluster index implementation) - * ---------------------- - */ -typedef struct ClusterStmt -{ - NodeTag type; - char *relname; /* relation being indexed */ - char *indexname; /* original index defined */ -} ClusterStmt; - -/* ---------------------- - * Vacuum and Analyze Statements - * - * Even though these are nominally two statements, it's convenient to use - * just one node type for both. - * ---------------------- - */ -typedef struct VacuumStmt -{ - NodeTag type; - bool vacuum; /* do VACUUM step */ - bool full; /* do FULL (non-concurrent) vacuum */ - bool analyze; /* do ANALYZE step */ - bool freeze; /* early-freeze option */ - bool verbose; /* print progress info */ - char *vacrel; /* name of single table to process, or - * NULL */ - List *va_cols; /* list of column names, or NIL for all */ -} VacuumStmt; - -/* ---------------------- - * Explain Statement - * ---------------------- - */ -typedef struct ExplainStmt -{ - NodeTag type; - Query *query; /* the query */ - bool verbose; /* print plan info */ - bool analyze; /* get statistics by executing plan */ -} ExplainStmt; - -/* ---------------------- - * Checkpoint Statement - * ---------------------- - */ -typedef struct CheckPointStmt -{ - NodeTag type; -} CheckPointStmt; - -/* ---------------------- - * Set Statement - * ---------------------- - */ - -typedef struct VariableSetStmt -{ - NodeTag type; - char *name; - List *args; -} VariableSetStmt; - -/* ---------------------- - * Show Statement - * ---------------------- - */ - -typedef struct VariableShowStmt -{ - NodeTag type; - char *name; -} VariableShowStmt; - -/* ---------------------- - * Reset Statement - * ---------------------- - */ - -typedef struct VariableResetStmt -{ - NodeTag type; - char *name; -} VariableResetStmt; - -/* ---------------------- - * LOCK Statement - * ---------------------- - */ -typedef struct LockStmt -{ - NodeTag type; - List *rellist; /* relations to lock */ - int mode; /* lock mode */ -} LockStmt; - - -/* ---------------------- - * SET CONSTRAINTS Statement - * ---------------------- - */ -typedef struct ConstraintsSetStmt -{ - NodeTag type; - List *constraints; - bool deferred; -} ConstraintsSetStmt; - -/* ---------------------- - * REINDEX Statement - * ---------------------- - */ -typedef struct ReindexStmt -{ - NodeTag type; - int reindexType; /* INDEX|TABLE|DATABASE */ - const char *name; /* name to reindex */ - bool force; - bool all; -} ReindexStmt; - - -/***************************************************************************** - * Optimizable Statements - *****************************************************************************/ - -/* ---------------------- - * Insert Statement - * ---------------------- - */ -typedef struct InsertStmt -{ - NodeTag type; - char *relname; /* relation to insert into */ - List *cols; /* optional: names of the target columns */ - - /* - * An INSERT statement has *either* VALUES or SELECT, never both. If - * VALUES, a targetList is supplied (empty for DEFAULT VALUES). If - * SELECT, a complete SelectStmt (or set-operation tree) is supplied. - */ - List *targetList; /* the target list (of ResTarget) */ - Node *selectStmt; /* the source SELECT */ -} InsertStmt; - -/* ---------------------- - * Delete Statement - * ---------------------- - */ -typedef struct DeleteStmt -{ - NodeTag type; - char *relname; /* relation to delete from */ - Node *whereClause; /* qualifications */ - InhOption inhOpt; /* recursively act on children? */ -} DeleteStmt; - -/* ---------------------- - * Update Statement - * ---------------------- - */ -typedef struct UpdateStmt -{ - NodeTag type; - char *relname; /* relation to update */ - List *targetList; /* the target list (of ResTarget) */ - Node *whereClause; /* qualifications */ - List *fromClause; /* the from clause */ - InhOption inhOpt; /* recursively act on children? */ -} UpdateStmt; - -/* ---------------------- - * Select Statement - * - * A "simple" SELECT is represented in the output of gram.y by a single - * SelectStmt node. A SELECT construct containing set operators (UNION, - * INTERSECT, EXCEPT) is represented by a tree of SelectStmt nodes, in - * which the leaf nodes are component SELECTs and the internal nodes - * represent UNION, INTERSECT, or EXCEPT operators. Using the same node - * type for both leaf and internal nodes allows gram.y to stick ORDER BY, - * LIMIT, etc, clause values into a SELECT statement without worrying - * whether it is a simple or compound SELECT. - * ---------------------- - */ -typedef enum SetOperation -{ - SETOP_NONE = 0, - SETOP_UNION, - SETOP_INTERSECT, - SETOP_EXCEPT -} SetOperation; - -typedef struct SelectStmt -{ - NodeTag type; - - /* - * These fields are used only in "leaf" SelectStmts. - */ - List *distinctClause; /* NULL, list of DISTINCT ON exprs, or - * lcons(NIL,NIL) for all (SELECT - * DISTINCT) */ - char *into; /* name of table (for select into table) */ - bool istemp; /* into is a temp table? */ - List *intoColNames; /* column names for into table */ - List *targetList; /* the target list (of ResTarget) */ - List *fromClause; /* the FROM clause */ - Node *whereClause; /* WHERE qualification */ - List *groupClause; /* GROUP BY clauses */ - Node *havingClause; /* HAVING conditional-expression */ - - /* - * These fields are used in both "leaf" SelectStmts and upper-level - * SelectStmts. portalname/binary may only be set at the top level. - */ - List *sortClause; /* sort clause (a list of SortGroupBy's) */ - char *portalname; /* the portal (cursor) to create */ - bool binary; /* a binary (internal) portal? */ - Node *limitOffset; /* # of result tuples to skip */ - Node *limitCount; /* # of result tuples to return */ - List *forUpdate; /* FOR UPDATE clause */ - - /* - * These fields are used only in upper-level SelectStmts. - */ - SetOperation op; /* type of set op */ - bool all; /* ALL specified? */ - struct SelectStmt *larg; /* left child */ - struct SelectStmt *rarg; /* right child */ - /* Eventually add fields for CORRESPONDING spec here */ -} SelectStmt; - -/* ---------------------- - * Set Operation node for post-analysis query trees - * - * After parse analysis, a SELECT with set operations is represented by a - * 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. - * ---------------------- - */ -typedef struct SetOperationStmt -{ - NodeTag type; - SetOperation op; /* type of set op */ - bool all; /* ALL specified? */ - Node *larg; /* left child */ - Node *rarg; /* right child */ - /* Eventually add fields for CORRESPONDING spec here */ - - /* Fields derived during parse analysis: */ - List *colTypes; /* integer list of OIDs of output column - * types */ -} SetOperationStmt; - /**************************************************************************** * Supporting data structures for Parse Trees * @@ -1397,4 +524,872 @@ typedef struct SortClause */ typedef SortClause GroupClause; + +/***************************************************************************** + * Optimizable Statements + *****************************************************************************/ + +/* ---------------------- + * Insert Statement + * ---------------------- + */ +typedef struct InsertStmt +{ + NodeTag type; + char *relname; /* relation to insert into */ + List *cols; /* optional: names of the target columns */ + + /* + * An INSERT statement has *either* VALUES or SELECT, never both. If + * VALUES, a targetList is supplied (empty for DEFAULT VALUES). If + * SELECT, a complete SelectStmt (or set-operation tree) is supplied. + */ + List *targetList; /* the target list (of ResTarget) */ + Node *selectStmt; /* the source SELECT */ +} InsertStmt; + +/* ---------------------- + * Delete Statement + * ---------------------- + */ +typedef struct DeleteStmt +{ + NodeTag type; + char *relname; /* relation to delete from */ + Node *whereClause; /* qualifications */ + InhOption inhOpt; /* recursively act on children? */ +} DeleteStmt; + +/* ---------------------- + * Update Statement + * ---------------------- + */ +typedef struct UpdateStmt +{ + NodeTag type; + char *relname; /* relation to update */ + List *targetList; /* the target list (of ResTarget) */ + Node *whereClause; /* qualifications */ + List *fromClause; /* the from clause */ + InhOption inhOpt; /* recursively act on children? */ +} UpdateStmt; + +/* ---------------------- + * Select Statement + * + * A "simple" SELECT is represented in the output of gram.y by a single + * SelectStmt node. A SELECT construct containing set operators (UNION, + * INTERSECT, EXCEPT) is represented by a tree of SelectStmt nodes, in + * which the leaf nodes are component SELECTs and the internal nodes + * represent UNION, INTERSECT, or EXCEPT operators. Using the same node + * type for both leaf and internal nodes allows gram.y to stick ORDER BY, + * LIMIT, etc, clause values into a SELECT statement without worrying + * whether it is a simple or compound SELECT. + * ---------------------- + */ +typedef enum SetOperation +{ + SETOP_NONE = 0, + SETOP_UNION, + SETOP_INTERSECT, + SETOP_EXCEPT +} SetOperation; + +typedef struct SelectStmt +{ + NodeTag type; + + /* + * These fields are used only in "leaf" SelectStmts. + */ + List *distinctClause; /* NULL, list of DISTINCT ON exprs, or + * lcons(NIL,NIL) for all (SELECT + * DISTINCT) */ + char *into; /* name of table (for select into table) */ + bool istemp; /* into is a temp table? */ + List *intoColNames; /* column names for into table */ + List *targetList; /* the target list (of ResTarget) */ + List *fromClause; /* the FROM clause */ + Node *whereClause; /* WHERE qualification */ + List *groupClause; /* GROUP BY clauses */ + Node *havingClause; /* HAVING conditional-expression */ + + /* + * These fields are used in both "leaf" SelectStmts and upper-level + * SelectStmts. portalname/binary may only be set at the top level. + */ + List *sortClause; /* sort clause (a list of SortGroupBy's) */ + char *portalname; /* the portal (cursor) to create */ + bool binary; /* a binary (internal) portal? */ + Node *limitOffset; /* # of result tuples to skip */ + Node *limitCount; /* # of result tuples to return */ + List *forUpdate; /* FOR UPDATE clause */ + + /* + * These fields are used only in upper-level SelectStmts. + */ + SetOperation op; /* type of set op */ + bool all; /* ALL specified? */ + struct SelectStmt *larg; /* left child */ + struct SelectStmt *rarg; /* right child */ + /* Eventually add fields for CORRESPONDING spec here */ +} SelectStmt; + +/* ---------------------- + * Set Operation node for post-analysis query trees + * + * After parse analysis, a SELECT with set operations is represented by a + * 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. + * ---------------------- + */ +typedef struct SetOperationStmt +{ + NodeTag type; + SetOperation op; /* type of set op */ + bool all; /* ALL specified? */ + Node *larg; /* left child */ + Node *rarg; /* right child */ + /* Eventually add fields for CORRESPONDING spec here */ + + /* Fields derived during parse analysis: */ + List *colTypes; /* integer list of OIDs of output column + * types */ +} SetOperationStmt; + + +/***************************************************************************** + * Other Statements (no optimizations required) + * + * Some of them require a little bit of transformation (which is also + * done by transformStmt). The whole structure is then passed on to + * ProcessUtility (by-passing the optimization step) as the utilityStmt + * field in Query. + *****************************************************************************/ + +/* ---------------------- + * Alter Table + * + * The fields are used in different ways by the different variants of + * this command. + * ---------------------- + */ +typedef struct AlterTableStmt +{ + NodeTag type; + char subtype; /*------------ + * A = add column + * T = alter column default + * S = alter column statistics + * M = alter column storage + * D = drop column + * C = add constraint + * X = drop constraint + * E = create toast table + * U = change owner + *------------ + */ + char *relname; /* table to work on */ + InhOption inhOpt; /* recursively act on children? */ + char *name; /* column or constraint name to act on, or + * new owner */ + Node *def; /* definition of new column or constraint */ + int behavior; /* CASCADE or RESTRICT drop behavior */ +} AlterTableStmt; + +/* ---------------------- + * Grant Statement + * ---------------------- + */ + +typedef struct GrantStmt +{ + NodeTag type; + bool is_grant; /* not revoke */ + int objtype; + List *objects; /* list of names (as Value strings) */ + List *privileges; /* integer list of privilege codes */ + List *grantees; /* list of PrivGrantee nodes */ +} GrantStmt; + + +typedef struct PrivGrantee +{ + NodeTag type; + char *username; /* if both are NULL then PUBLIC */ + char *groupname; +} PrivGrantee; + + +typedef struct FuncWithArgs +{ + NodeTag type; + char *funcname; + List *funcargs; /* list of Typename nodes */ +} FuncWithArgs; + + +/* This is only used internally in gram.y. */ +typedef struct PrivTarget +{ + NodeTag type; + int objtype; + List *objs; +} PrivTarget; + + +/* ---------------------- + * Close Portal Statement + * ---------------------- + */ +typedef struct ClosePortalStmt +{ + NodeTag type; + char *portalname; /* name of the portal (cursor) */ +} ClosePortalStmt; + +/* ---------------------- + * Copy Statement + * ---------------------- + */ +typedef struct CopyStmt +{ + NodeTag type; + bool binary; /* is a binary copy? */ + char *relname; /* the relation to copy */ + bool oids; /* copy oid's? */ + int direction; /* TO or FROM */ + char *filename; /* if NULL, use stdin/stdout */ + char *delimiter; /* delimiter character, \t by default */ + char *null_print; /* how to print NULLs, `\N' by default */ +} CopyStmt; + +/* ---------------------- + * Create Table Statement + * + * NOTE: in the raw gram.y output, ColumnDef, Constraint, and FkConstraint + * nodes are intermixed in tableElts, and constraints is NIL. After parse + * analysis, tableElts contains just ColumnDefs, and constraints contains + * just Constraint nodes (in fact, only CONSTR_CHECK nodes, in the present + * implementation). + * ---------------------- + */ +typedef struct CreateStmt +{ + NodeTag type; + char *relname; /* name of relation to create */ + List *tableElts; /* column definitions (list of ColumnDef) */ + List *inhRelnames; /* relations to inherit from (list of + * T_String Values) */ + List *constraints; /* constraints (list of Constraint nodes) */ + bool istemp; /* is this a temp table? */ + bool hasoids; /* should it have OIDs? */ +} CreateStmt; + +/* ---------- + * Definitions for plain (non-FOREIGN KEY) constraints in CreateStmt + * + * XXX probably these ought to be unified with FkConstraints at some point? + * + * For constraints that use expressions (CONSTR_DEFAULT, CONSTR_CHECK) + * we may have the expression in either "raw" form (an untransformed + * parse tree) or "cooked" form (the nodeToString representation of + * an executable expression tree), depending on how this Constraint + * node was created (by parsing, or by inheritance from an existing + * relation). We should never have both in the same node! + * + * Constraint attributes (DEFERRABLE etc) are initially represented as + * separate Constraint nodes for simplicity of parsing. analyze.c makes + * a pass through the constraints list to attach the info to the appropriate + * FkConstraint node (and, perhaps, someday to other kinds of constraints). + * ---------- + */ + +typedef enum ConstrType /* types of constraints */ +{ + CONSTR_NULL, /* not SQL92, but a lot of people expect + * it */ + CONSTR_NOTNULL, + CONSTR_DEFAULT, + CONSTR_CHECK, + CONSTR_PRIMARY, + CONSTR_UNIQUE, + CONSTR_ATTR_DEFERRABLE, /* attributes for previous constraint node */ + CONSTR_ATTR_NOT_DEFERRABLE, + CONSTR_ATTR_DEFERRED, + CONSTR_ATTR_IMMEDIATE +} ConstrType; + +typedef struct Constraint +{ + NodeTag type; + ConstrType contype; + char *name; /* name, or NULL if unnamed */ + Node *raw_expr; /* expr, as untransformed parse tree */ + char *cooked_expr; /* expr, as nodeToString representation */ + List *keys; /* Ident nodes naming referenced column(s) */ +} Constraint; + +/* ---------- + * Definitions for FOREIGN KEY constraints in CreateStmt + * ---------- + */ +#define FKCONSTR_ON_KEY_NOACTION 0x0000 +#define FKCONSTR_ON_KEY_RESTRICT 0x0001 +#define FKCONSTR_ON_KEY_CASCADE 0x0002 +#define FKCONSTR_ON_KEY_SETNULL 0x0004 +#define FKCONSTR_ON_KEY_SETDEFAULT 0x0008 + +#define FKCONSTR_ON_DELETE_MASK 0x000F +#define FKCONSTR_ON_DELETE_SHIFT 0 + +#define FKCONSTR_ON_UPDATE_MASK 0x00F0 +#define FKCONSTR_ON_UPDATE_SHIFT 4 + +typedef struct FkConstraint +{ + NodeTag type; + char *constr_name; /* Constraint name */ + char *pktable_name; /* Primary key table name */ + List *fk_attrs; /* Attributes of foreign key */ + List *pk_attrs; /* Corresponding attrs in PK table */ + char *match_type; /* FULL or PARTIAL */ + int32 actions; /* ON DELETE/UPDATE actions */ + bool deferrable; /* DEFERRABLE */ + bool initdeferred; /* INITIALLY DEFERRED */ +} FkConstraint; + +/* ---------------------- + * Create/Drop TRIGGER Statements + * ---------------------- + */ + +typedef struct CreateTrigStmt +{ + NodeTag type; + char *trigname; /* TRIGGER' name */ + char *relname; /* triggered relation */ + char *funcname; /* function to call (or NULL) */ + List *args; /* list of (T_String) Values or NULL */ + bool before; /* BEFORE/AFTER */ + bool row; /* ROW/STATEMENT */ + char actions[4]; /* Insert, Update, Delete */ + char *lang; /* currently not used, always NULL */ + char *text; /* AS 'text' */ + List *attr; /* UPDATE OF a, b,... (NI) or NULL */ + char *when; /* WHEN 'a > 10 ...' (NI) or NULL */ + + /* The following are used for referential */ + /* integrity constraint triggers */ + bool isconstraint; /* This is an RI trigger */ + bool deferrable; /* [NOT] DEFERRABLE */ + bool initdeferred; /* INITIALLY {DEFERRED|IMMEDIATE} */ + char *constrrelname; /* opposite relation */ +} CreateTrigStmt; + +typedef struct DropTrigStmt +{ + NodeTag type; + char *trigname; /* TRIGGER' name */ + char *relname; /* triggered relation */ +} DropTrigStmt; + +/* ---------------------- + * Create/Drop PROCEDURAL LANGUAGE Statement + * ---------------------- + */ +typedef struct CreatePLangStmt +{ + NodeTag type; + char *plname; /* PL name */ + char *plhandler; /* PL call handler function */ + char *plcompiler; /* lancompiler text */ + bool pltrusted; /* PL is trusted */ +} CreatePLangStmt; + +typedef struct DropPLangStmt +{ + NodeTag type; + char *plname; /* PL name */ +} DropPLangStmt; + +/* ---------------------- + * Create/Alter/Drop User Statements + * ---------------------- + */ +typedef struct CreateUserStmt +{ + NodeTag type; + char *user; /* PostgreSQL user login name */ + List *options; /* List of DefElem nodes */ +} CreateUserStmt; + +typedef struct AlterUserStmt +{ + NodeTag type; + char *user; /* PostgreSQL user login name */ + List *options; /* List of DefElem nodes */ +} AlterUserStmt; + +typedef struct AlterUserSetStmt +{ + NodeTag type; + char *user; + char *variable; + List *value; +} AlterUserSetStmt; + +typedef struct DropUserStmt +{ + NodeTag type; + List *users; /* List of users to remove */ +} DropUserStmt; + +/* ---------------------- + * Create/Alter/Drop Group Statements + * ---------------------- + */ +typedef struct CreateGroupStmt +{ + NodeTag type; + char *name; /* name of the new group */ + List *options; /* List of DefElem nodes */ +} CreateGroupStmt; + +typedef struct AlterGroupStmt +{ + NodeTag type; + char *name; /* name of group to alter */ + int action; /* +1 = add, -1 = drop user */ + List *listUsers; /* list of users to add/drop */ +} AlterGroupStmt; + +typedef struct DropGroupStmt +{ + NodeTag type; + char *name; +} DropGroupStmt; + +/* ---------------------- + * Create SEQUENCE Statement + * ---------------------- + */ + +typedef struct CreateSeqStmt +{ + NodeTag type; + char *seqname; /* the relation to create */ + bool istemp; /* is this a temp sequence? */ + List *options; +} CreateSeqStmt; + +/* ---------------------- + * Create Version Statement + * ---------------------- + */ +typedef struct VersionStmt +{ + NodeTag type; + char *relname; /* the new relation */ + int direction; /* FORWARD | BACKWARD */ + char *fromRelname; /* relation to create a version */ + char *date; /* date of the snapshot */ +} VersionStmt; + +/* ---------------------- + * Create {Operator|Type|Aggregate} Statement + * ---------------------- + */ +typedef struct DefineStmt +{ + NodeTag type; + int defType; /* OPERATOR|P_TYPE|AGGREGATE */ + char *defname; + List *definition; /* a list of DefElem */ +} DefineStmt; + +/* ---------------------- + * Drop Table|Sequence|View|Index|Rule|Type Statement + * ---------------------- + */ + +#define DROP_TABLE 1 +#define DROP_SEQUENCE 2 +#define DROP_VIEW 3 +#define DROP_INDEX 4 +#define DROP_RULE 5 +#define DROP_TYPE_P 6 + +typedef struct DropStmt +{ + NodeTag type; + List *names; + int removeType; +} DropStmt; + +/* ---------------------- + * Truncate Table Statement + * ---------------------- + */ +typedef struct TruncateStmt +{ + NodeTag type; + char *relName; /* relation to be truncated */ +} TruncateStmt; + +/* ---------------------- + * Comment On Statement + * ---------------------- + */ +typedef struct CommentStmt +{ + NodeTag type; + int objtype; /* Object's type */ + char *objname; /* Name of the object */ + char *objproperty; /* Property Id (such as column) */ + List *objlist; /* Arguments for VAL objects */ + char *comment; /* The comment to insert */ +} CommentStmt; + +/* ---------------------- + * Begin Recipe Statement + * ---------------------- + */ +typedef struct RecipeStmt +{ + NodeTag type; + char *recipeName; /* name of the recipe */ +} RecipeStmt; + +/* ---------------------- + * Fetch Statement + * ---------------------- + */ +typedef struct FetchStmt +{ + NodeTag type; + int direction; /* FORWARD or BACKWARD */ + int howMany; /* amount to fetch ("ALL" --> 0) */ + char *portalname; /* name of portal (cursor) */ + bool ismove; /* TRUE if MOVE */ +} FetchStmt; + +/* ---------------------- + * Create Index Statement + * ---------------------- + */ +typedef struct IndexStmt +{ + NodeTag type; + char *idxname; /* name of the index */ + char *relname; /* name of relation to index on */ + char *accessMethod; /* name of access method (eg. btree) */ + List *indexParams; /* a list of IndexElem */ + Node *whereClause; /* qualification (partial-index predicate) */ + List *rangetable; /* range table for qual, filled in by + * transformStmt() */ + bool unique; /* is index unique? */ + bool primary; /* is index on primary key? */ +} IndexStmt; + +/* ---------------------- + * Create Function Statement + * ---------------------- + */ +typedef struct ProcedureStmt +{ + NodeTag type; + bool replace; /* T => replace if already exists */ + char *funcname; /* name of function to create */ + List *argTypes; /* list of argument types (TypeName nodes) */ + Node *returnType; /* the return type (a TypeName node) */ + List *withClause; /* a list of DefElem */ + List *as; /* definition of function body */ + char *language; /* C, SQL, etc */ +} ProcedureStmt; + +/* ---------------------- + * Drop Aggregate Statement + * ---------------------- + */ +typedef struct RemoveAggrStmt +{ + NodeTag type; + char *aggname; /* aggregate to drop */ + Node *aggtype; /* TypeName for input datatype, or NULL */ +} RemoveAggrStmt; + +/* ---------------------- + * Drop Function Statement + * ---------------------- + */ +typedef struct RemoveFuncStmt +{ + NodeTag type; + char *funcname; /* function to drop */ + List *args; /* types of the arguments */ +} RemoveFuncStmt; + +/* ---------------------- + * Drop Operator Statement + * ---------------------- + */ +typedef struct RemoveOperStmt +{ + NodeTag type; + char *opname; /* operator to drop */ + List *args; /* types of the arguments */ +} RemoveOperStmt; + +/* ---------------------- + * Alter Table Statement + * ---------------------- + */ +typedef struct RenameStmt +{ + NodeTag type; + char *relname; /* relation to be altered */ + InhOption inhOpt; /* recursively act on children? */ + char *column; /* if NULL, rename the relation name to + * the new name. Otherwise, rename this + * column name. */ + char *newname; /* the new name */ +} RenameStmt; + +/* ---------------------- + * Create Rule Statement + * ---------------------- + */ +typedef struct RuleStmt +{ + NodeTag type; + char *rulename; /* name of the rule */ + Node *whereClause; /* qualifications */ + CmdType event; /* RETRIEVE */ + struct Attr *object; /* object affected */ + bool instead; /* is a 'do instead'? */ + List *actions; /* the action statements */ +} RuleStmt; + +/* ---------------------- + * Notify Statement + * ---------------------- + */ +typedef struct NotifyStmt +{ + NodeTag type; + char *relname; /* relation to notify */ +} NotifyStmt; + +/* ---------------------- + * Listen Statement + * ---------------------- + */ +typedef struct ListenStmt +{ + NodeTag type; + char *relname; /* relation to listen on */ +} ListenStmt; + +/* ---------------------- + * Unlisten Statement + * ---------------------- + */ +typedef struct UnlistenStmt +{ + NodeTag type; + char *relname; /* relation to unlisten on */ +} UnlistenStmt; + +/* ---------------------- + * {Begin|Abort|End} Transaction Statement + * ---------------------- + */ +typedef struct TransactionStmt +{ + NodeTag type; + int command; /* BEGIN|END|ABORT */ +} TransactionStmt; + +/* ---------------------- + * Create View Statement + * ---------------------- + */ +typedef struct ViewStmt +{ + NodeTag type; + char *viewname; /* name of the view */ + List *aliases; /* target column names */ + Query *query; /* the SQL statement */ +} ViewStmt; + +/* ---------------------- + * Load Statement + * ---------------------- + */ +typedef struct LoadStmt +{ + NodeTag type; + char *filename; /* file to load */ +} LoadStmt; + +/* ---------------------- + * Createdb Statement + * ---------------------- + */ +typedef struct CreatedbStmt +{ + NodeTag type; + char *dbname; /* name of database to create */ + char *dbowner; /* name of owner (NULL = default) */ + char *dbpath; /* location of database (NULL = default) */ + char *dbtemplate; /* template to use (NULL = default) */ + int encoding; /* MULTIBYTE encoding (-1 = use default) */ +} CreatedbStmt; + +/* ---------------------- + * Alter Database + * ---------------------- + */ +typedef struct AlterDatabaseSetStmt +{ + NodeTag type; + char *dbname; + char *variable; + List *value; +} AlterDatabaseSetStmt; + +/* ---------------------- + * Dropdb Statement + * ---------------------- + */ +typedef struct DropdbStmt +{ + NodeTag type; + char *dbname; /* database to drop */ +} DropdbStmt; + +/* ---------------------- + * Cluster Statement (support pbrown's cluster index implementation) + * ---------------------- + */ +typedef struct ClusterStmt +{ + NodeTag type; + char *relname; /* relation being indexed */ + char *indexname; /* original index defined */ +} ClusterStmt; + +/* ---------------------- + * Vacuum and Analyze Statements + * + * Even though these are nominally two statements, it's convenient to use + * just one node type for both. + * ---------------------- + */ +typedef struct VacuumStmt +{ + NodeTag type; + bool vacuum; /* do VACUUM step */ + bool full; /* do FULL (non-concurrent) vacuum */ + bool analyze; /* do ANALYZE step */ + bool freeze; /* early-freeze option */ + bool verbose; /* print progress info */ + char *vacrel; /* name of single table to process, or + * NULL */ + List *va_cols; /* list of column names, or NIL for all */ +} VacuumStmt; + +/* ---------------------- + * Explain Statement + * ---------------------- + */ +typedef struct ExplainStmt +{ + NodeTag type; + Query *query; /* the query */ + bool verbose; /* print plan info */ + bool analyze; /* get statistics by executing plan */ +} ExplainStmt; + +/* ---------------------- + * Checkpoint Statement + * ---------------------- + */ +typedef struct CheckPointStmt +{ + NodeTag type; +} CheckPointStmt; + +/* ---------------------- + * Set Statement + * ---------------------- + */ + +typedef struct VariableSetStmt +{ + NodeTag type; + char *name; + List *args; +} VariableSetStmt; + +/* ---------------------- + * Show Statement + * ---------------------- + */ + +typedef struct VariableShowStmt +{ + NodeTag type; + char *name; +} VariableShowStmt; + +/* ---------------------- + * Reset Statement + * ---------------------- + */ + +typedef struct VariableResetStmt +{ + NodeTag type; + char *name; +} VariableResetStmt; + +/* ---------------------- + * LOCK Statement + * ---------------------- + */ +typedef struct LockStmt +{ + NodeTag type; + List *rellist; /* relations to lock */ + int mode; /* lock mode */ +} LockStmt; + +/* ---------------------- + * SET CONSTRAINTS Statement + * ---------------------- + */ +typedef struct ConstraintsSetStmt +{ + NodeTag type; + List *constraints; /* List of names as Value strings */ + bool deferred; +} ConstraintsSetStmt; + +/* ---------------------- + * REINDEX Statement + * ---------------------- + */ +typedef struct ReindexStmt +{ + NodeTag type; + int reindexType; /* INDEX|TABLE|DATABASE */ + const char *name; /* name to reindex */ + bool force; + bool all; +} ReindexStmt; + #endif /* PARSENODES_H */