From d7b6fe50c4af123051d7ba48a0a0b6eda208a1bb Mon Sep 17 00:00:00 2001 From: Melanie Plageman Date: Thu, 17 Oct 2024 15:51:24 -0400 Subject: [PATCH v25 01/11] Remove unused rs_cindex condition in heap AM bitmap callback HeapScanDescData.rs_cindex can't be less than 0 for bitmap heap scans. Remove this test from heapam_scan_bitmap_next_tuple() and add an assertion to ensure this stays true. Also initialize HeapScanDescData.rs_cindex to 0 in initscan(). Author: Melanie Plageman --- src/backend/access/heap/heapam.c | 1 + src/backend/access/heap/heapam_handler.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index da5e656a08d..cbc5f62aff6 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -378,6 +378,7 @@ initscan(HeapScanDesc scan, ScanKey key, bool keep_startblock) ItemPointerSetInvalid(&scan->rs_ctup.t_self); scan->rs_cbuf = InvalidBuffer; scan->rs_cblock = InvalidBlockNumber; + scan->rs_cindex = 0; /* * Initialize to ForwardScanDirection because it is most common and diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c index 8c59b77b64f..bdb7599684b 100644 --- a/src/backend/access/heap/heapam_handler.c +++ b/src/backend/access/heap/heapam_handler.c @@ -2269,7 +2269,8 @@ heapam_scan_bitmap_next_tuple(TableScanDesc scan, /* * Out of range? If so, nothing more to look at on this page */ - if (hscan->rs_cindex < 0 || hscan->rs_cindex >= hscan->rs_ntuples) + Assert(hscan->rs_cindex >= 0); + if (hscan->rs_cindex >= hscan->rs_ntuples) return false; targoffset = hscan->rs_vistuples[hscan->rs_cindex]; -- 2.45.2