summaryrefslogtreecommitdiff
path: root/src/backend/access/gist/gistbuild.c
diff options
context:
space:
mode:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>2020-09-21 14:50:07 +0300
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>2020-09-21 14:50:07 +0300
commitc47a240fe6db8293e2de1565233faee40afa64b6 (patch)
tree943e1c31e29d83b1caaf8bd5d2bcce94a5650723 /src/backend/access/gist/gistbuild.c
parentc2bb287025189d93c8df16b28f2a3d9d07d25655 (diff)
downloadpostgresql-c47a240fe6db8293e2de1565233faee40afa64b6.tar.gz
Fix checksum calculation in the new sorting GiST build.
Since we're bypassing the buffer manager, we need to call PageSetChecksumInplace() directly. As reported by Justin Pryzby. In the passing, add RelationOpenSmgr() calls before all smgrwrite() and smgrextend() calls. Tom added one before the first smgrextend() call in commit c2bb287025, which seems to be enough, but let's play it safe and do it before each one. That's how it's done in the similar code in nbtsort.c, too. Discussion: https://www.postgresql.org/message-id/20200920224446.GF30557@telsasoft.com
Diffstat (limited to 'src/backend/access/gist/gistbuild.c')
-rw-r--r--src/backend/access/gist/gistbuild.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/backend/access/gist/gistbuild.c b/src/backend/access/gist/gistbuild.c
index 5ecc4c87d1..188e33642f 100644
--- a/src/backend/access/gist/gistbuild.c
+++ b/src/backend/access/gist/gistbuild.c
@@ -449,7 +449,9 @@ gist_indexsortbuild(GISTBuildState *state)
gist_indexsortbuild_flush_ready_pages(state);
/* Write out the root */
+ RelationOpenSmgr(state->indexrel);
PageSetLSN(pagestate->page, GistBuildLSN);
+ PageSetChecksumInplace(pagestate->page, GIST_ROOT_BLKNO);
smgrwrite(state->indexrel->rd_smgr, MAIN_FORKNUM, GIST_ROOT_BLKNO,
pagestate->page, true);
if (RelationNeedsWAL(state->indexrel))
@@ -546,21 +548,22 @@ gist_indexsortbuild_flush_ready_pages(GISTBuildState *state)
if (state->ready_num_pages == 0)
return;
+ RelationOpenSmgr(state->indexrel);
+
for (int i = 0; i < state->ready_num_pages; i++)
{
Page page = state->ready_pages[i];
+ BlockNumber blkno = state->ready_blknos[i];
/* Currently, the blocks must be buffered in order. */
- if (state->ready_blknos[i] != state->pages_written)
+ if (blkno != state->pages_written)
elog(ERROR, "unexpected block number to flush GiST sorting build");
PageSetLSN(page, GistBuildLSN);
+ PageSetChecksumInplace(page, blkno);
+ smgrextend(state->indexrel->rd_smgr, MAIN_FORKNUM, blkno, page, true);
- smgrextend(state->indexrel->rd_smgr,
- MAIN_FORKNUM,
- state->pages_written++,
- page,
- true);
+ state->pages_written++;
}
if (RelationNeedsWAL(state->indexrel))