Re: BitmapHeapScan streaming read user and prelim refactoring

Melanie Plageman <melanieplageman@gmail.com>

From: Melanie Plageman <melanieplageman@gmail.com>
To: Tomas Vondra <tomas@vondra.me>
Cc: Nazir Bilal Yavuz <byavuz81@gmail.com>, Dilip Kumar <dilipbalaut@gmail.com>, Heikki Linnakangas <hlinnaka@iki.fi>, Thomas Munro <thomas.munro@gmail.com>, Andres Freund <andres@anarazel.de>, Pg Hackers <pgsql-hackers@postgresql.org>
Date: 2025-02-13T16:52:13Z
Lists: pgsql-hackers
On Thu, Feb 13, 2025 at 11:28 AM Tomas Vondra <tomas@vondra.me> wrote:
>
> On 2/13/25 17:01, Melanie Plageman wrote:
> > On Thu, Feb 13, 2025 at 10:46 AM Tomas Vondra <tomas@vondra.me> wrote:
> >>
> >> I reviewed v29 today, and I think it's pretty much ready to go.
> >>
> >> The one part where I don't quite get is 0001, which replaces a
> >> FLEXIBLE_ARRAY_MEMBER array with a fixed-length array. It's not wrong,
> >> but I don't quite see the benefits / clarity. And I think Thomas might
> >> be right we may want to make this dynamic, to save memory.
> >>
> >> Not a blocker, but I'd probably skip 0001 (unless it's required by the
> >> later parts, I haven't checked/tried).
> >
> > So, on master, it already pallocs an array of size MAX_TUPLES_PER_PAGE
> > (which is hard-coded in the tidbitmap API to MaxHeapTuplesPerPage) --
> > see tbm_begin_private_iterate().
> >
> > So we always palloc the same amount of memory. The reason I changed it
> > from a flexible sized array to a fixed size is that we weren't using
> > the flexibility and having a flexible sized array in the
> > TBMIterateResult meant it couldn't be nested in another struct. Since
> > I have to separate the TBMIterateResult and TBMIterator to implement
> > the read stream API for BHS, once I separate them, I nest the
> > TBMIterateResult in the GinScanEntry. If the array of offsets is
> > flexible sized, then I would have to manage that memory separately in
> > GIN code for the TBMIterateResult..
> >
> > So, 0001 isn't a change in the amount of memory allocated.
> >
> > With the read stream API, these TBMIterateResults are palloc'd just
> > like we palloc'd one in master. However, we have to have more than one
> > at a time.
> >
>
> I know it's not changing how much memory we allocate (compared to
> master). I haven't thought about the GinScanEntry - yes, flexible array
> member would make this a bit more complex.

Oh, I see. I didn't understand Thomas' proposal. I don't know how hard
it would be to make tidbitmap allocate the offsets on-demand. I'd need
to investigate more. But probably not worth it for this patch.

- Melanie



Commits

  1. Fix bitmapheapscan incorrect recheck of NULL tuples

  2. Increase default maintenance_io_concurrency to 16

  3. Separate TBM[Shared|Private]Iterator and TBMIterateResult

  4. Improve read_stream.c advice for dense streams.

  5. Increase default effective_io_concurrency to 16

  6. Delay extraction of TIDBitmap per page offsets

  7. Add lossy indicator to TBMIterateResult

  8. Move BitmapTableScan per-scan setup into a helper

  9. Add and use BitmapHeapScanDescData struct

  10. Fix bitmap table scan crash on iterator release

  11. Bitmap Table Scans use unified TBMIterator

  12. Add common interface for TBMIterators

  13. Make table_scan_bitmap_next_block() async-friendly

  14. Move EXPLAIN counter increment to heapam_scan_bitmap_next_block

  15. Refactor tidstore.c iterator buffering.

  16. BitmapHeapScan: Remove incorrect assert and reset field

  17. Change BitmapAdjustPrefetchIterator to accept BlockNumber

  18. BitmapHeapScan: Use correct recheck flag for skip_fetch

  19. BitmapHeapScan: Push skip_fetch optimization into table AM

  20. BitmapHeapScan: postpone setting can_skip_fetch

  21. BitmapHeapScan: begin scan after bitmap creation

  22. Fix EXPLAIN Bitmap heap scan to count pages with no visible tuples

  23. Remove redundant snapshot copying from parallel leader to workers

  24. Remove some obsolete smgrcloseall() calls.

  25. Remove the "snapshot too old" feature.

  26. Compute XID horizon for page level index vacuum on primary.