Skip to content

Undo changes in Postgres core for building GIST/GIN indexes #433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: REL_16_STABLE_neon
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions src/backend/access/gin/gininsert.c
Original file line number Diff line number Diff line change
@@ -335,8 +335,6 @@ ginbuild(Relation heap, Relation index, IndexInfo *indexInfo)
elog(ERROR, "index \"%s\" already contains data",
RelationGetRelationName(index));

smgr_start_unlogged_build(index->rd_smgr);

initGinState(&buildstate.ginstate, index);
buildstate.indtuples = 0;
memset(&buildstate.buildStats, 0, sizeof(GinStatsData));
@@ -410,8 +408,6 @@ ginbuild(Relation heap, Relation index, IndexInfo *indexInfo)
buildstate.buildStats.nTotalPages = RelationGetNumberOfBlocks(index);
ginUpdateStats(index, &buildstate.buildStats, true);

smgr_finish_unlogged_build_phase_1(index->rd_smgr);

/*
* We didn't write WAL records as we built the index, so if WAL-logging is
* required, write all pages to the WAL now.
@@ -421,12 +417,8 @@ ginbuild(Relation heap, Relation index, IndexInfo *indexInfo)
log_newpage_range(index, MAIN_FORKNUM,
0, RelationGetNumberOfBlocks(index),
true);
SetLastWrittenLSNForBlockRange(XactLastRecEnd, index->rd_smgr->smgr_rlocator.locator, MAIN_FORKNUM, 0, RelationGetNumberOfBlocks(index));
SetLastWrittenLSNForRelation(XactLastRecEnd, index->rd_smgr->smgr_rlocator.locator, MAIN_FORKNUM);
}

smgr_end_unlogged_build(index->rd_smgr);

/*
* Return statistics
*/
10 changes: 0 additions & 10 deletions src/backend/access/gist/gistbuild.c
Original file line number Diff line number Diff line change
@@ -298,8 +298,6 @@ gistbuild(Relation heap, Relation index, IndexInfo *indexInfo)
Buffer buffer;
Page page;

smgr_start_unlogged_build(index->rd_smgr);

/* initialize the root page */
buffer = gistNewBuffer(index, heap);
Assert(BufferGetBlockNumber(buffer) == GIST_ROOT_BLKNO);
@@ -332,8 +330,6 @@ gistbuild(Relation heap, Relation index, IndexInfo *indexInfo)
gistFreeBuildBuffers(buildstate.gfbb);
}

smgr_finish_unlogged_build_phase_1(index->rd_smgr);

/*
* We didn't write WAL records as we built the index, so if
* WAL-logging is required, write all pages to the WAL now.
@@ -343,13 +339,7 @@ gistbuild(Relation heap, Relation index, IndexInfo *indexInfo)
log_newpage_range(index, MAIN_FORKNUM,
0, RelationGetNumberOfBlocks(index),
true);
SetLastWrittenLSNForBlockRange(XactLastRecEnd,
index->rd_smgr->smgr_rlocator.locator,
MAIN_FORKNUM, 0, RelationGetNumberOfBlocks(index));
SetLastWrittenLSNForRelation(XactLastRecEnd, index->rd_smgr->smgr_rlocator.locator, MAIN_FORKNUM);
}

smgr_end_unlogged_build(index->rd_smgr);
}

/* okay, all heap tuples are indexed */
6 changes: 4 additions & 2 deletions src/backend/access/gist/gistutil.c
Original file line number Diff line number Diff line change
@@ -793,13 +793,15 @@ gistcheckpage(Relation rel, Buffer buf)
* case, however.
*/
if (PageIsNew(page))
{
ereport(ERROR,
(errcode(ERRCODE_INDEX_CORRUPTED),
errmsg("index \"%s\" contains unexpected zero page at block %u",
errmsg("index \"%s\" (%d) contains unexpected zero page at block %u",
RelationGetRelationName(rel),
RelationGetRelid(rel),
BufferGetBlockNumber(buf)),
errhint("Please REINDEX it.")));

}
/*
* Additionally check that the special area looks sane.
*/
9 changes: 0 additions & 9 deletions src/backend/access/spgist/spginsert.c
Original file line number Diff line number Diff line change
@@ -85,8 +85,6 @@ spgbuild(Relation heap, Relation index, IndexInfo *indexInfo)
elog(ERROR, "index \"%s\" already contains data",
RelationGetRelationName(index));

smgr_start_unlogged_build(index->rd_smgr);

/*
* Initialize the meta page and root pages
*/
@@ -133,8 +131,6 @@ spgbuild(Relation heap, Relation index, IndexInfo *indexInfo)

SpGistUpdateMetaPage(index);

smgr_finish_unlogged_build_phase_1(index->rd_smgr);

/*
* We didn't write WAL records as we built the index, so if WAL-logging is
* required, write all pages to the WAL now.
@@ -144,13 +140,8 @@ spgbuild(Relation heap, Relation index, IndexInfo *indexInfo)
log_newpage_range(index, MAIN_FORKNUM,
0, RelationGetNumberOfBlocks(index),
true);
SetLastWrittenLSNForBlockRange(XactLastRecEnd, index->rd_smgr->smgr_rlocator.locator,
MAIN_FORKNUM, 0, RelationGetNumberOfBlocks(index));
SetLastWrittenLSNForRelation(XactLastRecEnd, index->rd_smgr->smgr_rlocator.locator, MAIN_FORKNUM);
}

smgr_end_unlogged_build(index->rd_smgr);

result = (IndexBuildResult *) palloc0(sizeof(IndexBuildResult));
result->heap_tuples = reltuples;
result->index_tuples = buildstate.indtuples;
11 changes: 9 additions & 2 deletions src/backend/access/transam/xloginsert.c
Original file line number Diff line number Diff line change
@@ -41,6 +41,7 @@
#include "storage/bufmgr.h"
#include "storage/proc.h"
#include "utils/memutils.h"
#include "utils/rel.h"
#include "utils/wait_event.h"

/*
@@ -94,6 +95,8 @@ int max_replication_apply_lag;
int max_replication_flush_lag;
int max_replication_write_lag;

log_newpage_range_callback_t log_newpage_range_callback;

static registered_buffer *registered_buffers;
static int max_registered_buffers; /* allocated size */
static int max_registered_block_id = 0; /* highest block_id + 1 currently
@@ -1305,6 +1308,7 @@ log_newpage_range(Relation rel, ForkNumber forknum,
XLogRecPtr recptr;
int nbufs;
int i;
BlockNumber firstblk = blkno;

CHECK_FOR_INTERRUPTS();

@@ -1335,7 +1339,6 @@ log_newpage_range(Relation rel, ForkNumber forknum,

/* Write WAL record for this batch. */
XLogBeginInsert();

START_CRIT_SECTION();
for (i = 0; i < nbufs; i++)
{
@@ -1344,14 +1347,18 @@ log_newpage_range(Relation rel, ForkNumber forknum,
}

recptr = XLogInsert(RM_XLOG_ID, XLOG_FPI);

SetLastWrittenLSNForBlockRange(recptr, rel->rd_smgr->smgr_rlocator.locator,
forknum, firstblk, blkno - firstblk);
SetLastWrittenLSNForRelation(recptr, rel->rd_smgr->smgr_rlocator.locator, forknum);
for (i = 0; i < nbufs; i++)
{
PageSetLSN(BufferGetPage(bufpack[i]), recptr);
UnlockReleaseBuffer(bufpack[i]);
}
END_CRIT_SECTION();
}
if (log_newpage_range_callback)
log_newpage_range_callback(rel, forknum);
}

/*
24 changes: 0 additions & 24 deletions src/backend/storage/smgr/smgr.c
Original file line number Diff line number Diff line change
@@ -725,30 +725,6 @@ smgrimmedsync(SMgrRelation reln, ForkNumber forknum)
(*reln->smgr).smgr_immedsync(reln, forknum);
}

/*
* Neon-added functions to mark the phases of an unlogged index build.
*/
void
smgr_start_unlogged_build(SMgrRelation reln)
{
if ((*reln->smgr).smgr_start_unlogged_build)
(*reln->smgr).smgr_start_unlogged_build(reln);
}

void
smgr_finish_unlogged_build_phase_1(SMgrRelation reln)
{
if ((*reln->smgr).smgr_finish_unlogged_build_phase_1)
(*reln->smgr).smgr_finish_unlogged_build_phase_1(reln);
}

void
smgr_end_unlogged_build(SMgrRelation reln)
{
if ((*reln->smgr).smgr_end_unlogged_build)
(*reln->smgr).smgr_end_unlogged_build(reln);
}

/*
* NEON: we do not want to include large pg_xact/multixact files in basebackup and prefer
* to download them on demand to reduce startup time.
4 changes: 4 additions & 0 deletions src/include/access/xloginsert.h
Original file line number Diff line number Diff line change
@@ -67,4 +67,8 @@ extern XLogRecPtr XLogSaveBufferForHint(Buffer buffer, bool buffer_std);

extern void InitXLogInsert(void);

typedef void (*log_newpage_range_callback_t)(Relation rel, ForkNumber forknum);
extern log_newpage_range_callback_t log_newpage_range_callback;


#endif /* XLOGINSERT_H */
4 changes: 0 additions & 4 deletions src/include/storage/smgr.h
Original file line number Diff line number Diff line change
@@ -127,10 +127,6 @@ typedef struct f_smgr
BlockNumber nblocks);
void (*smgr_immedsync) (SMgrRelation reln, ForkNumber forknum);

void (*smgr_start_unlogged_build) (SMgrRelation reln);
void (*smgr_finish_unlogged_build_phase_1) (SMgrRelation reln);
void (*smgr_end_unlogged_build) (SMgrRelation reln);

int (*smgr_read_slru_segment) (SMgrRelation reln, const char *path, int segno, void* buffer);
} f_smgr;