Skip to content

Commit 9ad7e15

Browse files
committed
Set indcheckxmin true when REINDEX fixes an invalid or not-ready index.
Per comment from Greg Stark, it's less clear that HOT chains don't conflict with the index than it would be for a valid index. So, let's preserve the former behavior that indcheckxmin does get set when there are potentially-broken HOT chains in this case. This change does not cause any pg_index update that wouldn't have happened anyway, so we're not re-introducing the previous bug with pg_index updates, and surely the case is not significant from a performance standpoint; so let's be as conservative as possible.
1 parent 5b8e442 commit 9ad7e15

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/backend/catalog/index.c

+10-3
Original file line numberDiff line numberDiff line change
@@ -2800,7 +2800,12 @@ reindex_index(Oid indexId, bool skip_constraint_checks)
28002800
*
28012801
* We can also reset indcheckxmin, because we have now done a
28022802
* non-concurrent index build, *except* in the case where index_build
2803-
* found some still-broken HOT chains.
2803+
* found some still-broken HOT chains. If it did, we normally leave
2804+
* indcheckxmin alone (note that index_build won't have changed it,
2805+
* because this is a reindex). But if the index was invalid or not ready
2806+
* and there were broken HOT chains, it seems best to force indcheckxmin
2807+
* true, because the normal argument that the HOT chains couldn't conflict
2808+
* with the index is suspect for an invalid index.
28042809
*
28052810
* Note that it is important to not update the pg_index entry if we don't
28062811
* have to, because updating it will move the index's usability horizon
@@ -2825,10 +2830,12 @@ reindex_index(Oid indexId, bool skip_constraint_checks)
28252830
if (!indexForm->indisvalid || !indexForm->indisready ||
28262831
(indexForm->indcheckxmin && !indexInfo->ii_BrokenHotChain))
28272832
{
2828-
indexForm->indisvalid = true;
2829-
indexForm->indisready = true;
28302833
if (!indexInfo->ii_BrokenHotChain)
28312834
indexForm->indcheckxmin = false;
2835+
else if (!indexForm->indisvalid || !indexForm->indisready)
2836+
indexForm->indcheckxmin = true;
2837+
indexForm->indisvalid = true;
2838+
indexForm->indisready = true;
28322839
simple_heap_update(pg_index, &indexTuple->t_self, indexTuple);
28332840
CatalogUpdateIndexes(pg_index, indexTuple);
28342841
}

0 commit comments

Comments
 (0)