Avoid creating init fork for unlogged indexes when it already exists.

Report by Greg Sabino Mullane, diagnosis and preliminary patch by
Andres Freund, corrections by me.
This commit is contained in:
Robert Haas 2011-06-02 13:28:52 -04:00
parent 3980f7fc6e
commit b8be5431a2
1 changed files with 7 additions and 2 deletions

View File

@ -1741,9 +1741,14 @@ index_build(Relation heapRelation,
Assert(PointerIsValid(stats));
/*
* If this is an unlogged index, we need to write out an init fork for it.
* If this is an unlogged index, we may need to write out an init fork for
* it -- but we must first check whether one already exists. If, for
* example, an unlogged relation is truncated in the transaction that
* created it, or truncated twice in a subsequent transaction, the
* relfilenode won't change, and nothing needs to be done here.
*/
if (heapRelation->rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED)
if (heapRelation->rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED
&& !smgrexists(indexRelation->rd_smgr, INIT_FORKNUM))
{
RegProcedure ambuildempty = indexRelation->rd_am->ambuildempty;