diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2004-06-18 06:14:31 +0000 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2004-06-18 06:14:31 +0000 |
| commit | 2467394ee1566e82d0314d12a0d1c0a5670a28c9 (patch) | |
| tree | 57b87b8c181a9c3eb0f33bf775a5f31b9de8b890 /src/backend/parser | |
| parent | 474875f4438ea0d18f9f4170117bc407e6812515 (diff) | |
| download | postgresql-2467394ee1566e82d0314d12a0d1c0a5670a28c9.tar.gz | |
Tablespaces. Alternate database locations are dead, long live tablespaces.
There are various things left to do: contrib dbsize and oid2name modules
need work, and so does the documentation. Also someone should think about
COMMENT ON TABLESPACE and maybe RENAME TABLESPACE. Also initlocation is
dead, it just doesn't know it yet.
Gavin Sherry and Tom Lane.
Diffstat (limited to 'src/backend/parser')
| -rw-r--r-- | src/backend/parser/analyze.c | 4 | ||||
| -rw-r--r-- | src/backend/parser/gram.y | 110 | ||||
| -rw-r--r-- | src/backend/parser/keywords.c | 3 |
3 files changed, 95 insertions, 22 deletions
diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c index e5537e26ae..5450103156 100644 --- a/src/backend/parser/analyze.c +++ b/src/backend/parser/analyze.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.305 2004/06/10 17:55:58 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.306 2004/06/18 06:13:31 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -874,6 +874,7 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt, seqstmt = makeNode(CreateSeqStmt); seqstmt->sequence = makeRangeVar(snamespace, sname); seqstmt->options = NIL; + seqstmt->tablespacename = NULL; cxt->blist = lappend(cxt->blist, seqstmt); @@ -1199,6 +1200,7 @@ transformIndexConstraints(ParseState *pstate, CreateStmtContext *cxt) index->relation = cxt->relation; index->accessMethod = DEFAULT_INDEX_TYPE; + index->tableSpace = NULL; index->indexParams = NIL; index->whereClause = NULL; diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 07a882f3db..9dc53604c6 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -11,7 +11,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.461 2004/06/09 19:08:17 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.462 2004/06/18 06:13:31 tgl Exp $ * * HISTORY * AUTHOR DATE MAJOR EVENT @@ -136,12 +136,12 @@ static void doNegateFloat(Value *v); AnalyzeStmt ClosePortalStmt ClusterStmt CommentStmt ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt CreateDomainStmt CreateGroupStmt CreateOpClassStmt CreatePLangStmt - CreateSchemaStmt CreateSeqStmt CreateStmt + CreateSchemaStmt CreateSeqStmt CreateStmt CreateTableSpaceStmt CreateAssertStmt CreateTrigStmt CreateUserStmt CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DropGroupStmt DropOpClassStmt DropPLangStmt DropStmt DropAssertStmt DropTrigStmt DropRuleStmt DropCastStmt - DropUserStmt DropdbStmt ExplainStmt FetchStmt + DropUserStmt DropdbStmt DropTableSpaceStmt ExplainStmt FetchStmt GrantStmt IndexStmt InsertStmt ListenStmt LoadStmt LockStmt NotifyStmt ExplainableStmt PreparableStmt CreateFunctionStmt ReindexStmt RemoveAggrStmt @@ -324,6 +324,7 @@ static void doNegateFloat(Value *v); %type <list> constraints_set_list %type <boolean> constraints_set_mode +%type <str> OptTableSpace OptTableSpaceOwner /* @@ -384,7 +385,7 @@ static void doNegateFloat(Value *v); ORDER OUT_P OUTER_P OVERLAPS OVERLAY OWNER PARTIAL PASSWORD PATH_P PENDANT PLACING POSITION - PRECISION PRESERVE PREPARE PRIMARY + PRECISION PRESERVE PREPARE PRIMARY PRIOR PRIVILEGES PROCEDURAL PROCEDURE QUOTE @@ -398,7 +399,7 @@ static void doNegateFloat(Value *v); SHOW SIMILAR SIMPLE SMALLINT SOME STABLE START STATEMENT STATISTICS STDIN STDOUT STORAGE STRICT_P SUBSTRING SYSID - TABLE TEMP TEMPLATE TEMPORARY THEN TIME TIMESTAMP + TABLE TABLESPACE TEMP TEMPLATE TEMPORARY THEN TIME TIMESTAMP TO TOAST TRAILING TRANSACTION TREAT TRIGGER TRIM TRUE_P TRUNCATE TRUSTED TYPE_P @@ -513,6 +514,7 @@ stmt : | CreateSchemaStmt | CreateSeqStmt | CreateStmt + | CreateTableSpaceStmt | CreateTrigStmt | CreateUserStmt | CreatedbStmt @@ -527,6 +529,7 @@ stmt : | DropPLangStmt | DropRuleStmt | DropStmt + | DropTableSpaceStmt | DropTrigStmt | DropUserStmt | DropdbStmt @@ -781,7 +784,7 @@ DropGroupStmt: *****************************************************************************/ CreateSchemaStmt: - CREATE SCHEMA OptSchemaName AUTHORIZATION UserId OptSchemaEltList + CREATE SCHEMA OptSchemaName AUTHORIZATION UserId OptTableSpace OptSchemaEltList { CreateSchemaStmt *n = makeNode(CreateSchemaStmt); /* One can omit the schema name or the authorization id. */ @@ -790,16 +793,18 @@ CreateSchemaStmt: else n->schemaname = $5; n->authid = $5; - n->schemaElts = $6; + n->tablespacename = $6; + n->schemaElts = $7; $$ = (Node *)n; } - | CREATE SCHEMA ColId OptSchemaEltList + | CREATE SCHEMA ColId OptTableSpace OptSchemaEltList { CreateSchemaStmt *n = makeNode(CreateSchemaStmt); /* ...but not both */ n->schemaname = $3; n->authid = NULL; - n->schemaElts = $4; + n->tablespacename = $4; + n->schemaElts = $5; $$ = (Node *)n; } ; @@ -1277,7 +1282,7 @@ alter_table_cmd: n->name = $3; $$ = (Node *)n; } - /* ALTER TABLE <name> SET WITHOUT CLUSTER */ + /* ALTER TABLE <name> SET WITHOUT CLUSTER */ | SET WITHOUT CLUSTER { AlterTableCmd *n = makeNode(AlterTableCmd); @@ -1464,7 +1469,7 @@ opt_using: *****************************************************************************/ CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')' - OptInherit OptWithOids OnCommitOption + OptInherit OptWithOids OnCommitOption OptTableSpace { CreateStmt *n = makeNode(CreateStmt); $4->istemp = $2; @@ -1474,10 +1479,11 @@ CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')' n->constraints = NIL; n->hasoids = $9; n->oncommit = $10; + n->tablespacename = $11; $$ = (Node *)n; } | CREATE OptTemp TABLE qualified_name OF qualified_name - '(' OptTableElementList ')' OptWithOids OnCommitOption + '(' OptTableElementList ')' OptWithOids OnCommitOption OptTableSpace { /* SQL99 CREATE TABLE OF <UDT> (cols) seems to be satisfied * by our inheritance capabilities. Let's try it... @@ -1490,6 +1496,7 @@ CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')' n->constraints = NIL; n->hasoids = $10; n->oncommit = $11; + n->tablespacename = $12; $$ = (Node *)n; } ; @@ -1901,6 +1908,10 @@ OnCommitOption: ON COMMIT DROP { $$ = ONCOMMIT_DROP; } | /*EMPTY*/ { $$ = ONCOMMIT_NOOP; } ; +OptTableSpace: TABLESPACE name { $$ = $2; } + | /*EMPTY*/ { $$ = NULL; } + ; + /* * Note: CREATE TABLE ... AS SELECT ... is just another spelling for @@ -1979,12 +1990,13 @@ CreateAsElement: *****************************************************************************/ CreateSeqStmt: - CREATE OptTemp SEQUENCE qualified_name OptSeqList + CREATE OptTemp SEQUENCE qualified_name OptSeqList OptTableSpace { CreateSeqStmt *n = makeNode(CreateSeqStmt); $4->istemp = $2; n->sequence = $4; n->options = $5; + n->tablespacename = $6; $$ = (Node *)n; } ; @@ -2136,6 +2148,45 @@ opt_procedural: /***************************************************************************** * + * QUERY: + * CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/' + * + *****************************************************************************/ + +CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst + { + CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt); + n->tablespacename = $3; + n->owner = $4; + n->location = $6; + $$ = (Node *) n; + } + ; + +OptTableSpaceOwner: OWNER name { $$ = $2; } + | /*EMPTY */ { $$ = NULL; } + ; + +/***************************************************************************** + * + * QUERY : + * DROP TABLESPACE <tablespace> + * + * No need for drop behaviour as we cannot implement dependencies for + * objects in other databases; we can only support RESTRICT. + * + ****************************************************************************/ + +DropTableSpaceStmt: DROP TABLESPACE name + { + DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt); + n->tablespacename = $3; + $$ = (Node *) n; + } + ; + +/***************************************************************************** + * * QUERIES : * CREATE TRIGGER ... * DROP TRIGGER ... @@ -2735,7 +2786,7 @@ CommentStmt: n->objargs = NIL; n->comment = $7; $$ = (Node *) n; - } + } ; comment_type: @@ -3026,6 +3077,13 @@ privilege_target: n->objs = $2; $$ = n; } + | TABLESPACE name_list + { + PrivTarget *n = makeNode(PrivTarget); + n->objtype = ACL_OBJECT_TABLESPACE; + n->objs = $2; + $$ = n; + } ; @@ -3092,12 +3150,14 @@ function_with_argtypes: * QUERY: * create index <indexname> on <relname> * [ using <access> ] "(" ( <col> [ using <opclass> ] )+ ")" - * [ where <predicate> ] + * [ tablespace <tablespacename> ] [ where <predicate> ] * + * Note: we cannot put TABLESPACE clause after WHERE clause unless we are + * willing to make TABLESPACE a fully reserved word. *****************************************************************************/ IndexStmt: CREATE index_opt_unique INDEX index_name ON qualified_name - access_method_clause '(' index_params ')' where_clause + access_method_clause '(' index_params ')' OptTableSpace where_clause { IndexStmt *n = makeNode(IndexStmt); n->unique = $2; @@ -3105,7 +3165,8 @@ IndexStmt: CREATE index_opt_unique INDEX index_name ON qualified_name n->relation = $6; n->accessMethod = $7; n->indexParams = $9; - n->whereClause = $11; + n->tableSpace = $11; + n->whereClause = $12; $$ = (Node *)n; } ; @@ -3896,7 +3957,15 @@ createdb_opt_list: ; createdb_opt_item: - LOCATION opt_equal Sconst + TABLESPACE opt_equal name + { + $$ = makeDefElem("tablespace", (Node *)makeString($3)); + } + | TABLESPACE opt_equal DEFAULT + { + $$ = makeDefElem("tablespace", NULL); + } + | LOCATION opt_equal Sconst { $$ = makeDefElem("location", (Node *)makeString($3)); } @@ -6801,7 +6870,7 @@ subquery_Op: { $$ = list_make1(makeString("!~~*")); } /* cannot put SIMILAR TO here, because SIMILAR TO is a hack. * the regular expression is preprocessed by a function (similar_escape), - * and the ~ operator for posix regular expressions is used. + * and the ~ operator for posix regular expressions is used. * x SIMILAR TO y -> x ~ similar_escape(y) * this transformation is made on the fly by the parser upwards. * however the SubLink structure which handles any/some/all stuff @@ -6978,7 +7047,7 @@ in_expr: select_with_parens * COALESCE(a,b,...) * same as CASE WHEN a IS NOT NULL THEN a WHEN b IS NOT NULL THEN b ... END * - thomas 1998-11-09 - * + * * NULLIF and COALESCE have become first class nodes to * prevent double evaluation of arguments. * - Kris Jurka 2003-02-11 @@ -7565,6 +7634,7 @@ unreserved_keyword: | STORAGE | SYSID | STRICT_P + | TABLESPACE | TEMP | TEMPLATE | TEMPORARY diff --git a/src/backend/parser/keywords.c b/src/backend/parser/keywords.c index a3c765a195..a89f8da7d4 100644 --- a/src/backend/parser/keywords.c +++ b/src/backend/parser/keywords.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/parser/keywords.c,v 1.149 2004/04/21 00:34:18 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/parser/keywords.c,v 1.150 2004/06/18 06:13:31 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -297,6 +297,7 @@ static const ScanKeyword ScanKeywords[] = { {"substring", SUBSTRING}, {"sysid", SYSID}, {"table", TABLE}, + {"tablespace", TABLESPACE}, {"temp", TEMP}, {"template", TEMPLATE}, {"temporary", TEMPORARY}, |
