diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2012-12-17 20:15:32 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2012-12-17 20:15:32 -0500 |
commit | 6919b7e3294702adc39effd16634b2715d04f012 (patch) | |
tree | 0931f18ad031305d4e15944960d94a719098c0e5 /src/include/utils | |
parent | c299477229559d4ee7db68720d86d3fb391db761 (diff) | |
download | postgresql-6919b7e3294702adc39effd16634b2715d04f012.tar.gz postgresql-6919b7e3294702adc39effd16634b2715d04f012.zip |
Fix failure to ignore leftover temp tables after a server crash.
During crash recovery, we remove disk files belonging to temporary tables,
but the system catalog entries for such tables are intentionally not
cleaned up right away. Instead, the first backend that uses a temp schema
is expected to clean out any leftover objects therein. This approach
requires that we be careful to ignore leftover temp tables (since any
actual access attempt would fail), *even if their BackendId matches our
session*, if we have not yet established use of the session's corresponding
temp schema. That worked fine in the past, but was broken by commit
debcec7dc31a992703911a9953e299c8d730c778 which incorrectly removed the
rd_islocaltemp relcache flag. Put it back, and undo various changes
that substituted tests like "rel->rd_backend == MyBackendId" for use
of a state-aware flag. Per trouble report from Heikki Linnakangas.
Back-patch to 9.1 where the erroneous change was made. In the back
branches, be careful to add rd_islocaltemp in a spot in the struct that
was alignment padding before, so as not to break existing add-on code.
Diffstat (limited to 'src/include/utils')
-rw-r--r-- | src/include/utils/rel.h | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 4669d8a67ef..f7f84e6f71e 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -81,6 +81,7 @@ typedef struct RelationData struct SMgrRelationData *rd_smgr; /* cached file handle, or NULL */ int rd_refcnt; /* reference count */ BackendId rd_backend; /* owning backend id, if temporary relation */ + bool rd_islocaltemp; /* rel is a temp rel of this session */ bool rd_isnailed; /* rel is nailed in cache */ bool rd_isvalid; /* relcache entry is valid */ char rd_indexvalid; /* state of rd_indexlist: 0 = not valid, 1 = @@ -363,21 +364,15 @@ typedef struct StdRdOptions ((relation)->rd_rel->relpersistence == RELPERSISTENCE_TEMP) /* - * RelationUsesTempNamespace - * True if relation's catalog entries live in a private namespace. - */ -#define RelationUsesTempNamespace(relation) \ - ((relation)->rd_rel->relpersistence == RELPERSISTENCE_TEMP) - -/* * RELATION_IS_LOCAL * If a rel is either temp or newly created in the current transaction, - * it can be assumed to be visible only to the current backend. + * it can be assumed to be accessible only to the current backend. + * This is typically used to decide that we can skip acquiring locks. * * Beware of multiple eval of argument */ #define RELATION_IS_LOCAL(relation) \ - ((relation)->rd_backend == MyBackendId || \ + ((relation)->rd_islocaltemp || \ (relation)->rd_createSubid != InvalidSubTransactionId) /* @@ -387,8 +382,8 @@ typedef struct StdRdOptions * Beware of multiple eval of argument */ #define RELATION_IS_OTHER_TEMP(relation) \ - ((relation)->rd_rel->relpersistence == RELPERSISTENCE_TEMP \ - && (relation)->rd_backend != MyBackendId) + ((relation)->rd_rel->relpersistence == RELPERSISTENCE_TEMP && \ + !(relation)->rd_islocaltemp) /* routines in utils/cache/relcache.c */ extern void RelationIncrementReferenceCount(Relation rel); |