Re: [HACKERS] [WIP] Effective storage of duplicates in B-tree index.
Peter Geoghegan <pg@bowt.ie>
Attachments
- v32-0002-Teach-pageinspect-about-nbtree-posting-lists.patch (application/x-patch) patch v32-0002
- v32-0003-DEBUG-Show-index-values-in-pageinspect.patch (application/x-patch) patch v32-0003
- v32-0001-Add-deduplication-to-nbtree.patch (application/x-patch) patch v32-0001
On Tue, Jan 28, 2020 at 5:29 PM Peter Geoghegan <pg@bowt.ie> wrote: > In my opinion, the patch is now pretty close to being committable. Attached is v32, which is even closer to being committable. > I do have two outstanding open items for the patch, though. These items > are: > > * We still need infrastructure that marks B-Tree opclasses as safe for > deduplication, to avoid things like the numeric display scale problem, > collations that are unsafe for deduplication because they're > nondeterministic, etc. No progress on this item for v32, though. It's now my only open item for this entire project. Getting very close. > * Make VACUUM's WAL record more space efficient when it contains one > or more "updates" to an existing posting list tuple. * I've focussed on this item in v32 -- it has been closed out. v32 doesn't explicitly WAL-log post-update index tuples during vacuuming of posting list tuples, making the WAL records a lot smaller in some cases. v32 represents the posting list TIDs that must be deleted instead. It does this in the most WAL-space-efficient manner possible: by storing an array of uint16 offsets for each "updated" posting list within xl_btree_vacuum records -- each entry in each array is an offset to remove (i.e. a TID that should not appear in the updated version of the tuple). We use a new nbtdedup.c utility function for this, _bt_update_posting(). The new function is similar to its neighbor function, _bt_swap_posting(), which is the nbtdedup.c utility function used during posting list splits. Just like _bt_swap_posting(), we call _bt_update_posting() both during the initial action, and from the REDO routine that replays that action. Performing vacuuming of posting list tuples this way seems to matter with larger databases that depend on deduplication to control bloat, though I haven't taken the time to figure out exactly how much it matters. I'm satisfied that this is worth having based on microbenchmarks that measure WAL volume using pg_waldump. One microbenchmark showed something like a 10x decrease in the size of all xl_btree_vacuum records taken together compared to v31. I'm pretty sure that v32 makes it all but impossible for deduplication to write out more WAL than an equivalent case with deduplication disabled (I'm excluding FPIs here, of course -- full_page_writes=on cases will see significant benefits from reduced FPIs, simply by having fewer index pages). The per-leaf-page WAL record header accounts for a lot of the space overhead of xl_btree_vacuum records, and we naturally reduce that overhead when deduplicating, so we can now noticeably come out ahead when it comes to overall WAL volume. I wouldn't say that reducing WAL volume (other than FPIs) is actually a goal of this project, but it might end up happening anyway. Apparently Microsoft Azure PostgreSQL uses full_page_writes=off, so not everyone cares about the number of FPIs (everyone cares about raw record size, though). * Removed the GUC that controls the use of deduplication in this new version, per discussion with Robert over on the "Enabling B-Tree deduplication by default" thread. Perhaps we can get by with only an index storage parameter. Let's defer this until after the Postgres 13 beta period is over, and we get feedback from testers. * Turned the documentation on deduplication in the B-Tree internals chapter into a more general discussion of the on-disk format that covers deduplication. Deduplication enhances this on-disk representation, and discussing it outside that wider context always felt awkward to me. Having this kind of discussion in the docs seems like a good idea anyway. -- Peter Geoghegan
Commits
-
Teach pageinspect about nbtree deduplication.
- 93ee38eade1b 13.0 landed
-
Doc: Fix deduplicate_items index term.
- e537aed61db7 13.0 landed
-
Revise BTP_HAS_GARBAGE nbtree VACUUM comments.
- 4b25f5d0ba01 13.0 cited
-
Remove unneeded "pin scan" nbtree VACUUM code.
- 9f83468b3536 13.0 landed
-
Cleanup code in reloptions.h regarding reloption handling
- 50d22de9325f 13.0 cited
-
Catch invalid typlens in a couple of places
- 8557a6f10ca6 13.0 cited
-
Compute XID horizon for page level index vacuum on primary.
- 558a9165e081 12.0 cited
-
Make heap TID a tiebreaker nbtree index column.
- dd299df8189b 12.0 cited
-
Avoid pin scan for replay of XLOG_BTREE_VACUUM in all cases
- 3e4b7d87988f 9.6.0 cited
-
Revert buggy optimization of index scans
- c7111d11b188 9.6.0 cited
-
Restructure index access method API to hide most of it at the C level.
- 65c5fcd353a8 9.6.0 cited
-
Reduce pinning and buffer content locking for btree scans.
- 2ed5b87f96d4 9.5.0 cited
-
Avoid scanning nulls at the beginning of a btree index scan.
- 1a77f8b63d15 9.2.0 cited