Skip to content

Commit b8778c4

Browse files
Add lossy indicator to TBMIterateResult
TBMIterateResult->ntuples is -1 when the page in the bitmap is lossy. Add an explicit lossy indicator so that we can move ntuples out of the TBMIterateResult in a future commit. Discussion: https://postgr.es/m/CA%2BhUKGLHbKP3jwJ6_%2BhnGi37Pw3BD5j2amjV3oSk7j-KyCnY7Q%40mail.gmail.com
1 parent c56e8af commit b8778c4

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

src/backend/access/gin/ginget.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ entryGetItem(GinState *ginstate, GinScanEntry entry,
827827
* in the bitmap.
828828
*/
829829
while (entry->matchResult == NULL ||
830-
(entry->matchResult->ntuples >= 0 &&
830+
(!entry->matchResult->lossy &&
831831
entry->offset >= entry->matchResult->ntuples) ||
832832
entry->matchResult->blockno < advancePastBlk ||
833833
(ItemPointerIsLossyPage(&advancePast) &&
@@ -860,7 +860,7 @@ entryGetItem(GinState *ginstate, GinScanEntry entry,
860860
* We're now on the first page after advancePast which has any
861861
* items on it. If it's a lossy result, return that.
862862
*/
863-
if (entry->matchResult->ntuples < 0)
863+
if (entry->matchResult->lossy)
864864
{
865865
ItemPointerSetLossyPage(&entry->curItem,
866866
entry->matchResult->blockno);
@@ -879,6 +879,8 @@ entryGetItem(GinState *ginstate, GinScanEntry entry,
879879
*/
880880
if (entry->matchResult->blockno == advancePastBlk)
881881
{
882+
Assert(entry->matchResult->ntuples > 0);
883+
882884
/*
883885
* First, do a quick check against the last offset on the
884886
* page. If that's > advancePast, so are all the other

src/backend/access/heap/heapam_handler.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,7 +2170,7 @@ heapam_scan_bitmap_next_block(TableScanDesc scan,
21702170
VM_ALL_VISIBLE(scan->rs_rd, tbmres->blockno, &bscan->rs_vmbuffer))
21712171
{
21722172
/* can't be lossy in the skip_fetch case */
2173-
Assert(tbmres->ntuples >= 0);
2173+
Assert(!tbmres->lossy);
21742174
Assert(bscan->rs_empty_tuples_pending >= 0);
21752175

21762176
bscan->rs_empty_tuples_pending += tbmres->ntuples;
@@ -2207,7 +2207,7 @@ heapam_scan_bitmap_next_block(TableScanDesc scan,
22072207
/*
22082208
* We need two separate strategies for lossy and non-lossy cases.
22092209
*/
2210-
if (tbmres->ntuples >= 0)
2210+
if (!tbmres->lossy)
22112211
{
22122212
/*
22132213
* Bitmap is non-lossy, so we just look through the offsets listed in
@@ -2268,10 +2268,10 @@ heapam_scan_bitmap_next_block(TableScanDesc scan,
22682268
Assert(ntup <= MaxHeapTuplesPerPage);
22692269
hscan->rs_ntuples = ntup;
22702270

2271-
if (tbmres->ntuples >= 0)
2272-
(*exact_pages)++;
2273-
else
2271+
if (tbmres->lossy)
22742272
(*lossy_pages)++;
2273+
else
2274+
(*exact_pages)++;
22752275

22762276
/*
22772277
* Return true to indicate that a valid block was found and the bitmap is

src/backend/nodes/tidbitmap.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -961,12 +961,13 @@ tbm_advance_schunkbit(PagetableEntry *chunk, int *schunkbitp)
961961
*
962962
* Returns a TBMIterateResult representing one page, or NULL if there are
963963
* no more pages to scan. Pages are guaranteed to be delivered in numerical
964-
* order. If result->ntuples < 0, then the bitmap is "lossy" and failed to
964+
* order. If lossy is true, then the bitmap is "lossy" and failed to
965965
* remember the exact tuples to look at on this page --- the caller must
966966
* examine all tuples on the page and check if they meet the intended
967-
* condition. If result->recheck is true, only the indicated tuples need
967+
* condition. result->ntuples is set to -1 when the bitmap is lossy.
968+
* If result->recheck is true, only the indicated tuples need
968969
* be examined, but the condition must be rechecked anyway. (For ease of
969-
* testing, recheck is always set true when ntuples < 0.)
970+
* testing, recheck is always set true when lossy is true.)
970971
*/
971972
TBMIterateResult *
972973
tbm_private_iterate(TBMPrivateIterator *iterator)
@@ -1012,6 +1013,7 @@ tbm_private_iterate(TBMPrivateIterator *iterator)
10121013
/* Return a lossy page indicator from the chunk */
10131014
output->blockno = chunk_blockno;
10141015
output->ntuples = -1;
1016+
output->lossy = true;
10151017
output->recheck = true;
10161018
iterator->schunkbit++;
10171019
return output;
@@ -1033,6 +1035,7 @@ tbm_private_iterate(TBMPrivateIterator *iterator)
10331035
ntuples = tbm_extract_page_tuple(page, output);
10341036
output->blockno = page->blockno;
10351037
output->ntuples = ntuples;
1038+
output->lossy = false;
10361039
output->recheck = page->recheck;
10371040
iterator->spageptr++;
10381041
return output;
@@ -1105,6 +1108,7 @@ tbm_shared_iterate(TBMSharedIterator *iterator)
11051108
/* Return a lossy page indicator from the chunk */
11061109
output->blockno = chunk_blockno;
11071110
output->ntuples = -1;
1111+
output->lossy = true;
11081112
output->recheck = true;
11091113
istate->schunkbit++;
11101114

@@ -1122,6 +1126,7 @@ tbm_shared_iterate(TBMSharedIterator *iterator)
11221126
ntuples = tbm_extract_page_tuple(page, output);
11231127
output->blockno = page->blockno;
11241128
output->ntuples = ntuples;
1129+
output->lossy = false;
11251130
output->recheck = page->recheck;
11261131
istate->spageptr++;
11271132

src/include/nodes/tidbitmap.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ typedef struct TBMIterator
5454
typedef struct TBMIterateResult
5555
{
5656
BlockNumber blockno; /* page number containing tuples */
57-
int ntuples; /* -1 indicates lossy result */
57+
int ntuples; /* -1 when lossy */
58+
bool lossy;
5859
bool recheck; /* should the tuples be rechecked? */
59-
/* Note: recheck is always true if ntuples < 0 */
60+
/* Note: recheck is always true if lossy */
6061
OffsetNumber offsets[FLEXIBLE_ARRAY_MEMBER];
6162
} TBMIterateResult;
6263

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy