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/utils/cache/relcache.c | |
parent | 474875f4438ea0d18f9f4170117bc407e6812515 (diff) | |
download | postgresql-2467394ee1566e82d0314d12a0d1c0a5670a28c9.tar.gz postgresql-2467394ee1566e82d0314d12a0d1c0a5670a28c9.zip |
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/utils/cache/relcache.c')
-rw-r--r-- | src/backend/utils/cache/relcache.c | 73 |
1 files changed, 45 insertions, 28 deletions
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 4221976f0b1..ee8b46407e1 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.204 2004/05/30 23:40:37 neilc Exp $ + * $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.205 2004/06/18 06:13:52 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -260,6 +260,7 @@ static void RelationBuildTupleDesc(RelationBuildDescInfo buildinfo, Relation relation); static Relation RelationBuildDesc(RelationBuildDescInfo buildinfo, Relation oldrelation); +static void RelationInitPhysicalAddr(Relation relation); static void AttrDefaultFetch(Relation relation); static void CheckConstraintFetch(Relation relation); static List *insert_ordered_oid(List *list, Oid datum); @@ -873,11 +874,10 @@ RelationBuildDesc(RelationBuildDescInfo buildinfo, */ RelationInitLockInfo(relation); /* see lmgr.c */ - if (relation->rd_rel->relisshared) - relation->rd_node.tblNode = InvalidOid; - else - relation->rd_node.tblNode = MyDatabaseId; - relation->rd_node.relNode = relation->rd_rel->relfilenode; + /* + * initialize physical addressing information for the relation + */ + RelationInitPhysicalAddr(relation); /* make sure relation is marked as having no open file yet */ relation->rd_smgr = NULL; @@ -893,6 +893,23 @@ RelationBuildDesc(RelationBuildDescInfo buildinfo, } /* + * Initialize the physical addressing info (RelFileNode) for a relcache entry + */ +static void +RelationInitPhysicalAddr(Relation relation) +{ + if (relation->rd_rel->reltablespace) + relation->rd_node.spcNode = relation->rd_rel->reltablespace; + else + relation->rd_node.spcNode = MyDatabaseTableSpace; + if (relation->rd_rel->relisshared) + relation->rd_node.dbNode = InvalidOid; + else + relation->rd_node.dbNode = MyDatabaseId; + relation->rd_node.relNode = relation->rd_rel->relfilenode; +} + +/* * Initialize index-access-method support data for an index relation */ void @@ -1343,18 +1360,17 @@ formrdesc(const char *relationName, * initialize relation id from info in att array (my, this is ugly) */ RelationGetRelid(relation) = relation->rd_att->attrs[0]->attrelid; + relation->rd_rel->relfilenode = RelationGetRelid(relation); /* - * initialize the relation's lock manager and RelFileNode information + * initialize the relation lock manager information */ RelationInitLockInfo(relation); /* see lmgr.c */ - if (relation->rd_rel->relisshared) - relation->rd_node.tblNode = InvalidOid; - else - relation->rd_node.tblNode = MyDatabaseId; - relation->rd_node.relNode = - relation->rd_rel->relfilenode = RelationGetRelid(relation); + /* + * initialize physical addressing information for the relation + */ + RelationInitPhysicalAddr(relation); /* * initialize the rel-has-index flag, using hardwired knowledge @@ -1570,7 +1586,8 @@ RelationReloadClassinfo(Relation relation) relation->rd_id); relp = (Form_pg_class) GETSTRUCT(pg_class_tuple); memcpy((char *) relation->rd_rel, (char *) relp, CLASS_TUPLE_SIZE); - relation->rd_node.relNode = relp->relfilenode; + /* Now we can recalculate physical address */ + RelationInitPhysicalAddr(relation); heap_freetuple(pg_class_tuple); relation->rd_targblock = InvalidBlockNumber; /* Okay, now it's valid again */ @@ -2040,8 +2057,9 @@ Relation RelationBuildLocalRelation(const char *relname, Oid relnamespace, TupleDesc tupDesc, - Oid relid, Oid dbid, - RelFileNode rnode, + Oid relid, + Oid reltablespace, + bool shared_relation, bool nailit) { Relation rel; @@ -2125,20 +2143,23 @@ RelationBuildLocalRelation(const char *relname, /* * Insert relation physical and logical identifiers (OIDs) into the - * right places. + * right places. Note that the physical ID (relfilenode) is initially + * the same as the logical ID (OID). */ - rel->rd_rel->relisshared = (dbid == InvalidOid); + rel->rd_rel->relisshared = shared_relation; RelationGetRelid(rel) = relid; for (i = 0; i < natts; i++) rel->rd_att->attrs[i]->attrelid = relid; - rel->rd_node = rnode; - rel->rd_rel->relfilenode = rnode.relNode; + rel->rd_rel->relfilenode = relid; + rel->rd_rel->reltablespace = reltablespace; RelationInitLockInfo(rel); /* see lmgr.c */ + RelationInitPhysicalAddr(rel); + /* * Okay to insert into the relcache hash tables. */ @@ -3053,16 +3074,12 @@ load_relcache_init_file(void) MemSet(&rel->pgstat_info, 0, sizeof(rel->pgstat_info)); /* - * Make sure database ID is correct. This is needed in case the - * pg_internal.init file was copied from some other database by - * CREATE DATABASE. + * Recompute lock and physical addressing info. This is needed in + * case the pg_internal.init file was copied from some other database + * by CREATE DATABASE. */ - if (rel->rd_rel->relisshared) - rel->rd_node.tblNode = InvalidOid; - else - rel->rd_node.tblNode = MyDatabaseId; - RelationInitLockInfo(rel); + RelationInitPhysicalAddr(rel); } /* |