File tree 1 file changed +8
-3
lines changed
1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -1741,9 +1741,14 @@ index_build(Relation heapRelation,
1741
1741
Assert (PointerIsValid (stats ));
1742
1742
1743
1743
/*
1744
- * If this is an unlogged index, we need to write out an init fork for it.
1745
- */
1746
- if (heapRelation -> rd_rel -> relpersistence == RELPERSISTENCE_UNLOGGED )
1744
+ * If this is an unlogged index, we may need to write out an init fork for
1745
+ * it -- but we must first check whether one already exists. If, for
1746
+ * example, an unlogged relation is truncated in the transaction that
1747
+ * created it, or truncated twice in a subsequent transaction, the
1748
+ * relfilenode won't change, and nothing needs to be done here.
1749
+ */
1750
+ if (heapRelation -> rd_rel -> relpersistence == RELPERSISTENCE_UNLOGGED
1751
+ && !smgrexists (indexRelation -> rd_smgr , INIT_FORKNUM ))
1747
1752
{
1748
1753
RegProcedure ambuildempty = indexRelation -> rd_am -> ambuildempty ;
1749
1754
You can’t perform that action at this time.
0 commit comments