Skip to content

Commit b1cbc85

Browse files
committed
Fix brin index summarizing while vacuuming.
If the number of heap blocks is not multiples of pages per range, the summarizing produces wrong summary information for the last brin index tuple while vacuuming. Problem reported by Tatsuo Ishii and fixed by Amit Langote. Discussion at "[HACKERS] BRIN INDEX value (message id :20150903.174935.1946402199422994347.t-ishii@sraoss.co.jp) Backpatched to 9.5 in which brin index was added.
1 parent a2538da commit b1cbc85

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/backend/access/brin/brin.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -934,12 +934,13 @@ terminate_brin_buildstate(BrinBuildState *state)
934934
*/
935935
static void
936936
summarize_range(IndexInfo *indexInfo, BrinBuildState *state, Relation heapRel,
937-
BlockNumber heapBlk)
937+
BlockNumber heapBlk, BlockNumber heapNumBlks)
938938
{
939939
Buffer phbuf;
940940
BrinTuple *phtup;
941941
Size phsz;
942942
OffsetNumber offset;
943+
BlockNumber scanNumBlks;
943944

944945
/*
945946
* Insert the placeholder tuple
@@ -960,8 +961,10 @@ summarize_range(IndexInfo *indexInfo, BrinBuildState *state, Relation heapRel,
960961
* by transactions that are still in progress, among other corner cases.
961962
*/
962963
state->bs_currRangeStart = heapBlk;
964+
scanNumBlks = heapBlk + state->bs_pagesPerRange <= heapNumBlks ?
965+
state->bs_pagesPerRange : heapNumBlks - heapBlk;
963966
IndexBuildHeapRangeScan(heapRel, state->bs_irel, indexInfo, false, true,
964-
heapBlk, state->bs_pagesPerRange,
967+
heapBlk, scanNumBlks,
965968
brinbuildCallback, (void *) state);
966969

967970
/*
@@ -1066,7 +1069,7 @@ brinsummarize(Relation index, Relation heapRel, double *numSummarized,
10661069
pagesPerRange);
10671070
indexInfo = BuildIndexInfo(index);
10681071
}
1069-
summarize_range(indexInfo, state, heapRel, heapBlk);
1072+
summarize_range(indexInfo, state, heapRel, heapBlk, heapNumBlocks);
10701073

10711074
/* and re-initialize state for the next range */
10721075
brin_memtuple_initialize(state->bs_dtuple, state->bs_bdesc);

0 commit comments

Comments
 (0)