On 9/4/2015 8:28 AM, Tatsuo Ishii wrote: >> >> Attached hack fixes the symptom but perhaps not the correct fix for this. > > Why can't we fix summarize_range() in brin.c: > > IndexBuildHeapRangeScan(heapRel, state->bs_irel, indexInfo, false, true, > heapBlk, > state->bs_pagesPerRange, > brinbuildCallback, > (void *) state); > > This currently thoughtlessly passes scannumblocks as > state->bs_pagesPerRange. Shouldn't we change this so that > (scanStartBlock + scanNumBlocks) does not exceed scan->rs_nblocks? >
Ah, it did cross my mind to the fix it in brin.c but was not sure. I did it that way in the attached patch. Thanks, Amit
diff --git a/src/backend/access/brin/brin.c b/src/backend/access/brin/brin.c index 25d2a09..198ec13 100644 --- a/src/backend/access/brin/brin.c +++ b/src/backend/access/brin/brin.c @@ -940,6 +940,8 @@ summarize_range(IndexInfo *indexInfo, BrinBuildState *state, Relation heapRel, BrinTuple *phtup; Size phsz; OffsetNumber offset; + BlockNumber heapNumBlks; + BlockNumber scanNumBlks; /* * Insert the placeholder tuple @@ -960,8 +962,11 @@ summarize_range(IndexInfo *indexInfo, BrinBuildState *state, Relation heapRel, * by transactions that are still in progress, among other corner cases. */ state->bs_currRangeStart = heapBlk; + heapNumBlks = RelationGetNumberOfBlocks(heapRel); + 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); /*
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers