Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit63c678d

Browse files
committed
Fix for COPY-after-truncate feature.
Simon Riggs
1 parentae35867 commit63c678d

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

‎src/backend/catalog/index.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.279 2007/02/14 01:58:56 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.280 2007/03/03 20:08:41 momjian Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -1250,6 +1250,7 @@ setNewRelfilenode(Relation relation)
12501250

12511251
/* Remember we did this in current transaction, to allow later optimisations */
12521252
relation->rd_newRelfilenodeSubid=GetCurrentSubTransactionId();
1253+
RelationCacheResetAtEOXact();
12531254

12541255
/* Make sure the relfilenode change is visible */
12551256
CommandCounterIncrement();

‎src/backend/utils/cache/relcache.c

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.256 2007/02/27 23:48:09 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.257 2007/03/03 20:08:41 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1915,9 +1915,6 @@ RelationCacheInvalidateEntry(Oid relationId)
19151915
* so we do not touch new-in-transaction relations; they cannot be targets
19161916
* of cross-backend SI updates (and our own updates now go through a
19171917
* separate linked list that isn't limited by the SI message buffer size).
1918-
* We don't do anything special for newRelfilenode-in-transaction relations,
1919-
* though since we have a lock on the relation nobody else should be
1920-
* generating cache invalidation messages for it anyhow.
19211918
*
19221919
* We do this in two phases: the first pass deletes deletable items, and
19231920
* the second one rebuilds the rebuildable items. This is essential for
@@ -1960,6 +1957,14 @@ RelationCacheInvalidate(void)
19601957
if (relation->rd_createSubid!=InvalidSubTransactionId)
19611958
continue;
19621959

1960+
/*
1961+
* Reset newRelfilenode hint. It is never used for correctness, only
1962+
* for performance optimization. An incorrectly set hint can lead
1963+
* to data loss in some circumstances, so play safe.
1964+
*/
1965+
if (relation->rd_newRelfilenodeSubid!=InvalidSubTransactionId)
1966+
relation->rd_newRelfilenodeSubid=InvalidSubTransactionId;
1967+
19631968
relcacheInvalsReceived++;
19641969

19651970
if (RelationHasReferenceCountZero(relation))
@@ -2011,6 +2016,17 @@ RelationCacheInvalidate(void)
20112016
list_free(rebuildList);
20122017
}
20132018

2019+
/*
2020+
* RelationCacheResetAtEOXact
2021+
*
2022+
* Register that work will be required at main-transaction commit or abort
2023+
*/
2024+
void
2025+
RelationCacheResetAtEOXact(void)
2026+
{
2027+
need_eoxact_work= true;
2028+
}
2029+
20142030
/*
20152031
* AtEOXact_RelationCache
20162032
*
@@ -2161,7 +2177,7 @@ AtEOSubXact_RelationCache(bool isCommit, SubTransactionId mySubid,
21612177
if (isCommit)
21622178
relation->rd_newRelfilenodeSubid=parentSubid;
21632179
else
2164-
relation->rd_newRelfilenodeSubid=InvalidSubTransactionId;
2180+
relation->rd_newRelfilenodeSubid=InvalidSubTransactionId;
21652181
}
21662182

21672183
/*
@@ -2255,7 +2271,7 @@ RelationBuildLocalRelation(const char *relname,
22552271
rel->rd_newRelfilenodeSubid=InvalidSubTransactionId;
22562272

22572273
/* must flag that we have rels created in this transaction */
2258-
need_eoxact_work= true;
2274+
RelationCacheResetAtEOXact();
22592275

22602276
/* is it a temporary relation? */
22612277
rel->rd_istemp=isTempNamespace(relnamespace);
@@ -2911,7 +2927,7 @@ RelationSetIndexList(Relation relation, List *indexIds, Oid oidIndex)
29112927
relation->rd_oidindex=oidIndex;
29122928
relation->rd_indexvalid=2;/* mark list as forced */
29132929
/* must flag that we have a forced index list */
2914-
need_eoxact_work= true;
2930+
RelationCacheResetAtEOXact();
29152931
}
29162932

29172933
/*

‎src/include/utils/relcache.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/utils/relcache.h,v 1.57 2007/01/05 22:19:59 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/utils/relcache.h,v 1.58 2007/03/03 20:08:41 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -60,6 +60,8 @@ extern void RelationCacheInvalidateEntry(Oid relationId);
6060

6161
externvoidRelationCacheInvalidate(void);
6262

63+
externvoidRelationCacheResetAtEOXact(void);
64+
6365
externvoidAtEOXact_RelationCache(boolisCommit);
6466
externvoidAtEOSubXact_RelationCache(boolisCommit,SubTransactionIdmySubid,
6567
SubTransactionIdparentSubid);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp