diff options
author | Melanie Plageman <melanieplageman@gmail.com> | 2025-01-16 18:42:39 -0500 |
---|---|---|
committer | Melanie Plageman <melanieplageman@gmail.com> | 2025-01-16 18:42:39 -0500 |
commit | f7a8fc10ccb882249f8624b937f2c3b467d07bd6 (patch) | |
tree | 12853f752004fb0283206e30caa9cce4f970eb6c /src/backend/access/heap/heapam.c | |
parent | 7b6468cc9523d7d923487d212281af51f7f3dae2 (diff) | |
download | postgresql-f7a8fc10ccb882249f8624b937f2c3b467d07bd6.tar.gz postgresql-f7a8fc10ccb882249f8624b937f2c3b467d07bd6.zip |
Add and use BitmapHeapScanDescData struct
Move the several members of HeapScanDescData which are specific to
Bitmap Heap Scans into a new struct, BitmapHeapScanDescData, which
inherits from HeapScanDescData.
This reduces the size of the HeapScanDescData for other types of scans
and will allow us to add additional bitmap heap scan-specific members in
the future without fear of bloating the HeapScanDescData.
Reviewed-by: Tomas Vondra
Discussion: https://postgr.es/m/c736f6aa-8b35-4e20-9621-62c7c82e2168%40vondra.me
Diffstat (limited to 'src/backend/access/heap/heapam.c')
-rw-r--r-- | src/backend/access/heap/heapam.c | 48 |
1 files changed, 33 insertions, 15 deletions
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index 485525f4d64..b6349950294 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -1048,7 +1048,16 @@ heap_beginscan(Relation relation, Snapshot snapshot, /* * 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; @@ -1056,8 +1065,6 @@ heap_beginscan(Relation relation, 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. @@ -1173,18 +1180,23 @@ heap_rescan(TableScanDesc sscan, ScanKey key, bool set_params, 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 @@ -1213,8 +1225,14 @@ heap_endscan(TableScanDesc sscan) 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. |