@@ -2529,26 +2529,29 @@ reindex_index(Oid indexId, bool skip_constraint_checks)
25292529 * reindex_relation - This routine is used to recreate all indexes
25302530 * of a relation (and optionally its toast relation too, if any).
25312531 *
2532- * If heap_rebuilt is true, then the relation was just completely rebuilt by
2533- * an operation such as VACUUM FULL or CLUSTER, and therefore its indexes are
2534- * inconsistent with it. This makes things tricky if the relation is a system
2535- * catalog that we might consult during the reindexing. To deal with that
2536- * case, we mark all of the indexes as pending rebuild so that they won't be
2537- * trusted until rebuilt. The caller is required to call us *without* having
2538- * made the rebuilt versions visible by doing CommandCounterIncrement; we'll
2539- * do CCI after having collected the index list. (This way we can still use
2540- * catalog indexes while collecting the list.)
2532+ * "flags" can include REINDEX_SUPPRESS_INDEX_USE and REINDEX_CHECK_CONSTRAINTS.
25412533 *
2542- * We also skip rechecking uniqueness/exclusion constraint properties if
2543- * heap_rebuilt is true. This avoids likely deadlock conditions when doing
2544- * VACUUM FULL or CLUSTER on system catalogs. REINDEX should be used to
2545- * rebuild an index if constraint inconsistency is suspected.
2534+ * If flags has REINDEX_SUPPRESS_INDEX_USE, the relation was just completely
2535+ * rebuilt by an operation such as VACUUM FULL or CLUSTER, and therefore its
2536+ * indexes are inconsistent with it. This makes things tricky if the relation
2537+ * is a system catalog that we might consult during the reindexing. To deal
2538+ * with that case, we mark all of the indexes as pending rebuild so that they
2539+ * won't be trusted until rebuilt. The caller is required to call us *without*
2540+ * having made the rebuilt versions visible by doing CommandCounterIncrement;
<
8000
/code>2541+ * we'll do CCI after having collected the index list. (This way we can still
2542+ * use catalog indexes while collecting the list.)
2543+ *
2544+ * To avoid deadlocks, VACUUM FULL or CLUSTER on a system catalog must omit the
2545+ * REINDEX_CHECK_CONSTRAINTS flag. REINDEX should be used to rebuild an index
2546+ * if constraint inconsistency is suspected. For optimal performance, other
2547+ * callers should include the flag only after transforming the data in a manner
2548+ * that risks a change in constraint validity.
25462549 *
25472550 * Returns true if any indexes were rebuilt. Note that a
25482551 * CommandCounterIncrement will occur after each index rebuild.
25492552 */
25502553bool
2551- reindex_relation (Oid relid , bool toast_too , bool heap_rebuilt )
2554+ reindex_relation (Oid relid , bool toast_too , int flags )
25522555{
25532556 Relation rel ;
25542557 Oid toast_relid ;
@@ -2604,7 +2607,7 @@ reindex_relation(Oid relid, bool toast_too, bool heap_rebuilt)
26042607 List * doneIndexes ;
26052608 ListCell * indexId ;
26062609
2607- if (heap_rebuilt )
2610+ if (flags & REINDEX_SUPPRESS_INDEX_USE )
26082611 {
26092612 /* Suppress use of all the indexes until they are rebuilt */
26102613 SetReindexPending (indexIds );
@@ -2625,11 +2628,11 @@ reindex_relation(Oid relid, bool toast_too, bool heap_rebuilt)
26252628 if (is_pg_class )
26262629 RelationSetIndexList (rel , doneIndexes , InvalidOid );
26272630
2628- reindex_index (indexOid , heap_rebuilt );
2631+ reindex_index (indexOid , !( flags & REINDEX_CHECK_CONSTRAINTS ) );
26292632
26302633 CommandCounterIncrement ();
26312634
2632- if (heap_rebuilt )
2635+ if (flags & REINDEX_SUPPRESS_INDEX_USE )
26332636 RemoveReindexPending (indexOid );
26342637
26352638 if (is_pg_class )
@@ -2657,10 +2660,12 @@ reindex_relation(Oid relid, bool toast_too, bool heap_rebuilt)
26572660
26582661 /*
26592662 * If the relation has a secondary toast rel, reindex that too while we
2660- * still hold the lock on the master table.
2663+ * still hold the lock on the master table. There's never a reason to
2664+ * reindex the toast table right after rebuilding the heap.
26612665 */
2666+ Assert (!(toast_too && (flags & REINDEX_SUPPRESS_INDEX_USE )));
26622667 if (toast_too && OidIsValid (toast_relid ))
2663- result |= reindex_relation (toast_relid , false, false );
2668+ result |= reindex_relation (toast_relid , false, flags );
26642669
26652670 return result ;
26662671}
0 commit comments