From 8c19977e9c515cc29af449a7ab6c25e496f539f3 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 19 Apr 2011 18:50:56 -0400 Subject: Avoid changing an index's indcheckxmin horizon during REINDEX. There can never be a need to push the indcheckxmin horizon forward, since any HOT chains that are actually broken with respect to the index must pre-date its original creation. So we can just avoid changing pg_index altogether during a REINDEX operation. This offers a cleaner solution than my previous patch for the problem found a few days ago that we mustn't try to update pg_index while we are reindexing it. System catalog indexes will always be created with indcheckxmin = false during initdb, and with this modified code we should never try to change their pg_index entries. This avoids special-casing system catalogs as the former patch did, and should provide a performance benefit for many cases where REINDEX formerly caused an index to be considered unusable for a short time. Back-patch to 8.3 to cover all versions containing HOT. Note that this patch changes the API for index_build(), but I believe it is unlikely that any add-on code is calling that directly. --- src/backend/commands/cluster.c | 6 ++++++ src/backend/commands/indexcmds.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'src/backend/commands') diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 10ec32c05de..ff228b7d531 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -1398,6 +1398,12 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, * advantage to the other order anyway because this is all transactional, * so no chance to reclaim disk space before commit. We do not need a * final CommandCounterIncrement() because reindex_relation does it. + * + * Note: because index_build is called via reindex_relation, it will never + * set indcheckxmin true for the indexes. This is OK even though in some + * sense we are building new indexes rather than rebuilding existing ones, + * because the new heap won't contain any HOT chains at all, let alone + * broken ones, so it can't be necessary to set indcheckxmin. */ reindex_flags = REINDEX_REL_SUPPRESS_INDEX_USE; if (check_constraints) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 2f4e751100d..53a6aafbbfb 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -505,7 +505,7 @@ DefineIndex(RangeVar *heapRelation, indexInfo->ii_BrokenHotChain = false; /* Now build the index */ - index_build(rel, indexRelation, indexInfo, primary); + index_build(rel, indexRelation, indexInfo, primary, false); /* Close both the relations, but keep the locks */ heap_close(rel, NoLock); -- cgit v1.2.3