Re: [HACKERS] [WIP] Effective storage of duplicates in B-tree index.
Anastasia Lubennikova <a.lubennikova@postgrespro.ru>
Attachments
- 0001-btree_compression_pg12_v2.patch (text/x-patch) patch v2-0001
11.07.2019 21:19, Peter Geoghegan wrote: > On Thu, Jul 11, 2019 at 8:34 AM Rafia Sabih <rafia.pghackers@gmail.com> wrote: Hi, Peter, Rafia, thanks for the review. New version is attached. >> + elog(DEBUG4, "insert_itupprev_to_page. compressState->ntuples %d >> IndexTupleSize %zu free %zu", >> + compressState->ntuples, IndexTupleSize(to_insert), PageGetFreeSpace(page)); >> + >> and other such DEBUG4 statements are meant to be removed, right...? > I hope so too. Yes, these messages are only for debugging. I haven't delete them since this is still work in progress and it's handy to be able to print inner details. Maybe I should also write a patch for pageinspect. >> /* >> * If we have only 10 uncompressed items on the full page, it probably >> * won't worth to compress them. >> */ >> if (maxoff - n_posting_on_page < 10) >> return; >> >> Is this a magic number...? > I think that this should be a constant or something. Fixed. Now this is a constant in nbtree.h. I'm not 100% sure about the value. When the code will stabilize we can benchmark it and find optimal value. >> /* >> * We do not expect to meet any DEAD items, since this function is >> * called right after _bt_vacuum_one_page(). If for some reason we >> * found dead item, don't compress it, to allow upcoming microvacuum >> * or vacuum clean it up. >> */ >> if (ItemIdIsDead(itemId)) >> continue; >> >> This makes me wonder about those 'some' reasons. > I think that this is just defensive. Note that _bt_vacuum_one_page() > is prepared to find no dead items, even when the BTP_HAS_GARBAGE flag > is set for the page. You are right, now it is impossible to meet dead items in this function. Though it can change in the future if, for example, _bt_vacuum_one_page will behave lazily. So this is just a sanity check. Maybe it's worth to move it to Assert. > >> Caller is responsible for checking BTreeTupleIsPosting to ensure that >> + * he will get what he expects >> >> This can be re-framed to make the caller more gender neutral. > Agreed. I also don't like anthropomorphizing code like this. Fixed. >> Other than that, I am curious about the plans for its backward compatibility. > Me too. There is something about a new version 5 in comments in > nbtree.h, but the version number isn't changed. I think that we may be > able to get away with not increasing the B-Tree version from 4 to 5, > actually. Deduplication is performed lazily when it looks like we > might have to split the page, so there isn't any expectation that > tuples will either be compressed or uncompressed in any context. Current implementation is backward compatible. To distinguish posting tuples, it only adds one new flag combination. This combination was never possible before. Comment about version 5 is deleted. I also added a patch for amcheck. There is one major issue left - preserving TID order in posting lists. For a start, I added a sort into BTreeFormPostingTuple function. It turned out to be not very helpful, because we cannot check this invariant lazily. Now I work on patching _bt_binsrch_insert() and _bt_insertonpg() to implement insertion into the middle of the posting list. I'll send a new version this week. -- Anastasia Lubennikova Postgres Professional: http://www.postgrespro.com The Russian Postgres Company
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