diff options
author | Robert Haas <rhaas@postgresql.org> | 2010-08-13 20:10:54 +0000 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2010-08-13 20:10:54 +0000 |
commit | debcec7dc31a992703911a9953e299c8d730c778 (patch) | |
tree | dad0d10ec39eafe0cc254c17e36eb82ec822cdac /src/backend/utils/cache/relcache.c | |
parent | 3f9479ef3fdf49fc22088be5268fa536cf5d4efd (diff) | |
download | postgresql-debcec7dc31a992703911a9953e299c8d730c778.tar.gz postgresql-debcec7dc31a992703911a9953e299c8d730c778.zip |
Include the backend ID in the relpath of temporary relations.
This allows us to reliably remove all leftover temporary relation
files on cluster startup without reference to system catalogs or WAL;
therefore, we no longer include temporary relations in XLOG_XACT_COMMIT
and XLOG_XACT_ABORT WAL records.
Since these changes require including a backend ID in each
SharedInvalSmgrMsg, the size of the SharedInvalidationMessage.id
field has been reduced from two bytes to one, and the maximum number
of connections has been reduced from INT_MAX / 4 to 2^23-1. It would
be possible to remove these restrictions by increasing the size of
SharedInvalidationMessage by 4 bytes, but right now that doesn't seem
like a good trade-off.
Review by Jaime Casanova and Tom Lane.
Diffstat (limited to 'src/backend/utils/cache/relcache.c')
-rw-r--r-- | src/backend/utils/cache/relcache.c | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index f4304bce728..166beb25b15 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.311 2010/07/06 19:18:58 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.312 2010/08/13 20:10:52 rhaas Exp $ * *------------------------------------------------------------------------- */ @@ -858,10 +858,20 @@ RelationBuildDesc(Oid targetRelId, bool insertIt) relation->rd_createSubid = InvalidSubTransactionId; relation->rd_newRelfilenodeSubid = InvalidSubTransactionId; relation->rd_istemp = relation->rd_rel->relistemp; - if (relation->rd_istemp) - relation->rd_islocaltemp = isTempOrToastNamespace(relation->rd_rel->relnamespace); + if (!relation->rd_istemp) + relation->rd_backend = InvalidBackendId; + else if (isTempOrToastNamespace(relation->rd_rel->relnamespace)) + relation->rd_backend = MyBackendId; else - relation->rd_islocaltemp = false; + { + /* + * If it's a temporary table, but not one of ours, we have to use + * the slow, grotty method to figure out the owning backend. + */ + relation->rd_backend = + GetTempNamespaceBackendId(relation->rd_rel->relnamespace); + Assert(relation->rd_backend != InvalidBackendId); + } /* * initialize the tuple descriptor (relation->rd_att). @@ -1424,7 +1434,7 @@ formrdesc(const char *relationName, Oid relationReltype, relation->rd_createSubid = InvalidSubTransactionId; relation->rd_newRelfilenodeSubid = InvalidSubTransactionId; relation->rd_istemp = false; - relation->rd_islocaltemp = false; + relation->rd_backend = InvalidBackendId; /* * initialize relation tuple form @@ -2515,7 +2525,7 @@ RelationBuildLocalRelation(const char *relname, /* it is temporary if and only if it is in my temp-table namespace */ rel->rd_istemp = isTempOrToastNamespace(relnamespace); - rel->rd_islocaltemp = rel->rd_istemp; + rel->rd_backend = rel->rd_istemp ? MyBackendId : InvalidBackendId; /* * create a new tuple descriptor from the one passed in. We do this @@ -2629,7 +2639,7 @@ void RelationSetNewRelfilenode(Relation relation, TransactionId freezeXid) { Oid newrelfilenode; - RelFileNode newrnode; + RelFileNodeBackend newrnode; Relation pg_class; HeapTuple tuple; Form_pg_class classform; @@ -2640,7 +2650,8 @@ RelationSetNewRelfilenode(Relation relation, TransactionId freezeXid) TransactionIdIsNormal(freezeXid)); /* Allocate a new relfilenode */ - newrelfilenode = GetNewRelFileNode(relation->rd_rel->reltablespace, NULL); + newrelfilenode = GetNewRelFileNode(relation->rd_rel->reltablespace, NULL, + relation->rd_backend); /* * Get a writable copy of the pg_class tuple for the given relation. @@ -2660,9 +2671,10 @@ RelationSetNewRelfilenode(Relation relation, TransactionId freezeXid) * NOTE: any conflict in relfilenode value will be caught here, if * GetNewRelFileNode messes up for any reason. */ - newrnode = relation->rd_node; - newrnode.relNode = newrelfilenode; - RelationCreateStorage(newrnode, relation->rd_istemp); + newrnode.node = relation->rd_node; + newrnode.node.relNode = newrelfilenode; + newrnode.backend = relation->rd_backend; + RelationCreateStorage(newrnode.node, relation->rd_istemp); smgrclosenode(newrnode); /* |