From: Tom Lane Date: Tue, 5 Aug 2008 15:09:04 +0000 (+0000) Subject: In ReadOrZeroBuffer (and related entry points), don't bother to call X-Git-Tag: REL8_4_BETA1~1107 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d8b04d5fac574d96252230c39a16f651b185661f;p=postgresql In ReadOrZeroBuffer (and related entry points), don't bother to call PageHeaderIsValid when we zero the buffer instead of reading the page in. The actual performance improvement is probably marginal since this function isn't very heavily used, but a cycle saved is a cycle earned. Zdenek Kotala --- diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index e40a815b5d..456dc42336 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.235 2008/08/01 13:16:08 alvherre Exp $ + * $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.236 2008/08/05 15:09:04 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -352,28 +352,31 @@ ReadBuffer_common(SMgrRelation smgr, bool isLocalBuf, BlockNumber blockNum, if (zeroPage) MemSet((char *) bufBlock, 0, BLCKSZ); else - smgrread(smgr, blockNum, (char *) bufBlock); - /* check for garbage data */ - if (!PageHeaderIsValid((PageHeader) bufBlock)) { - if (zero_damaged_pages) + smgrread(smgr, blockNum, (char *) bufBlock); + + /* check for garbage data */ + if (!PageHeaderIsValid((PageHeader) bufBlock)) { - ereport(WARNING, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("invalid page header in block %u of relation %u/%u/%u; zeroing out page", - blockNum, - smgr->smgr_rnode.spcNode, - smgr->smgr_rnode.dbNode, - smgr->smgr_rnode.relNode))); - MemSet((char *) bufBlock, 0, BLCKSZ); + if (zero_damaged_pages) + { + ereport(WARNING, + (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("invalid page header in block %u of relation %u/%u/%u; zeroing out page", + blockNum, + smgr->smgr_rnode.spcNode, + smgr->smgr_rnode.dbNode, + smgr->smgr_rnode.relNode))); + MemSet((char *) bufBlock, 0, BLCKSZ); + } + else + ereport(ERROR, + (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("invalid page header in block %u of relation %u/%u/%u", + blockNum, smgr->smgr_rnode.spcNode, + smgr->smgr_rnode.dbNode, + smgr->smgr_rnode.relNode))); } - else - ereport(ERROR, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("invalid page header in block %u of relation %u/%u/%u", - blockNum, smgr->smgr_rnode.spcNode, - smgr->smgr_rnode.dbNode, - smgr->smgr_rnode.relNode))); } }