Commit 4c0239cb authored by Michael Paquier's avatar Michael Paquier

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
62369911.

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
parent 9afffcb8
...@@ -63,7 +63,6 @@ flushCachedPage(Relation index, BloomBuildState *buildstate) ...@@ -63,7 +63,6 @@ flushCachedPage(Relation index, BloomBuildState *buildstate)
static void static void
initCachedPage(BloomBuildState *buildstate) initCachedPage(BloomBuildState *buildstate)
{ {
memset(buildstate->data.data, 0, BLCKSZ);
BloomInitPage(buildstate->data.data, 0); BloomInitPage(buildstate->data.data, 0);
buildstate->count = 0; buildstate->count = 0;
} }
......
...@@ -411,7 +411,6 @@ BloomInitPage(Page page, uint16 flags) ...@@ -411,7 +411,6 @@ BloomInitPage(Page page, uint16 flags)
PageInit(page, BLCKSZ, sizeof(BloomPageOpaqueData)); PageInit(page, BLCKSZ, sizeof(BloomPageOpaqueData));
opaque = BloomPageGetOpaque(page); opaque = BloomPageGetOpaque(page);
memset(opaque, 0, sizeof(BloomPageOpaqueData));
opaque->flags = flags; opaque->flags = flags;
opaque->bloom_page_id = BLOOM_PAGE_ID; opaque->bloom_page_id = BLOOM_PAGE_ID;
} }
......
...@@ -348,7 +348,6 @@ GinInitPage(Page page, uint32 f, Size pageSize) ...@@ -348,7 +348,6 @@ GinInitPage(Page page, uint32 f, Size pageSize)
PageInit(page, pageSize, sizeof(GinPageOpaqueData)); PageInit(page, pageSize, sizeof(GinPageOpaqueData));
opaque = GinPageGetOpaque(page); opaque = GinPageGetOpaque(page);
memset(opaque, 0, sizeof(GinPageOpaqueData));
opaque->flags = f; opaque->flags = f;
opaque->rightlink = InvalidBlockNumber; opaque->rightlink = InvalidBlockNumber;
} }
......
...@@ -761,8 +761,6 @@ gistinitpage(Page page, uint32 f) ...@@ -761,8 +761,6 @@ gistinitpage(Page page, uint32 f)
PageInit(page, pageSize, sizeof(GISTPageOpaqueData)); PageInit(page, pageSize, sizeof(GISTPageOpaqueData));
opaque = GistPageGetOpaque(page); opaque = GistPageGetOpaque(page);
/* page was already zeroed by PageInit, so this is not needed: */
/* memset(&(opaque->nsn), 0, sizeof(GistNSN)); */
opaque->rightlink = InvalidBlockNumber; opaque->rightlink = InvalidBlockNumber;
opaque->flags = f; opaque->flags = f;
opaque->gist_page_id = GIST_PAGE_ID; opaque->gist_page_id = GIST_PAGE_ID;
......
...@@ -677,9 +677,8 @@ SpGistInitPage(Page page, uint16 f) ...@@ -677,9 +677,8 @@ SpGistInitPage(Page page, uint16 f)
{ {
SpGistPageOpaque opaque; SpGistPageOpaque opaque;
PageInit(page, BLCKSZ, MAXALIGN(sizeof(SpGistPageOpaqueData))); PageInit(page, BLCKSZ, sizeof(SpGistPageOpaqueData));
opaque = SpGistPageGetOpaque(page); opaque = SpGistPageGetOpaque(page);
memset(opaque, 0, sizeof(SpGistPageOpaqueData));
opaque->flags = f; opaque->flags = f;
opaque->spgist_page_id = SPGIST_PAGE_ID; opaque->spgist_page_id = SPGIST_PAGE_ID;
} }
......
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