Re: Combine Prune and Freeze records emitted by vacuum

From: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
To: Melanie Plageman <melanieplageman(at)gmail(dot)com>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>, Robert Haas <robertmhaas(at)gmail(dot)com>, Peter Geoghegan <pg(at)bowt(dot)ie>
Subject: Re: Combine Prune and Freeze records emitted by vacuum
Date: 2024-03-20 13:15:49
Message-ID: 8e10a952-7803-4f43-afd3-57ae3763b485@iki.fi
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 20/03/2024 03:36, Melanie Plageman wrote:
> On Mon, Mar 18, 2024 at 01:15:21AM +0200, Heikki Linnakangas wrote:
>> On 15/03/2024 02:56, Melanie Plageman wrote:
>>> Okay, so I was going to start using xl_heap_prune for vacuum here too,
>>> but I realized it would be bigger because of the
>>> snapshotConflictHorizon. Do you think there is a non-terrible way to
>>> make the snapshotConflictHorizon optional? Like with a flag?
>>
>> Yeah, another flag would do the trick.
>
> Okay, I've done this in attached v4 (including removing
> XLOG_HEAP2_VACUUM). I had to put the snapshot conflict horizon in the
> "main chunk" of data available at replay regardless of whether or not
> the record ended up including an FPI.
>
> I made it its own sub-record (xlhp_conflict_horizon) less to help with
> alignment (though we can use all the help we can get there) and more to
> keep it from getting lost. When you look at heapam_xlog.h, you can see
> what a XLOG_HEAP2_PRUNE record will contain starting with the
> xl_heap_prune struct and then all the sub-record types.

Ok, now that I look at this, I wonder if we're being overly cautious
about the WAL size. We probably could just always include the snapshot
field, and set it to InvalidTransactionId and waste 4 bytes when it's
not needed. For the sake of simplicity. I don't feel strongly either way
though, the flag is pretty simple too.

> xl_heap_prune->flags is a uint8, but we are already using 7 of the bits.
> Should we make it a unit16?

It doesn't matter much either way. We can also make it larger when we
need more bits, there's no need make room for them them beforehand.

> Eventually, I would like to avoid emitting a separate XLOG_HEAP2_VISIBLE
> record for vacuum's first and second passes and just include the VM
> update flags in the xl_heap_prune record. xl_heap_visible->flags is a
> uint8. If we made xl_heap_prune->flags uint16, we could probably combine
> them (though maybe we want other bits available). Also vacuum's second
> pass doesn't set a snapshotConflictHorizon, so if we combined
> xl_heap_visible and xl_heap_prune for vacuum we would end up saving even
> more space (since vacuum sets xl_heap_visible->snapshotConflictHorizon
> to InvalidXLogRecPtr).

Makes sense.

> A note on sub-record naming: I kept xl_heap_freeze_plan's name but
> prefixed the other sub-records with xlhp. Do you think it is worth
> renaming it (to xlhp_freeze_plan)?

Yeah, perhaps.

> Also, should I change xlhp_freeze to xlhp_freeze_page?
I renamed it to xlhp_freeze_plans, for some consistency with
xlhp_prune_items.

I realized that the WAL record format changes are pretty independent
from the rest of the patches. They could be applied before the rest.
Without the rest of the changes, we'll still write two WAL records per
page in vacuum, one to prune and another one to freeze, but it's another
meaningful incremental step. So I reshuffled the patches, so that the
WAL format is changed first, before the rest of the changes.

0001-0008: These are the WAL format changes. There's some comment
cleanup needed, but as far as the code goes, I think these are pretty
much ready to be squashed & committed.

0009-: The rest of the v4 patches, rebased over the WAL format changes.
I also added a few small commits for little cleanups that caught my eye,
let me know if you disagree with those.

--
Heikki Linnakangas
Neon (https://neon.tech)

Attachment Content-Type Size
v5-0001-Merge-prune-freeze-and-vacuum-WAL-record-formats.patch text/x-patch 47.5 KB
v5-0002-Keep-the-original-numbers-for-existing-WAL-record.patch text/x-patch 1.3 KB
v5-0003-Rename-record-to-XLOG_HEAP2_PRUNE_FREEZE.patch text/x-patch 7.3 KB
v5-0004-nplans-is-a-pointer.patch text/x-patch 847 bytes
v5-0005-Remind-myself-to-bump-XLOG_PAGE_MAGIC-when-this-i.patch text/x-patch 915 bytes
v5-0006-Fix-logging-snapshot-conflict-horizon.patch text/x-patch 4.3 KB
v5-0007-Add-comment-to-log_heap_prune_and_freeze.patch text/x-patch 1.4 KB
v5-0008-minor-refactoring-in-log_heap_prune_and_freeze.patch text/x-patch 6.3 KB
v5-0009-lazy_scan_prune-tests-tuple-vis-with-GlobalVisTes.patch text/x-patch 2.1 KB
v5-0010-Pass-heap_prune_chain-PruneResult-output-paramete.patch text/x-patch 3.3 KB
v5-0011-heap_page_prune-sets-all_visible-and-frz_conflict.patch text/x-patch 18.8 KB
v5-0012-Add-reference-to-VacuumCutoffs-in-HeapPageFreeze.patch text/x-patch 12.4 KB
v5-0013-still-use-a-local-cutoffs-variable.patch text/x-patch 9.3 KB
v5-0014-Prepare-freeze-tuples-in-heap_page_prune.patch text/x-patch 11.8 KB
v5-0015-lazy_scan_prune-reorder-freeze-execution-logic.patch text/x-patch 5.9 KB
v5-0016-Execute-freezing-in-heap_page_prune.patch text/x-patch 25.5 KB
v5-0017-Make-opp-freeze-heuristic-compatible-with-prune-f.patch text/x-patch 4.3 KB
v5-0018-Separate-tuple-pre-freeze-checks-and-invoke-earli.patch text/x-patch 6.6 KB
v5-0019-Remove-heap_freeze_execute_prepared.patch text/x-patch 8.3 KB
v5-0020-Merge-prune-and-freeze-records.patch text/x-patch 11.4 KB
v5-0021-move-whole_page_freezable-to-tighter-scope.patch text/x-patch 1.7 KB
v5-0022-make-all_visible_except_removable-local.patch text/x-patch 4.9 KB
v5-0023-Set-hastup-in-heap_page_prune.patch text/x-patch 7.7 KB
v5-0024-Count-tuples-for-vacuum-logging-in-heap_page_prun.patch text/x-patch 15.5 KB
v5-0025-Save-dead-tuple-offsets-during-heap_page_prune.patch text/x-patch 7.0 KB
v5-0026-reorder-PruneFreezeResult-fields.patch text/x-patch 1.2 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Masahiko Sawada 2024-03-20 13:30:06 Re: [PoC] Improve dead tuple storage for lazy vacuum
Previous Message Melanie Plageman 2024-03-20 13:15:07 Re: Test 031_recovery_conflict.pl is not immune to autovacuum