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

Commitde380a6

Browse files
Make table_scan_bitmap_next_block() async-friendly
Move all responsibility for indicating a block is exhuasted intotable_scan_bitmap_next_tuple() and advance the main iterator inheap-specific code. This flow control makes more sense and is a steptoward using the read stream API for bitmap heap scans.Previously, table_scan_bitmap_next_block() returned false to indicatetable_scan_bitmap_next_tuple() should not be called for the tuples onthe page. This happened both when 1) there were no visible tuples on thepage and 2) when the block returned by the iterator was past the end ofthe table. BitmapHeapNext() (generic bitmap table scan code) handled thecase when the bitmap was exhausted.It makes more sense for table_scan_bitmap_next_tuple() to return falsewhen there are no visible tuples on the page andtable_scan_bitmap_next_block() to return false when the bitmap isexhausted or there are no more blocks in the table.As part of this new design, TBMIterateResults are no longer used as aflow control mechanism in BitmapHeapNext(), so we removedtable_scan_bitmap_next_tuple's TBMIterateResult parameter.Note that the prefetch iterator is still saved in theBitmapHeapScanState node and advanced in generic bitmap table scan code.This is because 1) it was not necessary to change the prefetch iteratorlocation to change the flow control in BitmapHeapNext() 2) modifyingprefetch iterator management requires several more steps better splitover multiple commits and 3) the prefetch iterator will be removed oncethe read stream API is used.Author: Melanie PlagemanReviewed-by: Tomas Vondra, Andres Freund, Heikki Linnakangas, Mark DilgerDiscussion:https://postgr.es/m/063e4eb4-32d9-439e-a0b1-75565a9835a8%40iki.fi
1 parent7bd7aa4 commitde380a6

File tree

6 files changed

+252
-162
lines changed

6 files changed

+252
-162
lines changed

‎src/backend/access/heap/heapam.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,17 +1387,17 @@ heap_set_tidrange(TableScanDesc sscan, ItemPointer mintid,
13871387
heap_setscanlimits(sscan,startBlk,numBlks);
13881388

13891389
/* Finally, set the TID range in sscan */
1390-
ItemPointerCopy(&lowestItem,&sscan->rs_mintid);
1391-
ItemPointerCopy(&highestItem,&sscan->rs_maxtid);
1390+
ItemPointerCopy(&lowestItem,&sscan->st.tidrange.rs_mintid);
1391+
ItemPointerCopy(&highestItem,&sscan->st.tidrange.rs_maxtid);
13921392
}
13931393

13941394
bool
13951395
heap_getnextslot_tidrange(TableScanDescsscan,ScanDirectiondirection,
13961396
TupleTableSlot*slot)
13971397
{
13981398
HeapScanDescscan= (HeapScanDesc)sscan;
1399-
ItemPointermintid=&sscan->rs_mintid;
1400-
ItemPointermaxtid=&sscan->rs_maxtid;
1399+
ItemPointermintid=&sscan->st.tidrange.rs_mintid;
1400+
ItemPointermaxtid=&sscan->st.tidrange.rs_maxtid;
14011401

14021402
/* Note: no locking manipulations needed */
14031403
for (;;)

‎src/backend/access/heap/heapam_handler.c

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2115,18 +2115,49 @@ heapam_estimate_rel_size(Relation rel, int32 *attr_widths,
21152115

21162116
staticbool
21172117
heapam_scan_bitmap_next_block(TableScanDescscan,
2118-
TBMIterateResult*tbmres,
2118+
BlockNumber*blockno,bool*recheck,
21192119
uint64*lossy_pages,uint64*exact_pages)
21202120
{
21212121
HeapScanDeschscan= (HeapScanDesc)scan;
2122-
BlockNumberblock=tbmres->blockno;
2122+
BlockNumberblock;
21232123
Bufferbuffer;
21242124
Snapshotsnapshot;
21252125
intntup;
2126+
TBMIterateResult*tbmres;
21262127

21272128
hscan->rs_cindex=0;
21282129
hscan->rs_ntuples=0;
21292130

2131+
*blockno=InvalidBlockNumber;
2132+
*recheck= true;
2133+
2134+
do
2135+
{
2136+
CHECK_FOR_INTERRUPTS();
2137+
2138+
if (scan->st.bitmap.rs_shared_iterator)
2139+
tbmres=tbm_shared_iterate(scan->st.bitmap.rs_shared_iterator);
2140+
else
2141+
tbmres=tbm_iterate(scan->st.bitmap.rs_iterator);
2142+
2143+
if (tbmres==NULL)
2144+
return false;
2145+
2146+
/*
2147+
* Ignore any claimed entries past what we think is the end of the
2148+
* relation. It may have been extended after the start of our scan (we
2149+
* only hold an AccessShareLock, and it could be inserts from this
2150+
* backend). We don't take this optimization in SERIALIZABLE
2151+
* isolation though, as we need to examine all invisible tuples
2152+
* reachable by the index.
2153+
*/
2154+
}while (!IsolationIsSerializable()&&
2155+
tbmres->blockno >=hscan->rs_nblocks);
2156+
2157+
/* Got a valid block */
2158+
*blockno=tbmres->blockno;
2159+
*recheck=tbmres->recheck;
2160+
21302161
/*
21312162
* We can skip fetching the heap page if we don't need any fields from the
21322163
* heap, the bitmap entries don't need rechecking, and all tuples on the
@@ -2145,16 +2176,7 @@ heapam_scan_bitmap_next_block(TableScanDesc scan,
21452176
return true;
21462177
}
21472178

2148-
/*
2149-
* Ignore any claimed entries past what we think is the end of the
2150-
* relation. It may have been extended after the start of our scan (we
2151-
* only hold an AccessShareLock, and it could be inserts from this
2152-
* backend). We don't take this optimization in SERIALIZABLE isolation
2153-
* though, as we need to examine all invisible tuples reachable by the
2154-
* index.
2155-
*/
2156-
if (!IsolationIsSerializable()&&block >=hscan->rs_nblocks)
2157-
return false;
2179+
block=tbmres->blockno;
21582180

21592181
/*
21602182
* Acquire pin on the target heap page, trading in any pin we held before.
@@ -2249,12 +2271,18 @@ heapam_scan_bitmap_next_block(TableScanDesc scan,
22492271
else
22502272
(*lossy_pages)++;
22512273

2252-
returnntup>0;
2274+
/*
2275+
* Return true to indicate that a valid block was found and the bitmap is
2276+
* not exhausted. If there are no visible tuples on this page,
2277+
* hscan->rs_ntuples will be 0 and heapam_scan_bitmap_next_tuple() will
2278+
* return false returning control to this function to advance to the next
2279+
* block in the bitmap.
2280+
*/
2281+
return true;
22532282
}
22542283

22552284
staticbool
22562285
heapam_scan_bitmap_next_tuple(TableScanDescscan,
2257-
TBMIterateResult*tbmres,
22582286
TupleTableSlot*slot)
22592287
{
22602288
HeapScanDeschscan= (HeapScanDesc)scan;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp