diff options
author | Robert Haas <rhaas@postgresql.org> | 2011-06-02 13:28:52 -0400 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2011-06-02 13:28:52 -0400 |
commit | b8be5431a2baa2ea4a5140f1a49c3360deb4d64e (patch) | |
tree | 38f457e064e8a59a27e5e90d1a23d529c32fdef2 /src | |
parent | 3980f7fc6ecb75952ebe76c3d30ec6731728098d (diff) |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/catalog/index.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index a0898e00488..53b4c3c59bf 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -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 (heapRelation->rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED) + * 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 + && !smgrexists(indexRelation->rd_smgr, INIT_FORKNUM)) { RegProcedure ambuildempty = indexRelation->rd_am->ambuildempty; |