Re: Pluggable Storage - Andres's take
Andres Freund <andres@anarazel.de>
Attachments
- tableam-size.diff (text/x-diff) patch
Hi Heikki, Ashwin, Tom, On 2019-04-23 15:52:01 -0700, Andres Freund wrote: > On 2019-04-08 15:34:46 +0300, Heikki Linnakangas wrote: > > index_update_stats() calls RelationGetNumberOfBlocks(<table>). If the AM > > doesn't use normal data files, that won't work. I bumped into that with my > > toy implementation, which wouldn't need to create any data files, if it > > wasn't for this. > > There are a few more of these: > I'm not sure about doing so for v12 though. 1) and 3) are fairly > trivial, but 2) would involve changing the FDW interface, by changing > the AnalyzeForeignTable, AcquireSampleRowsFunc signatures. But OTOH, > we're not even in beta1. Hm. I think some of those changes would be a bit bigger than I initially though. Attached is a more minimal fix that'd route RelationGetNumberOfBlocksForFork() through tableam if necessary. I think it's definitely the right answer for 1), probably the pragmatic answer to 2), but certainly not for 3). I've for now made the AM return the size in bytes, and then convert that into blocks in RelationGetNumberOfBlocksForFork(). Most postgres callers are going to continue to want it internally as pages (otherwise there's going to be way too much churn, without a benefit I can see). So I thinkt that's OK. There's also a somewhat weird bit of returning the total relation size for InvalidForkNumber - it's pretty likely that other AMs wouldn't use postgres' current forks, but have equivalent concepts. And without that there'd be no way to get that size. I'm not sure I like this, input welcome. But it seems good to offer the ability to get the entire size somehow. Btw, isn't RelationGetNumberOfBlocksForFork() currently weirdly placed? I don't see why bufmgr.c would be appropriate? Although I don't think it's particulary clear where it'd best reside - I'd tentatively say storage.c. Heikki, Ashwin, your inputs would be appreciated here, in particular the tid fetch bit below. The attached patch isn't intended to be applied as-is, just basis for discussion. > 1) index_update_stats(), computing pg_class.relpages > > Feels like the number of both heap and index blocks should be > computed by the index build and stored in IndexInfo. That'd also get > a bit closer towards allowing indexams not going through smgr (useful > e.g. for memory only ones). Due to parallel index builds that'd actually be hard. Given the number of places wanting to compute relpages for pg_class I think the above patch routing RelationGetNumberOfBlocksForFork() through tableam is the right fix. > 2) commands/analyze.c, computing pg_class.relpages > > This should imo be moved to the tableam callback. It's currently done > a bit weirdly imo, with fdws computing relpages the callback, but > then also returning the acquirefunc. Seems like it should entirely be > computed as part of calling acquirefunc. Here I'm not sure routing RelationGetNumberOfBlocksForFork() through tableam wouldn't be the right minimal approach too. It has the disadvantage of implying certain values for the RelationGetNumberOfBlocksForFork(MAIN) return value. The alternative would be to return the desire sampling range in table_beginscan_analyze() - but that'd require some duplication because currently that just uses the generic scan_begin() callback. I suspect - as previously mentioned- that we're going to have to extend statistics collection beyond the current approach at some point, but I don't think that's now. At least to me it's not clear how to best represent the stats, and how to best use them, if the underlying storage is fundamentally not block best. Nor how we'd avoid code duplication... > 3) nodeTidscan, skipping over too large tids > I think this should just be moved into the AMs, there's no need to > have this in nodeTidscan.c I think here it's *not* actually correct at all to use the relation size. It's currently doing: /* * We silently discard any TIDs that are out of range at the time of scan * start. (Since we hold at least AccessShareLock on the table, it won't * be possible for someone to truncate away the blocks we intend to * visit.) */ nblocks = RelationGetNumberOfBlocks(tidstate->ss.ss_currentRelation); which is fine (except for a certain abstraction leakage) for an AM like heap or zheap, but I suspect strongly that that's not ok for Ashwin & Heikki's approach where tid isn't tied to physical representation. The obvious answer would be to just move that check into the table_fetch_row_version implementation (currently just calling heap_fetch()) - but that doesn't seem OK from a performance POV, because we'd then determine the relation size once for each tid, rather than once per tidscan. And it'd also check in cases where we know the tid is supposed to be valid (e.g. fetching trigger tuples and such). The proper fix seems to be to introduce a new scan variant (e.g. table_beginscan_tid()), and then have table_fetch_row_version take a scan as a parameter. But it seems we'd have to introduce that as a separate tableam callback, because we'd not want to incur the overhead of creating an additional scan / RelationGetNumberOfBlocks() checks for triggers et al. Greetings, Andres Freund
Commits
-
Add default_table_access_method to postgresql.conf.sample.
- 3a5c08aa0267 12.0 landed
- f7db0ac7d5b6 13.0 landed
-
tableam: Avoid relying on relation size to determine validity of tids.
- 147e3722f7e5 12.0 landed
-
tableam: Don't assume that every AM uses md.c style storage.
- 7f44ede59414 12.0 landed
-
Allow pg_class xid & multixid horizons to not be set.
- fdc7efcc30b1 12.0 landed
-
Fix slot type issue for fuzzy distance index scan over out-of-core table AM.
- b8b94ea129ff 12.0 cited
-
tableam: comment and formatting fixes.
- 6421011ea24d 12.0 landed
-
table: docs: fix typos and grammar.
- 86cc06d1cf9c 12.0 landed
-
tableam: basic documentation.
- b73c3a11963c 12.0 landed
-
Only allow heap in a number of contrib modules.
- 4b82664156c2 12.0 landed
-
tableam: Add table_finish_bulk_insert().
- d45e40158623 12.0 landed
-
tableam: sample scan.
- 73c954d24896 12.0 landed
-
tableam: bitmap table scan.
- bfbcad478f05 12.0 landed
-
tableam: Move heap specific logic from estimate_rel_size below tableam.
- 696d78469f37 12.0 landed
-
tableam: VACUUM and ANALYZE support.
- 737a292b5de2 12.0 landed
-
tableam: relation creation, VACUUM FULL/CLUSTER, SET TABLESPACE.
- d25f519107bf 12.0 landed
-
tableam: Support for an index build's initial table scan(s).
- 2a96909a4a8c 12.0 landed
-
tableam: Add table_get_latest_tid, to wrap heap_get_latest_tid.
- 2e3da03e9ee4 12.0 landed
-
tableam: Add helper for indexes to check if a corresponding table tuples exist.
- 71bdc99d0d7c 12.0 landed
-
tableam: Add and use table_fetch_row_version().
- 9a8ee1dc650b 12.0 landed
-
tableam: Use in CREATE TABLE AS and CREATE MATERIALIZED VIEW.
- 919e48b94301 12.0 landed
-
Ensure sufficient alignment for ParallelTableScanDescData in BTShared.
- 8cacea7a7251 12.0 landed
-
Don't reuse slots between root and partition in ON CONFLICT ... UPDATE.
- 277cb789836b 12.0 landed
-
Use a virtual rather than a heap slot in two places where that suffices.
- 70b9bda65f81 12.0 landed
-
Store tuples for EvalPlanQual in slots, rather than as HeapTuples.
- ad0bda5d24ea 12.0 landed
-
Use slots in trigger infrastructure, except for the actual invocation.
- ff11e7f4b9ae 12.0 landed
-
Store table oid and tuple's tid in tuple slots directly.
- b8d71745eac0 12.0 landed
-
Allow to use HeapTupleData embedded in [Buffer]HeapTupleTableSlot.
- 5408e233f066 12.0 landed
-
Add ExecStorePinnedBufferHeapTuple.
- 8aa02b52db11 12.0 landed
-
Add ArchiveOpts to pass options to ArchiveEntry
- f831d4accda0 12.0 cited
-
Rename RelationData.rd_amroutine to rd_indam.
- 346ed70b0ad7 12.0 landed
-
Rephrase references to "time qualification".
- ebcc7bf949ba 12.0 landed
-
Move remaining code from tqual.[ch] to heapam.h / heapam_visibility.c.
- c91560defc57 12.0 landed
-
Move generic snapshot related code from tqual.h to snapmgr.h.
- b7eda3e0e334 12.0 landed
-
Remove superfluous tqual.h includes.
- e7cc78ad43eb 12.0 landed
-
Don't duplicate parallel seqscan shmem sizing logic in nbtree.
- 90525d7b4e0f 12.0 landed
-
Move vacuumlazy.c into access/heap.
- 285d8e12055f 12.0 landed
-
Support parallel bitmap heap scans.
- f35742ccb7aa 10.0 cited