mirror of
https://github.com/postgres/postgres.git
synced 2025-11-22 12:22:45 +03:00
Generate less WAL during GiST, GIN and SP-GiST index build.
Instead of WAL-logging every modification during the build separately, first build the index without any WAL-logging, and make a separate pass through the index at the end, to write all pages to the WAL. This significantly reduces the amount of WAL generated, and is usually also faster, despite the extra I/O needed for the extra scan through the index. WAL generated this way is also faster to replay. For GiST, the LSN-NSN interlock makes this a little tricky. All pages must be marked with a valid (i.e. non-zero) LSN, so that the parent-child LSN-NSN interlock works correctly. We now use magic value 1 for that during index build. Change the fake LSN counter to begin from 1000, so that 1 is safely smaller than any real or fake LSN. 2 would've been enough for our purposes, but let's reserve a bigger range, in case we need more special values in the future. Author: Anastasia Lubennikova, Andrey V. Lepikhov Reviewed-by: Heikki Linnakangas, Dmitry Dolgov
This commit is contained in:
@@ -593,7 +593,7 @@ dataBeginPlaceToPageLeaf(GinBtree btree, Buffer buf, GinBtreeStack *stack,
|
||||
* Great, all the items fit on a single page. If needed, prepare data
|
||||
* for a WAL record describing the changes we'll make.
|
||||
*/
|
||||
if (RelationNeedsWAL(btree->index))
|
||||
if (RelationNeedsWAL(btree->index) && !btree->isBuild)
|
||||
computeLeafRecompressWALData(leaf);
|
||||
|
||||
/*
|
||||
@@ -719,7 +719,7 @@ dataExecPlaceToPageLeaf(GinBtree btree, Buffer buf, GinBtreeStack *stack,
|
||||
dataPlaceToPageLeafRecompress(buf, leaf);
|
||||
|
||||
/* If needed, register WAL data built by computeLeafRecompressWALData */
|
||||
if (RelationNeedsWAL(btree->index))
|
||||
if (RelationNeedsWAL(btree->index) && !btree->isBuild)
|
||||
{
|
||||
XLogRegisterBufData(0, leaf->walinfo, leaf->walinfolen);
|
||||
}
|
||||
@@ -1152,7 +1152,7 @@ dataExecPlaceToPageInternal(GinBtree btree, Buffer buf, GinBtreeStack *stack,
|
||||
pitem = (PostingItem *) insertdata;
|
||||
GinDataPageAddPostingItem(page, pitem, off);
|
||||
|
||||
if (RelationNeedsWAL(btree->index))
|
||||
if (RelationNeedsWAL(btree->index) && !btree->isBuild)
|
||||
{
|
||||
/*
|
||||
* This must be static, because it has to survive until XLogInsert,
|
||||
@@ -1773,6 +1773,7 @@ createPostingTree(Relation index, ItemPointerData *items, uint32 nitems,
|
||||
Pointer ptr;
|
||||
int nrootitems;
|
||||
int rootsize;
|
||||
bool is_build = (buildStats != NULL);
|
||||
|
||||
/* Construct the new root page in memory first. */
|
||||
tmppage = (Page) palloc(BLCKSZ);
|
||||
@@ -1826,7 +1827,7 @@ createPostingTree(Relation index, ItemPointerData *items, uint32 nitems,
|
||||
PageRestoreTempPage(tmppage, page);
|
||||
MarkBufferDirty(buffer);
|
||||
|
||||
if (RelationNeedsWAL(index))
|
||||
if (RelationNeedsWAL(index) && !is_build)
|
||||
{
|
||||
XLogRecPtr recptr;
|
||||
ginxlogCreatePostingTree data;
|
||||
|
||||
Reference in New Issue
Block a user