summaryrefslogtreecommitdiff
path: root/src/backend/commands/tablecmds.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2004-11-05 19:17:13 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2004-11-05 19:17:13 +0000
commit98e8b4805324d8ba0b196b8ffaafd5ddd3051ea1 (patch)
tree61d027f5621f3ff37a675fb2e9982e0d28a81242 /src/backend/commands/tablecmds.c
parent0ed3c7665e2fe46efd3eef936a1265be2ec6707f (diff)
Create 'default_tablespace' GUC variable that supplies a TABLESPACE
clause implicitly whenever one is not given explicitly. Remove concept of a schema having an associated tablespace, and simplify the rules for selecting a default tablespace for a table or index. It's now just (a) explicit TABLESPACE clause; (b) default_tablespace if that's not an empty string; (c) database's default. This will allow pg_dump to use SET commands instead of tablespace clauses to determine object locations (but I didn't actually make it do so). All per recent discussions.
Diffstat (limited to 'src/backend/commands/tablecmds.c')
-rw-r--r--src/backend/commands/tablecmds.c69
1 files changed, 16 insertions, 53 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 4593327d35d..e4001f0102a 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.138 2004/10/30 20:52:56 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.139 2004/11/05 19:15:57 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -168,7 +168,6 @@ static void StoreCatalogInheritance(Oid relationId, List *supers);
static int findAttrByName(const char *attributeName, List *schema);
static void setRelhassubclassInRelation(Oid relationId, bool relhassubclass);
static bool needs_toast_table(Relation rel);
-static void check_tablespace_exists(Oid tablespaceId, Oid namespaceId);
static int transformColumnNameList(Oid relId, List *colList,
int16 *attnums, Oid *atttypids);
static int transformFkeyGetPrimaryKey(Relation pkrel, Oid *indexOid,
@@ -313,34 +312,34 @@ DefineRelation(CreateStmt *stmt, char relkind)
}
/*
- * Select tablespace to use. If not specified, use containing
- * schema's default tablespace (which may in turn default to
- * database's default).
+ * Select tablespace to use. If not specified, use default_tablespace
+ * (which may in turn default to database's default).
*/
if (stmt->tablespacename)
{
- AclResult aclresult;
-
tablespaceId = get_tablespace_oid(stmt->tablespacename);
if (!OidIsValid(tablespaceId))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("tablespace \"%s\" does not exist",
stmt->tablespacename)));
- /* check permissions */
+ }
+ else
+ {
+ tablespaceId = GetDefaultTablespace();
+ /* note InvalidOid is OK in this case */
+ }
+
+ /* Check permissions except when using database's default */
+ if (OidIsValid(tablespaceId))
+ {
+ AclResult aclresult;
+
aclresult = pg_tablespace_aclcheck(tablespaceId, GetUserId(),
ACL_CREATE);
if (aclresult != ACLCHECK_OK)
aclcheck_error(aclresult, ACL_KIND_TABLESPACE,
- stmt->tablespacename);
- }
- else
- {
- tablespaceId = get_namespace_tablespace(namespaceId);
- /* note no permission check on tablespace in this case */
- /* check to see that schema's tablespace still exists */
- if (OidIsValid(tablespaceId))
- check_tablespace_exists(tablespaceId, namespaceId);
+ get_tablespace_name(tablespaceId));
}
/*
@@ -5890,42 +5889,6 @@ needs_toast_table(Relation rel)
return (tuple_length > TOAST_TUPLE_THRESHOLD);
}
-/*
- * Verify that a schema's tablespace still exists
- *
- * We need this because DROP TABLESPACE cannot check whether the target
- * tablespace is the default tablespace for any schemas. (It could check
- * in the current database, but that doesn't seem very helpful.) Subsequent
- * attempts to create tables in that tablespace will fail. This code just
- * exists to ensure that we give a helpful error message.
- */
-static void
-check_tablespace_exists(Oid tablespaceId, Oid namespaceId)
-{
- Relation pg_tablespace;
- ScanKeyData entry[1];
- HeapScanDesc scan;
- HeapTuple tuple;
-
- /* There's no syscache for pg_tablespace, so must look the hard way */
- pg_tablespace = heap_openr(TableSpaceRelationName, AccessShareLock);
- ScanKeyInit(&entry[0],
- ObjectIdAttributeNumber,
- BTEqualStrategyNumber, F_OIDEQ,
- ObjectIdGetDatum(tablespaceId));
- scan = heap_beginscan(pg_tablespace, SnapshotNow, 1, entry);
- tuple = heap_getnext(scan, ForwardScanDirection);
- if (!HeapTupleIsValid(tuple))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_OBJECT),
- errmsg("tablespace with OID %u does not exist",
- tablespaceId),
- errdetail("The default tablespace for schema \"%s\" has been dropped.",
- get_namespace_name(namespaceId))));
- heap_endscan(scan);
- heap_close(pg_tablespace, AccessShareLock);
-}
-
/*
* This code supports