Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c47a240

Browse files
committed
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 c2bb287, 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
1 parent c2bb287 commit c47a240

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/backend/access/gist/gistbuild.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,9 @@ gist_indexsortbuild(GISTBuildState *state)
449449
gist_indexsortbuild_flush_ready_pages(state);
450450

451451
/* Write out the root */
452+
RelationOpenSmgr(state->indexrel);
452453
PageSetLSN(pagestate->page, GistBuildLSN);
454+
PageSetChecksumInplace(pagestate->page, GIST_ROOT_BLKNO);
453455
smgrwrite(state->indexrel->rd_smgr, MAIN_FORKNUM, GIST_ROOT_BLKNO,
454456
pagestate->page, true);
455457
if (RelationNeedsWAL(state->indexrel))
@@ -546,21 +548,22 @@ gist_indexsortbuild_flush_ready_pages(GISTBuildState *state)
546548
if (state->ready_num_pages == 0)
547549
return;
548550

551+
RelationOpenSmgr(state->indexrel);
552+
549553
for (int i = 0; i < state->ready_num_pages; i++)
550554
{
551555
Page page = state->ready_pages[i];
556+
BlockNumber blkno = state->ready_blknos[i];
552557

553558
/* Currently, the blocks must be buffered in order. */
554-
if (state->ready_blknos[i] != state->pages_written)
559+
if (blkno != state->pages_written)
555560
elog(ERROR, "unexpected block number to flush GiST sorting build");
556561

557562
PageSetLSN(page, GistBuildLSN);
563+
PageSetChecksumInplace(page, blkno);
564+
smgrextend(state->indexrel->rd_smgr, MAIN_FORKNUM, blkno, page, true);
558565

559-
smgrextend(state->indexrel->rd_smgr,
560-
MAIN_FORKNUM,
561-
state->pages_written++,
562-
page,
563-
true);
566+
state->pages_written++;
564567
}
565568

566569
if (RelationNeedsWAL(state->indexrel))

0 commit comments

Comments
 (0)