@@ -2841,29 +2841,33 @@ reindex_index(Oid indexId, bool skip_constraint_checks)
28412841 * reindex_relation - This routine is used to recreate all indexes
28422842 * of a relation (and optionally its toast relation too, if any).
28432843 *
2844- * "flags" can include REINDEX_SUPPRESS_INDEX_USE and REINDEX_CHECK_CONSTRAINTS.
2844+ * "flags" is a bitmask that can include any combination of these bits:
28452845 *
2846- * If flags has REINDEX_SUPPRESS_INDEX_USE, the relation was just completely
2846+ * REINDEX_REL_PROCESS_TOAST: if true, process the toast table too (if any).
2847+ *
2848+ * REINDEX_REL_SUPPRESS_INDEX_USE: if true, the relation was just completely
28472849 * rebuilt by an operation such as VACUUM FULL or CLUSTER, and therefore its
28482850 * indexes are inconsistent with it. This makes things tricky if the relation
28492851 * is a system catalog that we might consult during the reindexing. To deal
28502852 * with that case, we mark all of the indexes as pending rebuild so that they
28512853 * won't be trusted until rebuilt. The caller is required to call us *without*
2852- * having made the rebuilt versions visible by doing CommandCounterIncrement;
2854+ * having made the rebuilt table visible by doing CommandCounterIncrement;
28532855 * we'll do CCI after having collected the index list. (This way we can still
28542856 * use catalog indexes while collecting the list.)
28552857 *
2856- * To avoid deadlocks, VACUUM FULL or CLUSTER on a system catalog must omit the
2857- * REINDEX_CHECK_CONSTRAINTS flag. REINDEX should be used to rebuild an index
2858- * if constraint inconsistency is suspected. For optimal performance, other
2859- * callers should include the flag only after transforming the data in a manner
2860- * that risks a change in constraint validity.
2858+ * REINDEX_REL_CHECK_CONSTRAINTS: if true, recheck unique and exclusion
2859+ * constraint conditions, else don't. To avoid deadlocks, VACUUM FULL or
2860+ * CLUSTER on a system catalog must omit this flag. REINDEX should be used to
2861+ * rebuild an index if constraint inconsistency is suspected. For optimal
2862+ * performance, other callers should include the flag only after transforming
2863+ * the data in a manner that risks a change in constraint validity.
28612864 *
2862- * Returns true if any indexes were rebuilt. Note that a
2863- * CommandCounterIncrement will occur after each index rebuild.
2865+ * Returns true if any indexes were rebuilt (including toast table's index
2866+ * when relevant). Note that a CommandCounterIncrement will occur after each
2867+ * index rebuild.
28642868 */
28652869bool
2866- reindex_relation (Oid relid , bool toast_too , int flags )
2870+ reindex_relation (Oid relid , int flags )
28672871{
28682872 Relation rel ;
28692873 Oid toast_relid ;
@@ -2919,7 +2923,7 @@ reindex_relation(Oid relid, bool toast_too, int flags)
29192923 List * doneIndexes ;
29202924 ListCell * indexId ;
29212925
2922- if (flags & REINDEX_SUPPRESS_INDEX_USE )
2926+ if (flags & REINDEX_REL_SUPPRESS_INDEX_USE )
29232927 {
29242928 /* Suppress use of all the indexes until they are rebuilt */
29252929 SetReindexPending (indexIds );
@@ -2940,11 +2944,11 @@ reindex_relation(Oid relid, bool toast_too, int flags)
29402944 if (is_pg_class )
29412945 RelationSetIndexList (rel , doneIndexes , InvalidOid );
29422946
2943- reindex_index (indexOid , !(flags & REINDEX_CHECK_CONSTRAINTS ));
2947+ reindex_index (indexOid , !(flags & REINDEX_REL_CHECK_CONSTRAINTS ));
29442948
29452949 CommandCounterIncrement ();
29462950
2947- if (flags & REINDEX_SUPPRESS_INDEX_USE )
2951+ if (flags & REINDEX_REL_SUPPRESS_INDEX_USE )
29482952 RemoveReindexPending (indexOid );
29492953
29502954 if (is_pg_class )
@@ -2972,12 +2976,10 @@ reindex_relation(Oid relid, bool toast_too, int flags)
29722976
29732977 /*
29742978 * If the relation has a secondary toast rel, reindex that too while we
2975- * still hold the lock on the master table. There's never a reason to
2976- * reindex the toast table right after rebuilding the heap.
2979+ * still hold the lock on the master table.
29772980 */
2978- Assert (!(toast_too && (flags & REINDEX_SUPPRESS_INDEX_USE )));
2979- if (toast_too && OidIsValid (toast_relid ))
2980- result |= reindex_relation (toast_relid , false, flags );
2981+ if ((flags & REINDEX_REL_PROCESS_TOAST ) && OidIsValid (toast_relid ))
2982+ result |= reindex_relation (toast_relid , flags );
29812983
29822984 return result ;
29832985}
0 commit comments