/*
* allocate and initialize scan descriptor
*/
- scan = (HeapScanDesc) palloc(sizeof(HeapScanDescData));
+ if (flags & SO_TYPE_BITMAPSCAN)
+ {
+ BitmapHeapScanDesc bscan = palloc(sizeof(BitmapHeapScanDescData));
+
+ bscan->rs_vmbuffer = InvalidBuffer;
+ bscan->rs_empty_tuples_pending = 0;
+ scan = (HeapScanDesc) bscan;
+ }
+ else
+ scan = (HeapScanDesc) palloc(sizeof(HeapScanDescData));
scan->rs_base.rs_rd = relation;
scan->rs_base.rs_snapshot = snapshot;
scan->rs_base.rs_flags = flags;
scan->rs_base.rs_parallel = parallel_scan;
scan->rs_strategy = NULL; /* set in initscan */
- scan->rs_vmbuffer = InvalidBuffer;
- scan->rs_empty_tuples_pending = 0;
/*
* Disable page-at-a-time mode if it's not a MVCC-safe snapshot.
if (BufferIsValid(scan->rs_cbuf))
ReleaseBuffer(scan->rs_cbuf);
- if (BufferIsValid(scan->rs_vmbuffer))
+ if (scan->rs_base.rs_flags & SO_TYPE_BITMAPSCAN)
{
- ReleaseBuffer(scan->rs_vmbuffer);
- scan->rs_vmbuffer = InvalidBuffer;
- }
+ BitmapHeapScanDesc bscan = (BitmapHeapScanDesc) scan;
- /*
- * Reset rs_empty_tuples_pending, a field only used by bitmap heap scan,
- * to avoid incorrectly emitting NULL-filled tuples from a previous scan
- * on rescan.
- */
- scan->rs_empty_tuples_pending = 0;
+ /*
+ * Reset empty_tuples_pending, a field only used by bitmap heap scan,
+ * to avoid incorrectly emitting NULL-filled tuples from a previous
+ * scan on rescan.
+ */
+ bscan->rs_empty_tuples_pending = 0;
+
+ if (BufferIsValid(bscan->rs_vmbuffer))
+ {
+ ReleaseBuffer(bscan->rs_vmbuffer);
+ bscan->rs_vmbuffer = InvalidBuffer;
+ }
+ }
/*
* The read stream is reset on rescan. This must be done before
if (BufferIsValid(scan->rs_cbuf))
ReleaseBuffer(scan->rs_cbuf);
- if (BufferIsValid(scan->rs_vmbuffer))
- ReleaseBuffer(scan->rs_vmbuffer);
+ if (scan->rs_base.rs_flags & SO_TYPE_BITMAPSCAN)
+ {
+ BitmapHeapScanDesc bscan = (BitmapHeapScanDesc) sscan;
+
+ bscan->rs_empty_tuples_pending = 0;
+ if (BufferIsValid(bscan->rs_vmbuffer))
+ ReleaseBuffer(bscan->rs_vmbuffer);
+ }
/*
* Must free the read stream before freeing the BufferAccessStrategy.
BlockNumber *blockno, bool *recheck,
uint64 *lossy_pages, uint64 *exact_pages)
{
- HeapScanDesc hscan = (HeapScanDesc) scan;
+ BitmapHeapScanDesc bscan = (BitmapHeapScanDesc) scan;
+ HeapScanDesc hscan = (HeapScanDesc) bscan;
BlockNumber block;
Buffer buffer;
Snapshot snapshot;
int ntup;
TBMIterateResult *tbmres;
+ Assert(scan->rs_flags & SO_TYPE_BITMAPSCAN);
+
hscan->rs_cindex = 0;
hscan->rs_ntuples = 0;
*/
if (!(scan->rs_flags & SO_NEED_TUPLES) &&
!tbmres->recheck &&
- VM_ALL_VISIBLE(scan->rs_rd, tbmres->blockno, &hscan->rs_vmbuffer))
+ VM_ALL_VISIBLE(scan->rs_rd, tbmres->blockno, &bscan->rs_vmbuffer))
{
/* can't be lossy in the skip_fetch case */
Assert(tbmres->ntuples >= 0);
- Assert(hscan->rs_empty_tuples_pending >= 0);
+ Assert(bscan->rs_empty_tuples_pending >= 0);
- hscan->rs_empty_tuples_pending += tbmres->ntuples;
+ bscan->rs_empty_tuples_pending += tbmres->ntuples;
return true;
}
heapam_scan_bitmap_next_tuple(TableScanDesc scan,
TupleTableSlot *slot)
{
- HeapScanDesc hscan = (HeapScanDesc) scan;
+ BitmapHeapScanDesc bscan = (BitmapHeapScanDesc) scan;
+ HeapScanDesc hscan = (HeapScanDesc) bscan;
OffsetNumber targoffset;
Page page;
ItemId lp;
- if (hscan->rs_empty_tuples_pending > 0)
+ if (bscan->rs_empty_tuples_pending > 0)
{
/*
* If we don't have to fetch the tuple, just return nulls.
*/
ExecStoreAllNullTuple(slot);
- hscan->rs_empty_tuples_pending--;
+ bscan->rs_empty_tuples_pending--;
return true;
}
*/
ParallelBlockTableScanWorkerData *rs_parallelworkerdata;
+ /* these fields only used in page-at-a-time mode and for bitmap scans */
+ uint32 rs_cindex; /* current tuple's index in vistuples */
+ uint32 rs_ntuples; /* number of visible tuples on page */
+ OffsetNumber rs_vistuples[MaxHeapTuplesPerPage]; /* their offsets */
+} HeapScanDescData;
+typedef struct HeapScanDescData *HeapScanDesc;
+
+typedef struct BitmapHeapScanDescData
+{
+ HeapScanDescData rs_heap_base;
+
/*
* These fields are only used for bitmap scans for the "skip fetch"
* optimization. Bitmap scans needing no fields from the heap may skip
* fetching an all visible block, instead using the number of tuples per
* block reported by the bitmap to determine how many NULL-filled tuples
- * to return.
+ * to return. They are common to parallel and serial BitmapHeapScans
*/
+
+ /* page of VM containing info for current block */
Buffer rs_vmbuffer;
int rs_empty_tuples_pending;
-
- /* these fields only used in page-at-a-time mode and for bitmap scans */
- uint32 rs_cindex; /* current tuple's index in vistuples */
- uint32 rs_ntuples; /* number of visible tuples on page */
- OffsetNumber rs_vistuples[MaxHeapTuplesPerPage]; /* their offsets */
-} HeapScanDescData;
-typedef struct HeapScanDescData *HeapScanDesc;
+} BitmapHeapScanDescData;
+typedef struct BitmapHeapScanDescData *BitmapHeapScanDesc;
/*
* Descriptor for fetches from heap via an index.
BitmapHeapPath
BitmapHeapScan
BitmapHeapScanInstrumentation
+BitmapHeapScanDesc
BitmapHeapScanState
BitmapIndexScan
BitmapIndexScanState