Skip to content

Commit 417fefa

Browse files
committed
Faster PageIsVerified() for the all zeroes case.
That's primarily useful for testing very large relations, using sparse files. Discussion: <20140331101001.GE13135@alap3.anarazel.de> Reviewed-By: Peter Geoghegan
1 parent 769fd9d commit 417fefa

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/backend/storage/page/bufpage.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ bool
8181
PageIsVerified(Page page, BlockNumber blkno)
8282
{
8383
PageHeader p = (PageHeader) page;
84-
char *pagebytes;
84+
size_t *pagebytes;
8585
int i;
8686
bool checksum_failure = false;
8787
bool header_sane = false;
@@ -118,10 +118,17 @@ PageIsVerified(Page page, BlockNumber blkno)
118118
return true;
119119
}
120120

121-
/* Check all-zeroes case */
121+
/*
122+
* Check all-zeroes case. Luckily BLCKSZ is guaranteed to always be a
123+
* multiple of size_t - and it's much faster to compare memory using the
124+
* native word size.
125+
*/
126+
StaticAssertStmt(BLCKSZ == (BLCKSZ / sizeof(size_t)) * sizeof(size_t),
127+
"BLCKSZ has to be a multiple of sizeof(size_t)");
128+
122129
all_zeroes = true;
123-
pagebytes = (char *) page;
124-
for (i = 0; i < BLCKSZ; i++)
130+
pagebytes = (size_t *) page;
131+
for (i = 0; i < (BLCKSZ / sizeof(size_t)); i++)
125132
{
126133
if (pagebytes[i] != 0)
127134
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy