Re: New IndexAM API controlling index vacuum strategies
Masahiko Sawada <sawada.mshk@gmail.com>
From: Masahiko Sawada <sawada.mshk@gmail.com>
To: Peter Geoghegan <pg@bowt.ie>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2021-01-20T06:34:53Z
Lists: pgsql-hackers
On Wed, Jan 20, 2021 at 9:45 AM Peter Geoghegan <pg@bowt.ie> wrote: > > On Tue, Jan 19, 2021 at 2:57 PM Peter Geoghegan <pg@bowt.ie> wrote: > > * Maybe it would be better if you just changed the definition such > > that "MAXALIGN(SizeofHeapTupleHeader)" became "MAXIMUM_ALIGNOF", with > > no other changes? (Some variant of this suggestion might be better, > > not sure.) > > > > For some reason that feels a bit safer: we still have an "imaginary > > tuple header", but it's just 1 MAXALIGN() quantum now. This is still > > much less than the current 3 MAXALIGN() quantums (i.e. what > > MaxHeapTuplesPerPage treats as the tuple header size). Do you think > > that this alternative approach will be noticeably less effective > > within vacuumlazy.c? > > BTW, I think that increasing MaxHeapTuplesPerPage will make it > necessary to consider tidbitmap.c. Comments at the top of that file > say that it is assumed that MaxHeapTuplesPerPage is about 256. So > there is a risk of introducing performance regressions affecting > bitmap scans here. > > Apparently some other DB systems make the equivalent of > MaxHeapTuplesPerPage dynamically configurable at the level of heap > tables. It usually doesn't matter, but it can matter with on-disk > bitmap indexes, where the bitmap must be encoded from raw TIDs (this > must happen before the bitmap is compressed -- there must be a simple > mapping from every possible TID to some bit in a bitmap first). The > item offset component of each heap TID is not usually very large, so > there is a trade-off between keeping the representation of bitmaps > efficient and not unduly restricting the number of distinct heap > tuples on each heap page. I think that there might be a similar > consideration here, in tidbitmap.c (even though it's not concerned > about on-disk bitmaps). That's a good point. With the patch, MaxHeapTuplesPerPage increased to 2042 with 8k page, and to 8186 with 32k page whereas it's currently 291 with 8k page and 1169 with 32k page. So it is likely to be a problem as you pointed out. If we change "MAXALIGN(SizeofHeapTupleHeader)" to "MAXIMUM_ALIGNOF", it's 680 with 8k patch and 2728 with 32k page, which seems much better. The purpose of increasing MaxHeapTuplesPerPage in the patch is to have a heap page accumulate more LP_DEAD line pointers. As I explained before, considering MaxHeapTuplesPerPage, we cannot calculate how many LP_DEAD line pointers can be accumulated into the space taken by fillfactor simply by ((the space taken by fillfactor) / (size of line pointer)). We need to consider both how many line pointers are available for LP_DEAD and how much space is available for LP_DEAD. For example, suppose the tuple size is 50 bytes and fillfactor is 80, each page has 1633 bytes (=(8192-24)*0.2) free space taken by fillfactor, where 408 line pointers can fit. However, if we store 250 LP_DEAD line pointers into that space, the number of tuples that can be stored on the page is only 41, although we have 6534 bytes (=(8192-24)*0.8) where 121 tuples (+line pointers) can fit because MaxHeapTuplesPerPage is 291. In this case, where the tuple size is 50 and fillfactor is 80, we can accumulate up to about 170 LP_DEAD line pointers while storing 121 tuples. Increasing MaxHeapTuplesPerPage raises this 291 limit and enables us to forget the limit when calculating the maximum number of LP_DEAD line pointers that can be accumulated on a single page. An alternative approach would be to calculate it using the average tuple's size. I think if we know the tuple size, the maximum number of LP_DEAD line pointers can be accumulated into the single page is the minimum of the following two formula: (1) MaxHeapTuplesPerPage - (((BLCKSZ - SizeOfPageHeaderData) * (fillfactor/100)) / (sizeof(ItemIdData) + tuple_size))); //how many line pointers are available for LP_DEAD? (2) ((BLCKSZ - SizeOfPageHeaderData) * ((1 - fillfactor)/100)) / sizeof(ItemIdData); //how much space is available for LP_DEAD? But I'd prefer to increase MaxHeapTuplesPerPage but not to affect the bitmap much rather than introducing a complex theory. Regards, -- Masahiko Sawada EDB: https://www.enterprisedb.com/
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Don't truncate heap when VACUUM's failsafe is in effect.
- 60f1f09ff443 14.0 landed
-
Teach VACUUM to bypass unnecessary index vacuuming.
- 5100010ee4d5 14.0 landed
-
Add wraparound failsafe to VACUUM.
- 1e55e7d1755c 14.0 landed
-
Truncate line pointer array during VACUUM.
- 3c3b8a4b2689 14.0 landed
-
Remove tupgone special case from vacuumlazy.c.
- 8523492d4e34 14.0 landed
-
Refactor lazy_scan_heap() loop.
- 7ab96cf6b312 14.0 landed
-
Propagate parallel VACUUM's buffer access strategy.
- 49f49defe7c0 14.0 cited
-
Simplify state managed by VACUUM.
- b4af70cb2103 14.0 landed
-
Notice that heap page has dead items during VACUUM.
- 0ea71c93a06d 14.0 landed
-
Adjust lazy_scan_heap() accounting comments.
- 7cde6b13a9b6 14.0 cited
-
Use full 64-bit XID for checking if a deleted GiST page is old enough.
- 6655a7299d83 13.0 cited
-
Fix some problems with VACUUM (INDEX_CLEANUP FALSE).
- dd6959798885 12.0 cited