aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2007-03-03 20:08:41 +0000
committerBruce Momjian <bruce@momjian.us>2007-03-03 20:08:41 +0000
commit63c678d17b94c1819997d591742ea11d185aa87a (patch)
tree1616b1a9a634c99cec219ab8b51b4365ba841d7b /src
parentae35867a39cd990aea2b7e79f929193a32d359e2 (diff)
downloadpostgresql-63c678d17b94c1819997d591742ea11d185aa87a.tar.gz
postgresql-63c678d17b94c1819997d591742ea11d185aa87a.zip
Fix for COPY-after-truncate feature.
Simon Riggs
Diffstat (limited to 'src')
-rw-r--r--src/backend/catalog/index.c3
-rw-r--r--src/backend/utils/cache/relcache.c30
-rw-r--r--src/include/utils/relcache.h4
3 files changed, 28 insertions, 9 deletions
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index ae8965e730a..092a8d8de38 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.279 2007/02/14 01:58:56 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.280 2007/03/03 20:08:41 momjian Exp $
*
*
* INTERFACE ROUTINES
@@ -1250,6 +1250,7 @@ setNewRelfilenode(Relation relation)
/* Remember we did this in current transaction, to allow later optimisations */
relation->rd_newRelfilenodeSubid = GetCurrentSubTransactionId();
+ RelationCacheResetAtEOXact();
/* Make sure the relfilenode change is visible */
CommandCounterIncrement();
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index ae41b169c3d..4ce955917a5 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.256 2007/02/27 23:48:09 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.257 2007/03/03 20:08:41 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1915,9 +1915,6 @@ RelationCacheInvalidateEntry(Oid relationId)
* so we do not touch new-in-transaction relations; they cannot be targets
* of cross-backend SI updates (and our own updates now go through a
* separate linked list that isn't limited by the SI message buffer size).
- * We don't do anything special for newRelfilenode-in-transaction relations,
- * though since we have a lock on the relation nobody else should be
- * generating cache invalidation messages for it anyhow.
*
* We do this in two phases: the first pass deletes deletable items, and
* the second one rebuilds the rebuildable items. This is essential for
@@ -1960,6 +1957,14 @@ RelationCacheInvalidate(void)
if (relation->rd_createSubid != InvalidSubTransactionId)
continue;
+ /*
+ * Reset newRelfilenode hint. It is never used for correctness, only
+ * for performance optimization. An incorrectly set hint can lead
+ * to data loss in some circumstances, so play safe.
+ */
+ if (relation->rd_newRelfilenodeSubid != InvalidSubTransactionId)
+ relation->rd_newRelfilenodeSubid = InvalidSubTransactionId;
+
relcacheInvalsReceived++;
if (RelationHasReferenceCountZero(relation))
@@ -2012,6 +2017,17 @@ RelationCacheInvalidate(void)
}
/*
+ * RelationCacheResetAtEOXact
+ *
+ * Register that work will be required at main-transaction commit or abort
+ */
+void
+RelationCacheResetAtEOXact(void)
+{
+ need_eoxact_work = true;
+}
+
+/*
* AtEOXact_RelationCache
*
* Clean up the relcache at main-transaction commit or abort.
@@ -2161,7 +2177,7 @@ AtEOSubXact_RelationCache(bool isCommit, SubTransactionId mySubid,
if (isCommit)
relation->rd_newRelfilenodeSubid = parentSubid;
else
- relation->rd_newRelfilenodeSubid = InvalidSubTransactionId;
+ relation->rd_newRelfilenodeSubid = InvalidSubTransactionId;
}
/*
@@ -2255,7 +2271,7 @@ RelationBuildLocalRelation(const char *relname,
rel->rd_newRelfilenodeSubid = InvalidSubTransactionId;
/* must flag that we have rels created in this transaction */
- need_eoxact_work = true;
+ RelationCacheResetAtEOXact();
/* is it a temporary relation? */
rel->rd_istemp = isTempNamespace(relnamespace);
@@ -2911,7 +2927,7 @@ RelationSetIndexList(Relation relation, List *indexIds, Oid oidIndex)
relation->rd_oidindex = oidIndex;
relation->rd_indexvalid = 2; /* mark list as forced */
/* must flag that we have a forced index list */
- need_eoxact_work = true;
+ RelationCacheResetAtEOXact();
}
/*
diff --git a/src/include/utils/relcache.h b/src/include/utils/relcache.h
index 690477a4f11..c7b549d1cff 100644
--- a/src/include/utils/relcache.h
+++ b/src/include/utils/relcache.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/utils/relcache.h,v 1.57 2007/01/05 22:19:59 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/utils/relcache.h,v 1.58 2007/03/03 20:08:41 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -60,6 +60,8 @@ extern void RelationCacheInvalidateEntry(Oid relationId);
extern void RelationCacheInvalidate(void);
+extern void RelationCacheResetAtEOXact(void);
+
extern void AtEOXact_RelationCache(bool isCommit);
extern void AtEOSubXact_RelationCache(bool isCommit, SubTransactionId mySubid,
SubTransactionId parentSubid);