Commit 417fefaf authored by Andres Freund's avatar Andres Freund

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
parent 769fd9d8
...@@ -81,7 +81,7 @@ bool ...@@ -81,7 +81,7 @@ bool
PageIsVerified(Page page, BlockNumber blkno) PageIsVerified(Page page, BlockNumber blkno)
{ {
PageHeader p = (PageHeader) page; PageHeader p = (PageHeader) page;
char *pagebytes; size_t *pagebytes;
int i; int i;
bool checksum_failure = false; bool checksum_failure = false;
bool header_sane = false; bool header_sane = false;
...@@ -118,10 +118,17 @@ PageIsVerified(Page page, BlockNumber blkno) ...@@ -118,10 +118,17 @@ PageIsVerified(Page page, BlockNumber blkno)
return true; return true;
} }
/* Check all-zeroes case */ /*
* Check all-zeroes case. Luckily BLCKSZ is guaranteed to always be a
* multiple of size_t - and it's much faster to compare memory using the
* native word size.
*/
StaticAssertStmt(BLCKSZ == (BLCKSZ / sizeof(size_t)) * sizeof(size_t),
"BLCKSZ has to be a multiple of sizeof(size_t)");
all_zeroes = true; all_zeroes = true;
pagebytes = (char *) page; pagebytes = (size_t *) page;
for (i = 0; i < BLCKSZ; i++) for (i = 0; i < (BLCKSZ / sizeof(size_t)); i++)
{ {
if (pagebytes[i] != 0) if (pagebytes[i] != 0)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment