Skip to content
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

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

Open
wants to merge 1 commit into
base: REL_14_STABLE_neon
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Expand Up @@ -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));
Expand Down Expand Up @@ -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.
Expand All @@ -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_rnode.node, MAIN_FORKNUM, 0, RelationGetNumberOfBlocks(index));
SetLastWrittenLSNForRelation(XactLastRecEnd, index->rd_smgr->smgr_rnode.node, MAIN_FORKNUM);
}

smgr_end_unlogged_build(index->rd_smgr);

/*
* Return statistics
*/
Expand Down
9 changes: 0 additions & 9 deletions src/backend/access/gist/gistbuild.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,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);
Assert(BufferGetBlockNumber(buffer) == GIST_ROOT_BLKNO);
Expand Down Expand Up @@ -324,8 +322,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.
Expand All @@ -335,12 +331,7 @@ gistbuild(Relation heap, Relation index, IndexInfo *indexInfo)
log_newpage_range(index, MAIN_FORKNUM,
0, RelationGetNumberOfBlocks(index),
true);
SetLastWrittenLSNForBlockRange(XactLastRecEnd,
index->rd_smgr->smgr_rnode.node,
MAIN_FORKNUM, 0, RelationGetNumberOfBlocks(index));
SetLastWrittenLSNForRelation(XactLastRecEnd, index->rd_smgr->smgr_rnode.node, MAIN_FORKNUM);
}
smgr_end_unlogged_build(index->rd_smgr);
}

/* okay, all heap tuples are indexed */
Expand Down
9 changes: 0 additions & 9 deletions src/backend/access/spgist/spginsert.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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.
Expand All @@ -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_rnode.node,
MAIN_FORKNUM, 0, RelationGetNumberOfBlocks(index));
SetLastWrittenLSNForRelation(XactLastRecEnd, index->rd_smgr->smgr_rnode.node, MAIN_FORKNUM);
}

smgr_end_unlogged_build(index->rd_smgr);

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

/* Buffer size required to store a compressed version of backup block image */
Expand Down Expand Up @@ -68,6 +69,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
Expand Down Expand Up @@ -1159,6 +1162,7 @@ log_newpage_range(Relation rel, ForkNumber forkNum,
XLogRecPtr recptr;
int nbufs;
int i;
BlockNumber firstblk = blkno;

CHECK_FOR_INTERRUPTS();

Expand Down Expand Up @@ -1189,7 +1193,6 @@ log_newpage_range(Relation rel, ForkNumber forkNum,

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

START_CRIT_SECTION();
for (i = 0; i < nbufs; i++)
{
Expand All @@ -1198,14 +1201,18 @@ log_newpage_range(Relation rel, ForkNumber forkNum,
}

recptr = XLogInsert(RM_XLOG_ID, XLOG_FPI);

SetLastWrittenLSNForBlockRange(recptr, rel->rd_smgr->smgr_rnode.node,
forkNum, firstblk, blkno - firstblk);
SetLastWrittenLSNForRelation(recptr, rel->rd_smgr->smgr_rnode.node, 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);
}

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

/*
* Zenith-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);
}

/*
* AtEOXact_SMgr
*
Expand Down
4 changes: 4 additions & 0 deletions src/include/access/xloginsert.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
5 changes: 0 additions & 5 deletions src/include/storage/smgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,6 @@ typedef struct f_smgr
BlockNumber nblocks);
void (*smgr_immedsync) (SMgrRelation reln, ForkNumber forknum);

void (*smgr_reset_prefetch) (SMgrRelation reln);
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;

Expand Down