Skip to content

Commit 4c0239c

Browse files
committed
Remove redundant memset(0) calls for page init of some index AMs
Bloom, GIN, GiST and SP-GiST rely on PageInit() to initialize the contents of a page, and this routine fills entirely a page with zeros for a size of BLCKSZ, including the special space. Those index AMs have been using an extra memset() call to fill with zeros the special page space, or even the whole page, which is not necessary as PageInit() already does this work, so let's remove them. GiST was not doing this extra call, but has commented out a system call that did so since 6236991. While on it, remove one MAXALIGN() for SP-GiST as PageInit() takes care of that. This makes the whole page initialization logic more consistent across all index AMs. Author: Bharath Rupireddy Reviewed-by: Vignesh C, Mahendra Singh Thalor Discussion: https://postgr.es/m/CALj2ACViOo2qyaPT7krWm4LRyRTw9kOXt+g6PfNmYuGA=YHj9A@mail.gmail.com
1 parent 9afffcb commit 4c0239c

File tree

5 files changed

+1
-7
lines changed

5 files changed

+1
-7
lines changed

contrib/bloom/blinsert.c

-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ flushCachedPage(Relation index, BloomBuildState *buildstate)
6363
static void
6464
initCachedPage(BloomBuildState *buildstate)
6565
{
66-
memset(buildstate->data.data, 0, BLCKSZ);
6766
BloomInitPage(buildstate->data.data, 0);
6867
buildstate->count = 0;
6968
}

contrib/bloom/blutils.c

-1
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,6 @@ BloomInitPage(Page page, uint16 flags)
411411
PageInit(page, BLCKSZ, sizeof(BloomPageOpaqueData));
412412

413413
opaque = BloomPageGetOpaque(page);
414-
memset(opaque, 0, sizeof(BloomPageOpaqueData));
415414
opaque->flags = flags;
416415
opaque->bloom_page_id = BLOOM_PAGE_ID;
417416
}

src/backend/access/gin/ginutil.c

-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,6 @@ GinInitPage(Page page, uint32 f, Size pageSize)
348348
PageInit(page, pageSize, sizeof(GinPageOpaqueData));
349349

350350
opaque = GinPageGetOpaque(page);
351-
memset(opaque, 0, sizeof(GinPageOpaqueData));
352351
opaque->flags = f;
353352
opaque->rightlink = InvalidBlockNumber;
354353
}

src/backend/access/gist/gistutil.c

-2
Original file line numberDiff line numberDiff line change
@@ -761,8 +761,6 @@ gistinitpage(Page page, uint32 f)
761761
PageInit(page, pageSize, sizeof(GISTPageOpaqueData));
762762

763763
opaque = GistPageGetOpaque(page);
764-
/* page was already zeroed by PageInit, so this is not needed: */
765-
/* memset(&(opaque->nsn), 0, sizeof(GistNSN)); */
766764
opaque->rightlink = InvalidBlockNumber;
767765
opaque->flags = f;
768766
opaque->gist_page_id = GIST_PAGE_ID;

src/backend/access/spgist/spgutils.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -677,9 +677,8 @@ SpGistInitPage(Page page, uint16 f)
677677
{
678678
SpGistPageOpaque opaque;
679679

680-
PageInit(page, BLCKSZ, MAXALIGN(sizeof(SpGistPageOpaqueData)));
680+
PageInit(page, BLCKSZ, sizeof(SpGistPageOpaqueData));
681681
opaque = SpGistPageGetOpaque(page);
682-
memset(opaque, 0, sizeof(SpGistPageOpaqueData));
683682
opaque->flags = f;
684683
opaque->spgist_page_id = SPGIST_PAGE_ID;
685684
}

0 commit comments

Comments
 (0)