Delay extraction of TIDBitmap per page offsets Pages from the bitmap created by the TIDBitmap API can be exact or lossy. The TIDBitmap API extracts the tuple offsets from exact pages into an array for the convenience of the caller.
This was done in tbm_private|shared_iterate() right after advancing the iterator. However, as long as tbm_private|shared_iterate() set a reference to the PagetableEntry in the TBMIterateResult, the offset extraction can be done later. Waiting to extract the tuple offsets has a few benefits. For the shared iterator case, it allows us to extract the offsets after dropping the shared iterator state lock, reducing time spent holding a contended lock. Separating the iteration step and extracting the offsets later also allows us to avoid extracting the offsets for prefetched blocks. Those offsets were never used, so the overhead of extracting and storing them was wasted. The real motivation for this change, however, is that future commits will make bitmap heap scan use the read stream API. This requires a TBMIterateResult per issued block. By removing the array of tuple offsets from the TBMIterateResult and only extracting the offsets when they are used, we reduce the memory required for per buffer data substantially. Suggested-by: Thomas Munro <thomas.mu...@gmail.com> Reviewed-by: Thomas Munro <thomas.mu...@gmail.com> Discussion: https://postgr.es/m/CA%2BhUKGLHbKP3jwJ6_%2BhnGi37Pw3BD5j2amjV3oSk7j-KyCnY7Q%40mail.gmail.com Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/bfe56cdf9a4e07edca46254a88efd9ef17421cd7 Modified Files -------------- src/backend/access/gin/ginget.c | 28 +++++++++++----- src/backend/access/gin/ginscan.c | 1 + src/backend/access/heap/heapam_handler.c | 17 ++++++++-- src/backend/nodes/tidbitmap.c | 57 ++++++++++++++------------------ src/include/access/gin_private.h | 2 ++ src/include/nodes/tidbitmap.h | 32 +++++++++++++++--- 6 files changed, 87 insertions(+), 50 deletions(-)