Re: Tid scan improvements
David Rowley <dgrowleyml@gmail.com>
From: David Rowley <dgrowleyml@gmail.com>
To: Andres Freund <andres@anarazel.de>
Cc: Edmund Horner <ejrh00@gmail.com>, David Fetter <david@fetter.org>, Michael Paquier <michael@paquier.xyz>,
Alvaro Herrera <alvherre@2ndquadrant.com>, Thomas Munro <thomas.munro@gmail.com>, David Steele <david@pgmasters.net>, Tom Lane <tgl@sss.pgh.pa.us>, Tomas Vondra <tomas.vondra@2ndquadrant.com>, PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>
Date: 2021-02-04T10:51:39Z
Lists: pgsql-hackers
Attachments
- v13-0001-Add-TID-Range-Scans-to-support-efficient-scannin.patch (text/plain) patch v13-0001
On Thu, 4 Feb 2021 at 10:31, David Rowley <dgrowleyml@gmail.com> wrote: > > Thanks for looking at this. > > On Thu, 4 Feb 2021 at 10:19, Andres Freund <andres@anarazel.de> wrote: > > Perhaps something like > > > > typedef struct TableScanTidRange TableScanTidRange; > > > > TableScanTidRange* table_scan_tid_range_start(TableScanDesc sscan, ItemPointer mintid, ItemPointer maxtid); > > bool table_scan_tid_range_nextslot(TableScanDesc sscan, TableScanTidRange *range, TupleTableSlot *slot); > > void table_scan_tid_range_end(TableScanDesc sscan, TableScanTidRange* range); > > > > would work better? That'd allow an AM to have arbitrarily large state > > for a tid range scan, would make it clear what the lifetime of the > > ItemPointer mintid, ItemPointer maxtid are etc. Wouldn't, on the API > > level, prevent multiple tid range scans from being in progress at the > > same times though :(. Perhaps we could add a TableScanTidRange* pointer > > to TableScanDesc which'd be checked/set by tableam.h which'd prevent that? > > Maybe the TableScanTidRange can just have a field to store the > TableScanDesc. That way table_scan_tid_range_nextslot and > table_scan_tid_range_end can just pass the TableScanTidRange pointer. > > That way it seems like it would be ok for multiple scans to be going > on concurrently as nobody should be reusing the TableScanDesc. I ended up adding just two new API functions to table AM. void (*scan_set_tid_range) (TableScanDesc sscan, ItemPointer mintid, ItemPointer maxtid); and bool (*scan_tid_range_nextslot) (TableScanDesc sscan, ScanDirection direction, TupleTableSlot *slot); I added an additional function in tableam.h that does not have a corresponding API function: static inline TableScanDesc table_tid_range_start(Relation rel, Snapshot snapshot, ItemPointer mintid, ItemPointer maxtid) This just calls the standard scan_begin then calls scan_set_tid_range setting the specified mintid and maxtid. I also added 2 new fields to TableScanDesc: ItemPointerData rs_mintid; ItemPointerData rs_maxtid; I didn't quite see a need to have a new start and end scan API function. Updated patch attached. David
Commits
-
Add TID Range Scans to support efficient scanning ranges of TIDs
- bb437f995d47 14.0 landed
-
Improve planner's selectivity estimates for inequalities on CTID.
- f7111f72d2fd 12.0 landed