diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2004-11-05 19:17:13 +0000 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2004-11-05 19:17:13 +0000 |
| commit | 98e8b4805324d8ba0b196b8ffaafd5ddd3051ea1 (patch) | |
| tree | 61d027f5621f3ff37a675fb2e9982e0d28a81242 /src/backend/utils | |
| parent | 0ed3c7665e2fe46efd3eef936a1265be2ec6707f (diff) | |
| download | postgresql-98e8b4805324d8ba0b196b8ffaafd5ddd3051ea1.tar.gz | |
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/utils')
| -rw-r--r-- | src/backend/utils/adt/ruleutils.c | 111 | ||||
| -rw-r--r-- | src/backend/utils/cache/lsyscache.c | 58 | ||||
| -rw-r--r-- | src/backend/utils/misc/guc.c | 12 | ||||
| -rw-r--r-- | src/backend/utils/misc/postgresql.conf.sample | 1 |
4 files changed, 14 insertions, 168 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index bb0fc2a179..36e7208dc1 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -3,7 +3,7 @@ * back to source text * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.184 2004/10/27 18:09:38 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.185 2004/11/05 19:16:11 tgl Exp $ * * This software is copyrighted by Jan Wieck - Hamburg. * @@ -55,7 +55,6 @@ #include "catalog/pg_operator.h" #include "catalog/pg_shadow.h" #include "catalog/pg_trigger.h" -#include "commands/tablespace.h" #include "executor/spi.h" #include "lib/stringinfo.h" #include "miscadmin.h" @@ -163,7 +162,6 @@ static char *pg_get_constraintdef_worker(Oid constraintId, bool fullCommand, int prettyFlags); static char *pg_get_expr_worker(text *expr, Oid relid, char *relname, int prettyFlags); -static Oid get_constraint_index(Oid constraintRelOid, Oid constraintOid); static void make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc, int prettyFlags); static void make_viewdef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc, @@ -775,27 +773,6 @@ pg_get_indexdef_worker(Oid indexrelid, int colno, int prettyFlags) appendStringInfoChar(&buf, ')'); /* - * If the index is in a different tablespace from its parent, tell - * about that - */ - if (idxrelrec->reltablespace != get_rel_tablespace(indrelid)) - { - char *spcname; - - if (OidIsValid(idxrelrec->reltablespace)) - spcname = get_tablespace_name(idxrelrec->reltablespace); - else - spcname = get_tablespace_name(MyDatabaseTableSpace); - - if (spcname) /* just paranoia... */ - { - appendStringInfo(&buf, " TABLESPACE %s", - quote_identifier(spcname)); - pfree(spcname); - } - } - - /* * If it's a partial index, decompile and append the predicate */ if (!heap_attisnull(ht_idx, Anum_pg_index_indpred)) @@ -1023,7 +1000,6 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand, { Datum val; bool isnull; - Oid indexOid; /* Start off the constraint definition */ if (conForm->contype == CONSTRAINT_PRIMARY) @@ -1041,30 +1017,6 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand, decompile_column_index_array(val, conForm->conrelid, &buf); appendStringInfo(&buf, ")"); - - /* Add TABLESPACE if it's not default */ - indexOid = get_constraint_index(RelationGetRelid(conDesc), - constraintId); - if (OidIsValid(indexOid)) - { - Oid reltablespace; - Oid indtablespace; - - reltablespace = get_rel_tablespace(conForm->conrelid); - indtablespace = get_rel_tablespace(indexOid); - if (OidIsValid(indtablespace) && - indtablespace != reltablespace) - { - char *spcname = get_tablespace_name(indtablespace); - - if (spcname) /* just paranoia... */ - { - appendStringInfo(&buf, " USING INDEX TABLESPACE %s", - quote_identifier(spcname)); - pfree(spcname); - } - } - } break; } case CONSTRAINT_CHECK: @@ -1377,67 +1329,6 @@ pg_get_serial_sequence(PG_FUNCTION_ARGS) PG_RETURN_NULL(); } -/* - * get_constraint_index - * Given the OID of a unique or primary-key constraint, - * look up the OID of the underlying index. - * - * We make the caller pass in the OID of pg_constraint, too, simply because - * it's probably got it at hand already. - * - * Returns InvalidOid if index can't be found. - */ -static Oid -get_constraint_index(Oid constraintRelOid, Oid constraintOid) -{ - Oid result = InvalidOid; - Relation depRel; - ScanKeyData key[3]; - SysScanDesc scan; - HeapTuple tup; - - /* Search the dependency table for the dependent index */ - depRel = heap_openr(DependRelationName, AccessShareLock); - - ScanKeyInit(&key[0], - Anum_pg_depend_refclassid, - BTEqualStrategyNumber, F_OIDEQ, - ObjectIdGetDatum(constraintRelOid)); - ScanKeyInit(&key[1], - Anum_pg_depend_refobjid, - BTEqualStrategyNumber, F_OIDEQ, - ObjectIdGetDatum(constraintOid)); - ScanKeyInit(&key[2], - Anum_pg_depend_refobjsubid, - BTEqualStrategyNumber, F_INT4EQ, - Int32GetDatum(0)); - - scan = systable_beginscan(depRel, DependReferenceIndex, true, - SnapshotNow, 3, key); - - while (HeapTupleIsValid(tup = systable_getnext(scan))) - { - Form_pg_depend deprec = (Form_pg_depend) GETSTRUCT(tup); - - /* - * We assume any internal dependency of a relation on the - * constraint must be what we are looking for. - */ - if (deprec->classid == RelOid_pg_class && - deprec->objsubid == 0 && - deprec->deptype == DEPENDENCY_INTERNAL) - { - result = deprec->objid; - break; - } - } - - systable_endscan(scan); - heap_close(depRel, AccessShareLock); - - return result; -} - /* ---------- * deparse_expression - General utility for deparsing expressions diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 2e3848947c..3e63efcc4f 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/cache/lsyscache.c,v 1.117 2004/10/20 16:04:49 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/cache/lsyscache.c,v 1.118 2004/11/05 19:16:14 tgl Exp $ * * NOTES * Eventually, the index information should go through here, too. @@ -986,34 +986,6 @@ get_rel_namespace(Oid relid) } /* - * get_rel_tablespace - * Returns the pg_tablespace OID associated with a given relation. - * - * Note: failure return is InvalidOid, which cannot be distinguished from - * "default tablespace for this database", but that seems OK. - */ -Oid -get_rel_tablespace(Oid relid) -{ - HeapTuple tp; - - tp = SearchSysCache(RELOID, - ObjectIdGetDatum(relid), - 0, 0, 0); - if (HeapTupleIsValid(tp)) - { - Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); - Oid result; - - result = reltup->reltablespace; - ReleaseSysCache(tp); - return result; - } - else - return InvalidOid; -} - -/* * get_rel_type_id * * Returns the pg_type OID associated with a given relation. @@ -2044,34 +2016,6 @@ get_namespace_name(Oid nspid) return NULL; } -/* - * get_namespace_tablespace - * Returns the default tablespace of a given namespace - * - * Note: failure return is InvalidOid, which cannot be distinguished from - * "default tablespace for this database", but that seems OK. - */ -Oid -get_namespace_tablespace(Oid nspid) -{ - HeapTuple tp; - - tp = SearchSysCache(NAMESPACEOID, - ObjectIdGetDatum(nspid), - 0, 0, 0); - if (HeapTupleIsValid(tp)) - { - Form_pg_namespace nsptup = (Form_pg_namespace) GETSTRUCT(tp); - Oid result; - - result = nsptup->nsptablespace; - ReleaseSysCache(tp); - return result; - } - else - return InvalidOid; -} - /* ---------- PG_SHADOW CACHE ---------- */ /* diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index c742ace1b5..b59644397c 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -10,7 +10,7 @@ * Written by Peter Eisentraut <peter_e@gmx.net>. * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.247 2004/11/04 19:08:42 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.248 2004/11/05 19:16:16 tgl Exp $ * *-------------------------------------------------------------------- */ @@ -78,6 +78,7 @@ extern DLLIMPORT bool check_function_bodies; extern int CommitDelay; extern int CommitSiblings; extern int DebugSharedBuffers; +extern char *default_tablespace; static const char *assign_log_destination(const char *value, bool doit, GucSource source); @@ -1507,6 +1508,15 @@ static struct config_string ConfigureNamesString[] = }, { + {"default_tablespace", PGC_USERSET, CLIENT_CONN_STATEMENT, + gettext_noop("Sets the default tablespace to create tables and indexes in."), + gettext_noop("An empty string selects the database's default tablespace.") + }, + &default_tablespace, + "", assign_default_tablespace, NULL + }, + + { {"default_transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT, gettext_noop("Sets the transaction isolation level of each new transaction."), gettext_noop("Each SQL transaction has an isolation level, which " diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample index 3aed76a411..86640efa7d 100644 --- a/src/backend/utils/misc/postgresql.conf.sample +++ b/src/backend/utils/misc/postgresql.conf.sample @@ -269,6 +269,7 @@ # - Statement Behavior - #search_path = '$user,public' # schema names +#default_tablespace = '' # a tablespace name, or '' for default #check_function_bodies = true #default_transaction_isolation = 'read committed' #default_transaction_read_only = false |
