summaryrefslogtreecommitdiff
path: root/src/backend/catalog/index.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/catalog/index.c')
-rw-r--r--src/backend/catalog/index.c42
1 files changed, 24 insertions, 18 deletions
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index 074f4ec9bc8..5bd5511ce70 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -3143,29 +3143,35 @@ reindex_index(Oid indexId, bool skip_constraint_checks)
*/
TransferPredicateLocksToHeapRelation(iRel);
+ /* Fetch info needed for index_build */
+ indexInfo = BuildIndexInfo(iRel);
+
+ /* If requested, skip checking uniqueness/exclusion constraints */
+ if (skip_constraint_checks)
+ {
+ if (indexInfo->ii_Unique || indexInfo->ii_ExclusionOps != NULL)
+ skipped_constraint = true;
+ indexInfo->ii_Unique = false;
+ indexInfo->ii_ExclusionOps = NULL;
+ indexInfo->ii_ExclusionProcs = NULL;
+ indexInfo->ii_ExclusionStrats = NULL;
+ }
+
+ /*
+ * Build a new physical relation for the index. Need to do that before
+ * "officially" starting the reindexing with SetReindexProcessing -
+ * otherwise the necessary pg_class changes cannot be made with
+ * encountering assertions.
+ */
+ RelationSetNewRelfilenode(iRel, InvalidTransactionId,
+ InvalidMultiXactId);
+
+ /* ensure SetReindexProcessing state isn't leaked */
PG_TRY();
{
/* Suppress use of the target index while rebuilding it */
SetReindexProcessing(heapId, indexId);
- /* Fetch info needed for index_build */
- indexInfo = BuildIndexInfo(iRel);
-
- /* If requested, skip checking uniqueness/exclusion constraints */
- if (skip_constraint_checks)
- {
- if (indexInfo->ii_Unique || indexInfo->ii_ExclusionOps != NULL)
- skipped_constraint = true;
- indexInfo->ii_Unique = false;
- indexInfo->ii_ExclusionOps = NULL;
- indexInfo->ii_ExclusionProcs = NULL;
- indexInfo->ii_ExclusionStrats = NULL;
- }
-
- /* We'll build a new physical relation for the index */
- RelationSetNewRelfilenode(iRel, InvalidTransactionId,
- InvalidMultiXactId);
-
/* Initialize the index and rebuild */
/* Note: we do not need to re-establish pkey setting */
index_build(heapRelation, iRel, indexInfo, false, true);