Re: BitmapHeapScan streaming read user and prelim refactoring
Melanie Plageman <melanieplageman@gmail.com>
Attachments
- v24-0001-table_scan_bitmap_next_block-implementations-cou.patch (application/octet-stream) patch v24-0001
- v24-0002-Remove-table_scan_bitmap_next_tuple-parameter-tb.patch (application/octet-stream) patch v24-0002
- v24-0004-Add-common-interface-for-TBMIterators.patch (application/octet-stream) patch v24-0004
- v24-0003-Make-table_scan_bitmap_next_block-async-friendly.patch (application/octet-stream) patch v24-0003
- v24-0005-Bitmap-Table-Scans-use-unified-TBMIterator.patch (application/octet-stream) patch v24-0005
- v24-0008-Lift-and-Shift-Bitmap-Table-Scan-prefetch-functi.patch (application/octet-stream) patch v24-0008
- v24-0007-Add-and-use-BitmapHeapScanDesc-struct.patch (application/octet-stream) patch v24-0007
- v24-0010-Move-BitmapTableScan-per-scan-setup-into-a-helpe.patch (application/octet-stream) patch v24-0010
- v24-0009-Push-Bitmap-Table-Scan-prefetch-code-into-heap-A.patch (application/octet-stream) patch v24-0009
- v24-0011-Remove-table-AM-callback-scan_bitmap_next_block.patch (application/octet-stream) patch v24-0011
- v24-0012-Move-BitmapHeapScanNextBlock-next-to-other-helpe.patch (application/octet-stream) patch v24-0012
- v24-0006-Make-Bitmap-Table-Scan-prefetch-sync-error-more-.patch (application/octet-stream) patch v24-0006
On Mon, Aug 26, 2024 at 9:37 AM Heikki Linnakangas <hlinnaka@iki.fi> wrote:
>
> v23-0003-Make-table_scan_bitmap_next_block-async-friendly.patch
>
> > @@ -1955,19 +1954,26 @@ table_relation_estimate_size(Relation rel, int32 *attr_widths
>>
> > + * `blockno` is only used in bitmap table scan code to validate that the
> > + * prefetch block is staying ahead of the current block.
> > *
> > * Note, this is an optionally implemented function, therefore should only be
> > * used after verifying the presence (at plan time or such).
> > */
> > static inline bool
> > table_scan_bitmap_next_block(TableScanDesc scan,
> > - struct TBMIterateResult *tbmres,
> > + BlockNumber *blockno, bool *recheck,
> > long *lossy_pages,
> > long *exact_pages)
> > {
>
> The new comment doesn't really explain what *blockno means. Is it an
> input or output parameter? How is it used with the prefetching?
I've updated this comment.
> v23-0004-Add-common-interface-for-TBMIterators.patch
>
> > +void
> > +tbm_begin_iterate(TBMIterator *iterator, TIDBitmap *tbm,
> > + dsa_area *dsa, dsa_pointer dsp)
> > +{
> > + Assert(iterator);
> > +
> > + iterator->private_iterator = NULL;
> > + iterator->shared_iterator = NULL;
> > + iterator->exhausted = false;
> > +
> > + /* Allocate a private iterator and attach the shared state to it */
> > + if (DsaPointerIsValid(dsp))
> > + iterator->shared_iterator = tbm_attach_shared_iterate(dsa, dsp);
> > + else
> > + iterator->private_iterator = tbm_begin_private_iterate(tbm);
> > +}
>
> Hmm, I haven't looked at how this is used the later patches, but a
> function signature where some parameters are used or not depending on
> the situation seems a bit awkward. Perhaps it would be better to let the
> caller call tbm_attach_shared_iterate(dsa, dsp) or
> tbm_begin_private_iterate(tbm), and provide a function to turn that into
> a TBMIterator? Something like:
>
> TBMIterator *tbm_iterator_from_shared_iterator(TBMSharedIterator *);
> TBMIterator *tbm_iterator_from_private_iterator(TBMPrivateIterator *);
I thought about this a lot. I've changed the struct a bit but have
left the tbm_begin_iterate() interface mostly the same. I actually
think having some parameters that are used only for parallel and some
only for serial is better than exposing the private/shared versions of
the iterators only for tbm_begin_iterate() (which I would have to do
if the caller calls
tbm_attach_shared_iterate()/tbm_begin_private_iterate() directly).
> Does tbm_iterator() really need the 'exhausted' flag? The private and
> shared variants work without one.
I got rid of this.
> v23-0006-BitmapHeapScan-uses-unified-iterator.patch
>
> Makes sense. (Might be better to squash this with the previous patch)
Done.
> v23-0008-Push-current-scan-descriptor-into-specialized-sc.patch
> v23-0009-Remove-ss_current-prefix-from-ss_currentScanDesc.patch
>
> LGTM. I would squash these together.
I wanted to make a change that was lower impact than a new top level
scan descriptor. So, I made a few changes to the design to allow that.
Those rendered v23-0008 and v23-0009 moot.
See v24-0003 and v24-0007 for the new design. I could use input on
whether or not this strategy seems acceptable.
> v23-0010-Add-scan_in_progress-to-BitmapHeapScanState.patch
>
> > --- a/src/include/nodes/execnodes.h
> > +++ b/src/include/nodes/execnodes.h
> > @@ -1804,6 +1804,7 @@ typedef struct ParallelBitmapHeapState
> > * prefetch_target current target prefetch distance
> > * prefetch_maximum maximum value for prefetch_target
> > * initialized is node is ready to iterate
> > + * scan_in_progress is this a rescan
> > * pstate shared state for parallel bitmap scan
> > * recheck do current page's tuples need recheck
> > * blockno used to validate pf and current block in sync
> > @@ -1824,6 +1825,7 @@ typedef struct BitmapHeapScanState
> > int prefetch_target;
> > int prefetch_maximum;
> > bool initialized;
> > + bool scan_in_progress;
> > ParallelBitmapHeapState *pstate;
> > bool recheck;
> > BlockNumber blockno;
>
> Hmm, the "is this a rescan" comment sounds inaccurate, because it is set
> as soon as the scan is started, not only when rescanning. Other than
> that, LGTM.
It turns out I didn't need scan_in_progress once I rearranged some
things anyway.
- Melanie
Commits
-
Fix bitmapheapscan incorrect recheck of NULL tuples
- aea916fe555a 18.0 landed
-
Increase default maintenance_io_concurrency to 16
- cc6be07ebde2 18.0 landed
-
Separate TBM[Shared|Private]Iterator and TBMIterateResult
- 944e81bf99db 18.0 landed
-
Improve read_stream.c advice for dense streams.
- 7ea8cd15661e 18.0 landed
-
Increase default effective_io_concurrency to 16
- ff79b5b2aba0 18.0 landed
-
Delay extraction of TIDBitmap per page offsets
- bfe56cdf9a4e 18.0 landed
-
Add lossy indicator to TBMIterateResult
- b8778c4cd8bc 18.0 landed
-
Move BitmapTableScan per-scan setup into a helper
- a5358c14b2fe 18.0 landed
-
Add and use BitmapHeapScanDescData struct
- f7a8fc10ccb8 18.0 landed
-
Fix bitmap table scan crash on iterator release
- 754c610e13b8 18.0 landed
-
Bitmap Table Scans use unified TBMIterator
- 1a0da347a7ac 18.0 landed
-
Add common interface for TBMIterators
- 7f9d4187e7ba 18.0 landed
-
Make table_scan_bitmap_next_block() async-friendly
- de380a62b5da 18.0 landed
-
Move EXPLAIN counter increment to heapam_scan_bitmap_next_block
- 7bd7aa4d3067 18.0 landed
-
Refactor tidstore.c iterator buffering.
- f6bef362cac8 18.0 cited
-
BitmapHeapScan: Remove incorrect assert and reset field
- a3e6c6f92991 17.0 landed
-
Change BitmapAdjustPrefetchIterator to accept BlockNumber
- 92641d8d651e 17.0 landed
-
BitmapHeapScan: Use correct recheck flag for skip_fetch
- 1fdb0ce9b109 17.0 landed
-
BitmapHeapScan: Push skip_fetch optimization into table AM
- 04e72ed617be 17.0 landed
-
BitmapHeapScan: postpone setting can_skip_fetch
- fe1431e39cdd 17.0 landed
-
BitmapHeapScan: begin scan after bitmap creation
- 1577081e9614 17.0 landed
-
Fix EXPLAIN Bitmap heap scan to count pages with no visible tuples
- f3e4581acdc8 12.19 landed
- 992189a3e94d 13.15 landed
- 262757b73286 14.12 landed
- d3d95f583995 15.7 landed
- 1f4eb734200a 16.3 landed
- 0960ae1967d0 17.0 landed
-
Remove redundant snapshot copying from parallel leader to workers
- 84c18acaf690 17.0 landed
-
Remove some obsolete smgrcloseall() calls.
- 6a8ffe812d19 17.0 cited
-
Remove the "snapshot too old" feature.
- f691f5b80a85 17.0 cited
-
Compute XID horizon for page level index vacuum on primary.
- 558a9165e081 12.0 cited