freespace: Don't constantly close files when reading buffer.
authorAndres Freund <[email protected]>
Mon, 21 May 2018 22:43:30 +0000 (15:43 -0700)
committerAndres Freund <[email protected]>
Mon, 21 May 2018 22:43:30 +0000 (15:43 -0700)
fsm_readbuf() used to always do an smgrexists() when reading a buffer
beyond the known file size. That currently implies closing the md.c
handle, loosing all the data cached therein.  Change this to only
check for file existance when not already known to be larger than 0
blocks.

Author: Andres Freund
Reviewed-By:
Discussion: https://postgr.es/m/
Backpatch:

src/backend/storage/freespace/freespace.c

index 65c4e74999f101a4ae978df0fed5a70fd02288ed..d7569cec5ed0a466a19bf5c211ec8fdaf220ce25 100644 (file)
@@ -556,7 +556,7 @@ fsm_readbuf(Relation rel, FSMAddress addr, bool extend)
     * not on extension.)
     */
    if (rel->rd_smgr->smgr_fsm_nblocks == InvalidBlockNumber ||
-       blkno >= rel->rd_smgr->smgr_fsm_nblocks)
+       rel->rd_smgr->smgr_fsm_nblocks == 0)
    {
        if (smgrexists(rel->rd_smgr, FSM_FORKNUM))
            rel->rd_smgr->smgr_fsm_nblocks = smgrnblocks(rel->rd_smgr,
@@ -564,6 +564,9 @@ fsm_readbuf(Relation rel, FSMAddress addr, bool extend)
        else
            rel->rd_smgr->smgr_fsm_nblocks = 0;
    }
+   else if (blkno >= rel->rd_smgr->smgr_fsm_nblocks)
+       rel->rd_smgr->smgr_fsm_nblocks = smgrnblocks(rel->rd_smgr,
+                                                    FSM_FORKNUM);
 
    /* Handle requests beyond EOF */
    if (blkno >= rel->rd_smgr->smgr_fsm_nblocks)