aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access
diff options
context:
space:
mode:
authorMelanie Plageman <melanieplageman@gmail.com>2025-03-15 10:10:51 -0400
committerMelanie Plageman <melanieplageman@gmail.com>2025-03-15 10:11:19 -0400
commit944e81bf99db2b5b70b8a389d4f273534da73f74 (patch)
treeaef5b3e8d864fcdccc81ea1688b7a1ab8e7fbdf1 /src/backend/access
parent799959dc7cf0e2462601bea8d07b6edec3fa0c4f (diff)
downloadpostgresql-944e81bf99db2b5b70b8a389d4f273534da73f74.tar.gz
postgresql-944e81bf99db2b5b70b8a389d4f273534da73f74.zip
Separate TBM[Shared|Private]Iterator and TBMIterateResult
Remove the TBMIterateResult member from the TBMPrivateIterator and TBMSharedIterator and make tbm_[shared|private_]iterate() take a TBMIterateResult as a parameter. This allows tidbitmap API users to manage multiple TBMIterateResults per scan. This is required for bitmap heap scan to use the read stream API, with which there may be multiple I/Os in flight at once, each one with a TBMIterateResult. Reviewed-by: Tomas Vondra <tomas@vondra.me> Discussion: https://postgr.es/m/d4bb26c9-fe07-439e-ac53-c0e244387e01%40vondra.me
Diffstat (limited to 'src/backend/access')
-rw-r--r--src/backend/access/gin/ginget.c33
-rw-r--r--src/backend/access/gin/ginscan.c2
-rw-r--r--src/backend/access/heap/heapam_handler.c28
3 files changed, 30 insertions, 33 deletions
diff --git a/src/backend/access/gin/ginget.c b/src/backend/access/gin/ginget.c
index 4a56f19390d..f29ccd3c2d1 100644
--- a/src/backend/access/gin/ginget.c
+++ b/src/backend/access/gin/ginget.c
@@ -332,8 +332,8 @@ restartScanEntry:
entry->list = NULL;
entry->nlist = 0;
entry->matchBitmap = NULL;
- entry->matchResult = NULL;
entry->matchNtuples = -1;
+ entry->matchResult.blockno = InvalidBlockNumber;
entry->reduceResult = false;
entry->predictNumberResult = 0;
@@ -827,20 +827,19 @@ entryGetItem(GinState *ginstate, GinScanEntry entry,
{
/*
* If we've exhausted all items on this block, move to next block
- * in the bitmap.
+ * in the bitmap. tbm_private_iterate() sets matchResult.blockno
+ * to InvalidBlockNumber when the bitmap is exhausted.
*/
- while (entry->matchResult == NULL ||
- (!entry->matchResult->lossy &&
+ while ((!BlockNumberIsValid(entry->matchResult.blockno)) ||
+ (!entry->matchResult.lossy &&
entry->offset >= entry->matchNtuples) ||
- entry->matchResult->blockno < advancePastBlk ||
+ entry->matchResult.blockno < advancePastBlk ||
(ItemPointerIsLossyPage(&advancePast) &&
- entry->matchResult->blockno == advancePastBlk))
+ entry->matchResult.blockno == advancePastBlk))
{
- entry->matchResult =
- tbm_private_iterate(entry->matchIterator);
-
- if (entry->matchResult == NULL)
+ if (!tbm_private_iterate(entry->matchIterator, &entry->matchResult))
{
+ Assert(!BlockNumberIsValid(entry->matchResult.blockno));
ItemPointerSetInvalid(&entry->curItem);
tbm_end_private_iterate(entry->matchIterator);
entry->matchIterator = NULL;
@@ -849,14 +848,14 @@ entryGetItem(GinState *ginstate, GinScanEntry entry,
}
/* Exact pages need their tuple offsets extracted. */
- if (!entry->matchResult->lossy)
- entry->matchNtuples = tbm_extract_page_tuple(entry->matchResult,
+ if (!entry->matchResult.lossy)
+ entry->matchNtuples = tbm_extract_page_tuple(&entry->matchResult,
entry->matchOffsets,
TBM_MAX_TUPLES_PER_PAGE);
/*
* Reset counter to the beginning of entry->matchResult. Note:
- * entry->offset is still greater than entry->matchNtuples if
+ * entry->offset is still greater than matchResult.ntuples if
* matchResult is lossy. So, on next call we will get next
* result from TIDBitmap.
*/
@@ -869,10 +868,10 @@ entryGetItem(GinState *ginstate, GinScanEntry entry,
* We're now on the first page after advancePast which has any
* items on it. If it's a lossy result, return that.
*/
- if (entry->matchResult->lossy)
+ if (entry->matchResult.lossy)
{
ItemPointerSetLossyPage(&entry->curItem,
- entry->matchResult->blockno);
+ entry->matchResult.blockno);
/*
* We might as well fall out of the loop; we could not
@@ -889,7 +888,7 @@ entryGetItem(GinState *ginstate, GinScanEntry entry,
Assert(entry->matchNtuples > -1);
/* Skip over any offsets <= advancePast, and return that. */
- if (entry->matchResult->blockno == advancePastBlk)
+ if (entry->matchResult.blockno == advancePastBlk)
{
Assert(entry->matchNtuples > 0);
@@ -910,7 +909,7 @@ entryGetItem(GinState *ginstate, GinScanEntry entry,
}
ItemPointerSet(&entry->curItem,
- entry->matchResult->blockno,
+ entry->matchResult.blockno,
entry->matchOffsets[entry->offset]);
entry->offset++;
diff --git a/src/backend/access/gin/ginscan.c b/src/backend/access/gin/ginscan.c
index f6cdd098a02..c2d1771bd77 100644
--- a/src/backend/access/gin/ginscan.c
+++ b/src/backend/access/gin/ginscan.c
@@ -111,7 +111,7 @@ ginFillScanEntry(GinScanOpaque so, OffsetNumber attnum,
ItemPointerSetMin(&scanEntry->curItem);
scanEntry->matchBitmap = NULL;
scanEntry->matchIterator = NULL;
- scanEntry->matchResult = NULL;
+ scanEntry->matchResult.blockno = InvalidBlockNumber;
scanEntry->matchNtuples = -1;
scanEntry->list = NULL;
scanEntry->nlist = 0;
diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index eecff8ffd67..25d26409e2c 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -2126,7 +2126,7 @@ heapam_scan_bitmap_next_block(TableScanDesc scan,
Buffer buffer;
Snapshot snapshot;
int ntup;
- TBMIterateResult *tbmres;
+ TBMIterateResult tbmres;
OffsetNumber offsets[TBM_MAX_TUPLES_PER_PAGE];
int noffsets = -1;
@@ -2142,14 +2142,12 @@ heapam_scan_bitmap_next_block(TableScanDesc scan,
{
CHECK_FOR_INTERRUPTS();
- tbmres = tbm_iterate(&scan->st.rs_tbmiterator);
-
- if (tbmres == NULL)
+ if (!tbm_iterate(&scan->st.rs_tbmiterator, &tbmres))
return false;
/* Exact pages need their tuple offsets extracted. */
- if (!tbmres->lossy)
- noffsets = tbm_extract_page_tuple(tbmres, offsets,
+ if (!tbmres.lossy)
+ noffsets = tbm_extract_page_tuple(&tbmres, offsets,
TBM_MAX_TUPLES_PER_PAGE);
/*
@@ -2161,11 +2159,11 @@ heapam_scan_bitmap_next_block(TableScanDesc scan,
* reachable by the index.
*/
} while (!IsolationIsSerializable() &&
- tbmres->blockno >= hscan->rs_nblocks);
+ tbmres.blockno >= hscan->rs_nblocks);
/* Got a valid block */
- *blockno = tbmres->blockno;
- *recheck = tbmres->recheck;
+ *blockno = tbmres.blockno;
+ *recheck = tbmres.recheck;
/*
* We can skip fetching the heap page if we don't need any fields from the
@@ -2173,11 +2171,11 @@ heapam_scan_bitmap_next_block(TableScanDesc scan,
* page are visible to our transaction.
*/
if (!(scan->rs_flags & SO_NEED_TUPLES) &&
- !tbmres->recheck &&
- VM_ALL_VISIBLE(scan->rs_rd, tbmres->blockno, &bscan->rs_vmbuffer))
+ !tbmres.recheck &&
+ VM_ALL_VISIBLE(scan->rs_rd, tbmres.blockno, &bscan->rs_vmbuffer))
{
/* can't be lossy in the skip_fetch case */
- Assert(!tbmres->lossy);
+ Assert(!tbmres.lossy);
Assert(bscan->rs_empty_tuples_pending >= 0);
Assert(noffsets > -1);
@@ -2186,7 +2184,7 @@ heapam_scan_bitmap_next_block(TableScanDesc scan,
return true;
}
- block = tbmres->blockno;
+ block = tbmres.blockno;
/*
* Acquire pin on the target heap page, trading in any pin we held before.
@@ -2215,7 +2213,7 @@ heapam_scan_bitmap_next_block(TableScanDesc scan,
/*
* We need two separate strategies for lossy and non-lossy cases.
*/
- if (!tbmres->lossy)
+ if (!tbmres.lossy)
{
/*
* Bitmap is non-lossy, so we just look through the offsets listed in
@@ -2279,7 +2277,7 @@ heapam_scan_bitmap_next_block(TableScanDesc scan,
Assert(ntup <= MaxHeapTuplesPerPage);
hscan->rs_ntuples = ntup;
- if (tbmres->lossy)
+ if (tbmres.lossy)
(*lossy_pages)++;
else
(*exact_pages)++;