diff options
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/catalog/index.c | 40 | ||||
-rw-r--r-- | src/backend/catalog/indexing.c | 21 |
2 files changed, 42 insertions, 19 deletions
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 331f90528cd..ce024101fc9 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -3316,28 +3316,34 @@ reindex_index(Oid indexId, bool skip_constraint_checks, char persistence, */ 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, persistence); + + /* 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, persistence); - /* Initialize the index and rebuild */ /* Note: we do not need to re-establish pkey setting */ index_build(heapRelation, iRel, indexInfo, true, true); diff --git a/src/backend/catalog/indexing.c b/src/backend/catalog/indexing.c index 0c994122d85..507879ecaf0 100644 --- a/src/backend/catalog/indexing.c +++ b/src/backend/catalog/indexing.c @@ -82,9 +82,15 @@ CatalogIndexInsert(CatalogIndexState indstate, HeapTuple heapTuple) Datum values[INDEX_MAX_KEYS]; bool isnull[INDEX_MAX_KEYS]; - /* HOT update does not require index inserts */ + /* + * HOT update does not require index inserts. But with asserts enabled we + * want to check that it'd be legal to currently insert into the + * table/index. + */ +#ifndef USE_ASSERT_CHECKING if (HeapTupleIsHeapOnly(heapTuple)) return; +#endif /* * Get information from the state structure. Fall out if nothing to do. @@ -107,8 +113,10 @@ CatalogIndexInsert(CatalogIndexState indstate, HeapTuple heapTuple) for (i = 0; i < numIndexes; i++) { IndexInfo *indexInfo; + Relation index; indexInfo = indexInfoArray[i]; + index = relationDescs[i]; /* If the index is marked as read-only, ignore it */ if (!indexInfo->ii_ReadyForInserts) @@ -121,9 +129,18 @@ CatalogIndexInsert(CatalogIndexState indstate, HeapTuple heapTuple) Assert(indexInfo->ii_Expressions == NIL); Assert(indexInfo->ii_Predicate == NIL); Assert(indexInfo->ii_ExclusionOps == NULL); - Assert(relationDescs[i]->rd_index->indimmediate); + Assert(index->rd_index->indimmediate); Assert(indexInfo->ii_NumIndexKeyAttrs != 0); + /* see earlier check above */ +#ifdef USE_ASSERT_CHECKING + if (HeapTupleIsHeapOnly(heapTuple)) + { + Assert(!ReindexIsProcessingIndex(RelationGetRelid(index))); + continue; + } +#endif /* USE_ASSERT_CHECKING */ + /* * FormIndexDatum fills in its values and isnull parameters with the * appropriate values for the column(s) of the index. |