git.postgresql.org Git - postgresql.git/commitdiff

git projects / postgresql.git / commitdiff
? search:
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: dfed001)
Have TRUNCATE advance the affected table's relfrozenxid to RecentXmin, to
2007年5月16日 17:28:20 +0000 (17:28 +0000)
2007年5月16日 17:28:20 +0000 (17:28 +0000)
avoid a later needless VACUUM for Xid-wraparound purposes. We can do this
since the table is known to be left empty, so no Xid remains on it.

Per discussion.


diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index 377bc9f4f2cbac495551efd19392aa6c40aad4f5..bd3ae31b076c4fc8c512fdf495fade6fc42ebcef 100644 (file)
--- 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.282 2007年03月29日 00:15:37 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.283 2007年05月16日 17:28:20 alvherre Exp $
*
*
* INTERFACE ROUTINES
@@ -1188,9 +1188,12 @@ index_update_stats(Relation rel, bool hasindex, bool isprimary,
* setNewRelfilenode - assign a new relfilenode value to the relation
*
* Caller must already hold exclusive lock on the relation.
+ *
+ * The relation is marked with relfrozenxid=freezeXid (InvalidTransactionId
+ * must be passed for indexes)
*/
void
-setNewRelfilenode(Relation relation)
+setNewRelfilenode(Relation relation, TransactionId freezeXid)
{
Oid newrelfilenode;
RelFileNode newrnode;
@@ -1204,6 +1207,10 @@ setNewRelfilenode(Relation relation)
relation->rd_rel->relkind == RELKIND_INDEX);
/* Can't change for shared tables or indexes */
Assert(!relation->rd_rel->relisshared);
+ /* Indexes must have Invalid frozenxid; other relations must not */
+ Assert((relation->rd_rel->relkind == RELKIND_INDEX &&
+ freezeXid == InvalidTransactionId) ||
+ TransactionIdIsNormal(freezeXid));
/* Allocate a new relfilenode */
newrelfilenode = GetNewRelFileNode(relation->rd_rel->reltablespace,
@@ -1241,6 +1248,7 @@ setNewRelfilenode(Relation relation)
rd_rel->relfilenode = newrelfilenode;
rd_rel->relpages = 0; /* it's empty until further notice */
rd_rel->reltuples = 0;
+ rd_rel->relfrozenxid = freezeXid;
simple_heap_update(pg_class, &tuple->t_self, tuple);
CatalogUpdateIndexes(pg_class, tuple);
@@ -1957,7 +1965,7 @@ reindex_index(Oid indexId)
/*
* We'll build a new physical relation for the index.
*/
- setNewRelfilenode(iRel);
+ setNewRelfilenode(iRel, InvalidTransactionId);
}
/* Initialize the index and rebuild */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index d7ad90d0217fc631561d0069c86c506c14eb3a5d..cdfbc6f0829bd94116d90390fe8705281c80d02e 100644 (file)
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.223 2007年05月14日 20:24:41 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.224 2007年05月16日 17:28:20 alvherre Exp $
*
*-------------------------------------------------------------------------
*/
@@ -616,7 +616,7 @@ ExecuteTruncate(TruncateStmt *stmt)
* the relfilenode value. The old storage file is scheduled for
* deletion at commit.
*/
- setNewRelfilenode(rel);
+ setNewRelfilenode(rel, RecentXmin);
heap_relid = RelationGetRelid(rel);
toast_relid = rel->rd_rel->reltoastrelid;
@@ -629,7 +629,7 @@ ExecuteTruncate(TruncateStmt *stmt)
if (OidIsValid(toast_relid))
{
rel = relation_open(toast_relid, AccessExclusiveLock);
- setNewRelfilenode(rel);
+ setNewRelfilenode(rel, RecentXmin);
heap_close(rel, NoLock);
}
diff --git a/src/include/catalog/index.h b/src/include/catalog/index.h
index 32c704b71e6e421d3b923f62459273c9c670177f..7240ad600c34c721ab4535d31cd85be45e798d7c 100644 (file)
--- a/src/include/catalog/index.h
+++ b/src/include/catalog/index.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/catalog/index.h,v 1.73 2007年01月09日 02:14:15 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/catalog/index.h,v 1.74 2007年05月16日 17:28:20 alvherre Exp $
*
*-------------------------------------------------------------------------
*/
@@ -53,7 +53,7 @@ extern void FormIndexDatum(IndexInfo *indexInfo,
Datum *values,
bool *isnull);
-extern void setNewRelfilenode(Relation relation);
+extern void setNewRelfilenode(Relation relation, TransactionId freezeXid);
extern void index_build(Relation heapRelation,
Relation indexRelation,
This is the main PostgreSQL git repository.
RSS Atom

AltStyle によって変換されたページ (->オリジナル) /