Re: Pluggable Storage - Andres's take
Haribabu Kommi <kommi.haribabu@gmail.com>
On Tue, Jul 3, 2018 at 5:06 PM Andres Freund <andres@anarazel.de> wrote: > Hi, > > As I've previously mentioned I had planned to spend some time to polish > Haribabu's version of the pluggable storage patch and rebase it on the > vtable based slot approach from [1]. While doing so I found more and > more things that I previously hadn't noticed. I started rewriting things > into something closer to what I think we want architecturally. > Thanks for the deep review and changes. > The current state of my version of the patch is *NOT* ready for proper > review (it doesn't even pass all tests, there's FIXME / elog()s). But I > think it's getting close enough to it's eventual shape that more eyes, > and potentially more hands on keyboards, can be useful. > I will try to update it to make sure that it passes all the tests and also try to reduce the FIXME's. > The most fundamental issues I had with Haribabu's last version from [2] > are the following: > > - The use of TableTuple, a typedef from void *, is bad from multiple > fronts. For one it reduces just about all type safety. There were > numerous bugs in the patch where things were just cast from HeapTuple > to TableTuple to HeapTuple (and even to TupleTableSlot). I think it's > a really, really bad idea to introduce a vague type like this for > development purposes alone, it makes it way too hard to refactor - > essentially throwing the biggest benefit of type safe languages out of > the window. > My earlier intention was to remove the HeapTuple usage entirely and replace it with slot everywhere outside the tableam. But it ended up with TableTuple before it reach to the stage because of heavy use of HeapTuple. > Additionally I think it's also the wrong approach architecturally. We > shouldn't assume that a tuple can efficiently be represented as a > single palloc'ed chunk. In fact, we should move *away* from relying on > that so much. > > I've thus removed the TableTuple type entirely. > Thanks for the changes, I didn't check the code yet, so for now whenever the HeapTuple is required it will be generated from slot? > - Previous verions of the patchset exposed Buffers in the tableam.h API, > performed buffer locking / pinning / ExecStoreTuple() calls outside of > it. That is wrong in my opinion, as various AMs will deal very > differently with buffer pinning & locking. The relevant logic is > largely moved within the AM. Bringing me to the next point: > > > - tableam exposed various operations based on HeapTuple/TableTuple's > (and their Buffers). This all need be slot based, as we can't > represent the way each AM will deal with this. I've largely converted > the API to be slot based. That has some fallout, but I think largely > works. Lots of outdated comments. > Yes, I agree with you. > - I think the move of the indexing from outside the table layer into the > storage layer isn't a good idea. It lead to having to pass EState into > the tableam, a callback API to perform index updates, etc. This seems > to have at least partially been triggered by the speculative insertion > codepaths. I've reverted this part of the changes. The speculative > insertion / confirm codepaths are now exposed to tableam.h - I think > that's the right thing because we'll likely want to have that > functionality across more than a single tuple in the future. > > > - The visibility functions relied on the *caller* performing buffer > locking. That's not a great idea, because generic code shouldn't know > about the locking scheme a particular AM needs. I've changed the > external visibility functions to instead take a slot, and perform the > necessary locking inside. > When I first moved all the visibility functions as part of tableam, I find this problem, and it will be good if it takes of buffer locking and etc. > - There were numerous tableam callback uses inside heapam.c - that makes > no sense, we know what the storage is therein. The relevant > > > - The integration between index lookups and heap lookups based on the > results on a index lookup was IMO too tight. The index code dealt > with heap tuples, which isn't great. I've introduced a new concept, a > 'IndexFetchTableData' scan. It's initialized when building an index > scan, and provides the necessary state (say current heap buffer), to > do table lookups from within a heap. > I agree that it will be good with the new concept from index to access the heap. > - The am of relations required for bootstrapping was set to 0 - I don't > think that's a good idea. I changed it so it's set to the heap AM as > well. > > > - HOT was encoded in the API in a bunch of places. That doesn't look > right to me. I tried to improve a bit on that, but I'm not yet quite > sure I like it. Needs written explanation & arguments... > > > - the heap tableam did a heap_copytuple() nearly everywhere. Leading to > a higher memory usage, because the resulting tuples weren't freed or > anything. There might be a reason for doing such a change - we've > certainly discussed that before - but I'm *vehemently* against doing > that at the same time we introduce pluggable storage. Analyzing the > performance effects will be hard enough without changes like this. > How about using of slot instead of tuple and reusing of it? I don't know yet whether it is possible everywhere. > > - I've for now backed out the heap rewrite changes, partially. Mostly > because I didn't like the way the abstraction looks, but haven't quite > figured out how it should look like. > > > - I did not like that speculative tokens were moved to slots. There's > really no reason for them to live outside parameters to tableam.h > functsions. > > > - lotsa additional smaller changes. > > > - lotsa new bugs > Thanks for all the changes. > > My current working state is at [3] (urls to clone repo are at [4]). > This is *HEAVILY WIP*. I plan to continue working on it over the next > days, but I'll temporarily focus onto v11 work. If others want I could > move repo to github and grant others write access. > Yes, I want to access the code and do further development on it. > > Tasks / Questions: > > - split up patch > How about generating refactoring changes as patches first based on the code in your repo as discussed here[1]? > - Change heap table AM to not allocate handler function for each table, > instead allocate it statically. Avoids a significant amount of data > duplication, and allows for a few more compiler optimizations. > Some kind of static variable handlers for each tableam, but need to check how can we access that static handler from the relation. > - Merge tableam.h and tableamapi.h and make most tableam.c functions > small inline functions. Having one-line tableam.c wrappers makes this > more expensive than necessary. We'll have a big enough trouble not > regressing performancewise. > OK. > - change scan level slot creation to use tableam function for doing so > - get rid of slot->tts_tid, tts_tupleOid and potentially tts_tableOid > so with this there shouldn't be a way from slot to tid mapping or there should be some other way. > - COPY's multi_insert path should probably deal with a bunch of slots, > rather than forming HeapTuples > OK. - bitmap index scans probably need a new tableam.h callback, abstracting > bitgetpage() > OK. Regards, Haribabu Kommi Fujitsu Australia
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