Remove redundant memset(0) calls for page init of some index AMs
authorMichael Paquier <michael@paquier.xyz>
Wed, 7 Apr 2021 05:35:26 +0000 (14:35 +0900)
committerMichael Paquier <michael@paquier.xyz>
Wed, 7 Apr 2021 05:35:26 +0000 (14:35 +0900)
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

contrib/bloom/blinsert.c
contrib/bloom/blutils.c
src/backend/access/gin/ginutil.c
src/backend/access/gist/gistutil.c
src/backend/access/spgist/spgutils.c

index d37ceef753ab0110e38cade086699e62e3e2fdff..c34a640d1c44230ed94467b27c4cf6adc4a053f5 100644 (file)
@@ -63,7 +63,6 @@ flushCachedPage(Relation index, BloomBuildState *buildstate)
 static void
 initCachedPage(BloomBuildState *buildstate)
 {
-   memset(buildstate->data.data, 0, BLCKSZ);
    BloomInitPage(buildstate->data.data, 0);
    buildstate->count = 0;
 }
index 1e505b1da54242b83f6bd8d2ea967c62e046ea9a..754de008d43f4d3d9b448c369837b28695d6c2a1 100644 (file)
@@ -411,7 +411,6 @@ BloomInitPage(Page page, uint16 flags)
    PageInit(page, BLCKSZ, sizeof(BloomPageOpaqueData));
 
    opaque = BloomPageGetOpaque(page);
-   memset(opaque, 0, sizeof(BloomPageOpaqueData));
    opaque->flags = flags;
    opaque->bloom_page_id = BLOOM_PAGE_ID;
 }
index 6b9b04cf429e39480ae2e6c136246aa675d87864..cdd626ff0a444c5130302ff7d03c093777a8a07e 100644 (file)
@@ -348,7 +348,6 @@ GinInitPage(Page page, uint32 f, Size pageSize)
    PageInit(page, pageSize, sizeof(GinPageOpaqueData));
 
    opaque = GinPageGetOpaque(page);
-   memset(opaque, 0, sizeof(GinPageOpaqueData));
    opaque->flags = f;
    opaque->rightlink = InvalidBlockNumber;
 }
index 1ff1bf816f1b45f6e342a83b971e6726f9a94529..8dcd53c457799722463428538f2fed6b38e95930 100644 (file)
@@ -761,8 +761,6 @@ gistinitpage(Page page, uint32 f)
    PageInit(page, pageSize, sizeof(GISTPageOpaqueData));
 
    opaque = GistPageGetOpaque(page);
-   /* page was already zeroed by PageInit, so this is not needed: */
-   /* memset(&(opaque->nsn), 0, sizeof(GistNSN)); */
    opaque->rightlink = InvalidBlockNumber;
    opaque->flags = f;
    opaque->gist_page_id = GIST_PAGE_ID;
index 72cbde7e0b6c5dcf705bbb2afd26a7eefcbda443..8d99c9b762622b77acde99fa82c996e153c6c448 100644 (file)
@@ -677,9 +677,8 @@ SpGistInitPage(Page page, uint16 f)
 {
    SpGistPageOpaque opaque;
 
-   PageInit(page, BLCKSZ, MAXALIGN(sizeof(SpGistPageOpaqueData)));
+   PageInit(page, BLCKSZ, sizeof(SpGistPageOpaqueData));
    opaque = SpGistPageGetOpaque(page);
-   memset(opaque, 0, sizeof(SpGistPageOpaqueData));
    opaque->flags = f;
    opaque->spgist_page_id = SPGIST_PAGE_ID;
 }