summaryrefslogtreecommitdiff
path: root/src/backend/access
diff options
context:
space:
mode:
authorTatsuo Ishii2015-09-05 00:19:25 +0000
committerTatsuo Ishii2015-09-05 00:19:25 +0000
commitc39f5674dfc77802b4245dd92cb4b1e35499a5a5 (patch)
tree7cccee53f3def9204a4c4e7dea1dec286dde6b88 /src/backend/access
parentc5454f99c49fce01ce946b5f52a4929c21d5f229 (diff)
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 :[email protected]) Backpatched to 9.5 in which brin index was added.
Diffstat (limited to 'src/backend/access')
-rw-r--r--src/backend/access/brin/brin.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/backend/access/brin/brin.c b/src/backend/access/brin/brin.c
index 25d2a094dda..99337b0f0c0 100644
--- a/src/backend/access/brin/brin.c
+++ b/src/backend/access/brin/brin.c
@@ -934,12 +934,13 @@ terminate_brin_buildstate(BrinBuildState *state)
*/
static void
summarize_range(IndexInfo *indexInfo, BrinBuildState *state, Relation heapRel,
- BlockNumber heapBlk)
+ BlockNumber heapBlk, BlockNumber heapNumBlks)
{
Buffer phbuf;
BrinTuple *phtup;
Size phsz;
OffsetNumber offset;
+ BlockNumber scanNumBlks;
/*
* Insert the placeholder tuple
@@ -960,8 +961,10 @@ summarize_range(IndexInfo *indexInfo, BrinBuildState *state, Relation heapRel,
* by transactions that are still in progress, among other corner cases.
*/
state->bs_currRangeStart = heapBlk;
+ scanNumBlks = heapBlk + state->bs_pagesPerRange <= heapNumBlks ?
+ state->bs_pagesPerRange : heapNumBlks - heapBlk;
IndexBuildHeapRangeScan(heapRel, state->bs_irel, indexInfo, false, true,
- heapBlk, state->bs_pagesPerRange,
+ heapBlk, scanNumBlks,
brinbuildCallback, (void *) state);
/*
@@ -1066,7 +1069,7 @@ brinsummarize(Relation index, Relation heapRel, double *numSummarized,
pagesPerRange);
indexInfo = BuildIndexInfo(index);
}
- summarize_range(indexInfo, state, heapRel, heapBlk);
+ summarize_range(indexInfo, state, heapRel, heapBlk, heapNumBlocks);
/* and re-initialize state for the next range */
brin_memtuple_initialize(state->bs_dtuple, state->bs_bdesc);