Re: Add 64-bit XIDs into PostgreSQL 15 - Mailing list pgsql-hackers

From Evgeny Voropaev
Subject Re: Add 64-bit XIDs into PostgreSQL 15
Date
Msg-id 385a04da-7eb0-45d3-a852-e0cf20fed8fe@gmail.com
Whole thread Raw
In response to Re: Add 64-bit XIDs into PostgreSQL 15  (Maxim Orlov <orlovmg@gmail.com>)
Responses Re: Add 64-bit XIDs into PostgreSQL 15
List pgsql-hackers
Glad to see the activity around the full version of xid64!


1) About extra freezing in `freeze_single_heap_page`.

At xid64v62 `freeze_single_heap_page` performs freezing via a call to 
`heap_page_prune_and_freeze`.
Why, then, does `freeze_single_heap_page` perform freezing a second time?

```
freeze_single_heap_page(Relation relation, Buffer buffer)
{
    ...
// First freezing
heap_page_prune_and_freeze(relation, buffer, vistest, 0, NULL, &presult, 
PRUNE_ON_ACCESS, &dummy_off_loc, NULL, NULL, false);
...
// Preparation for Extra freezing
    for (offnum = FirstOffsetNumber; offnum <= maxoff; offnum = 
OffsetNumberNext(offnum))
    {
...
        heap_prepare_freeze_tuple(&tuple, &cutoffs, &pagefrz,
                                     &frozen[nfrozen], &totally_frozen)
...
    }
    ...
// Extra freezing
    heap_freeze_prepared_tuples(relation, buffer, frozen, nfrozen);
...
}
```

Are the actions of `heap_page_prune_and_freeze` not sufficient for freezing?
If this extra freezing step is redundant, we might want to consider 
removing this duplicated freezing.

2) About repairing fragmentation.

The original approach implemented in PG18 assumes that fragmentation 
occurs during every `prune_freeze` operation. It happens because the 
logic of the "redo"-function `heap_xlog_prune_freeze` assumes that 
fragmentation has to be done by `heap_page_prune_execute`. Attempting to 
omit fragmentation can result in page inconsistencies on the "redo"-side 
(i.e. on a secondary node, or during the recovery process on primary 
one). So, implementation of optional repairing of fragmentation 
conflicts with the basic assumption about "necessity of fragmentation". 
In order to prevent inconsistency xid64v62 patch invokes 
`heap_page_prune_and_freeze` with `repairFragmentation` equal to true 
from everywhere in the patch code except from 
`heap_page_prepare_for_xid` which uses `repairFragmentation=false`.

So, why must we perform a `heap_page_prune_execute` without a 
fragmentation during the preparation of a page for xid?

What exactly would break if we did perform `heap_page_prune_execute` 
with NO fragmentation repair during `heap_page_prepare_for_xid`?


Best regards,
Evgeny Voropaev,
Tantor Labs, LLC.





pgsql-hackers by date:

Previous
From: Dagfinn Ilmari Mannsåker
Date:
Subject: Re: Extend COPY FROM with HEADER to skip multiple lines
Next
From: Jim Jones
Date:
Subject: Re: XMLSerialize: version and explicit XML declaration