Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commiteea24eb

Browse files
committed
Fix BRIN 32-bit counter wrap issue with huge tables
A BlockNumber (32-bit) might not be large enough to add bo_pagesPerRangeto when the table contains close to 2^32 pages. At worst, this couldresult in a cancellable infinite loop during the BRIN index scan withpower-of-2 pagesPerRange, and slow (inefficient) BRIN index scans andscanning of unneeded heap blocks for non power-of-2 pagesPerRange.Backpatch to all supported versions.Author: sunil s <sunilfeb26@gmail.com>Reviewed-by: David Rowley <dgrowleyml@gmail.com>Reviewed-by: Michael Paquier <michael@paquier.xyz>Discussion:https://postgr.es/m/CAOG6S4-tGksTQhVzJM19NzLYAHusXsK2HmADPZzGQcfZABsvpA@mail.gmail.comBackpatch-through: 13
1 parent5274f11 commiteea24eb

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

‎src/backend/access/brin/brin.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,6 @@ bringetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
360360
RelationheapRel;
361361
BrinOpaque*opaque;
362362
BlockNumbernblocks;
363-
BlockNumberheapBlk;
364363
int64totalpages=0;
365364
FmgrInfo*consistentFn;
366365
MemoryContextoldcxt;
@@ -521,9 +520,10 @@ bringetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
521520
/*
522521
* Now scan the revmap. We start by querying for heap page 0,
523522
* incrementing by the number of pages per range; this gives us a full
524-
* view of the table.
523+
* view of the table. We make use of uint64 for heapBlk as a BlockNumber
524+
* could wrap for tables with close to 2^32 pages.
525525
*/
526-
for (heapBlk=0;heapBlk<nblocks;heapBlk+=opaque->bo_pagesPerRange)
526+
for (uint64heapBlk=0;heapBlk<nblocks;heapBlk+=opaque->bo_pagesPerRange)
527527
{
528528
booladdrange;
529529
boolgottuple= false;
@@ -535,7 +535,7 @@ bringetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
535535

536536
MemoryContextResetAndDeleteChildren(perRangeCxt);
537537

538-
tup=brinGetTupleForHeapBlock(opaque->bo_rmAccess,heapBlk,&buf,
538+
tup=brinGetTupleForHeapBlock(opaque->bo_rmAccess,(BlockNumber )heapBlk,&buf,
539539
&off,&size,BUFFER_LOCK_SHARE,
540540
scan->xs_snapshot);
541541
if (tup)
@@ -711,7 +711,7 @@ bringetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
711711
/* add the pages in the range to the output bitmap, if needed */
712712
if (addrange)
713713
{
714-
BlockNumberpageno;
714+
uint64pageno;
715715

716716
for (pageno=heapBlk;
717717
pageno <=Min(nblocks,heapBlk+opaque->bo_pagesPerRange)-1;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp