Re: Cleaning up nbtree after logical decoding on standby work

From: Peter Geoghegan <pg(at)bowt(dot)ie>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, "Drouvot, Bertrand" <bertranddrouvot(dot)pg(at)gmail(dot)com>, Andres Freund <andres(at)anarazel(dot)de>
Subject: Re: Cleaning up nbtree after logical decoding on standby work
Date: 2023-05-26 16:56:50
Message-ID: CAH2-WznPHDV-tVe1geXmqkiOS0rS+iE6ZajHugWFEgcQra2SMA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, May 26, 2023 at 12:46 AM Michael Paquier <michael(at)paquier(dot)xyz> wrote:
> Nice cleanup overall.

Thanks.

To be clear, when I said "it would be nice to get rid of P_NEW", what
I meant was that it would be nice to go much further than what I've
done in the patch by getting rid of the general idea of P_NEW. So the
handling of P_NEW at the top of ReadBuffer_common() would be removed,
for example. (Note that nbtree doesn't actually rely on that code,
even now; while its use of the P_NEW constant creates the impression
that it needs that bufmgr.c code, it actually doesn't, even now.)

> + if (XLogStandbyInfoActive() && RelationNeedsWAL(rel))
> {
> - /* Okay to use page. Initialize and return it. */
> - _bt_pageinit(page, BufferGetPageSize(buf));
> - return buf;
> + safexid = BTPageGetDeleteXid(page);
> + isCatalogRel = RelationIsAccessibleInLogicalDecoding(heaprel);
> + _bt_log_reuse_page(rel, blkno, safexid, isCatalogRel);
>
> There is only one caller of _bt_log_reuse_page(), so assigning a
> boolean rather than the heap relation is a bit strange to me. I think
> that calling RelationIsAccessibleInLogicalDecoding() within
> _bt_log_reuse_page() where xlrec_reuse is filled with its data is much
> more natural, like HEAD.

Attached is v2, which deals with this by moving the code from
_bt_log_reuse_page() into _bt_allocbuf() itself -- there is no need
for a separate logging function. This structure seems like a clear
improvement, since such logging is largely the point of having a
separate _bt_allocbuf() function that deals with new page allocations
and requires a valid heapRel in all cases.

v2 also renames "heaprel" to "heapRel" in function signatures, for
consistency with older code that always used that convention.

--
Peter Geoghegan

Attachment Content-Type Size
v2-0001-nbtree-Remove-use-of-P_NEW.patch application/octet-stream 64.8 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message vignesh C 2023-05-26 17:00:12 Re: Implement generalized sub routine find_in_log for tap test
Previous Message Tom Lane 2023-05-26 16:49:11 Re: Is NEW.ctid usable as table_tuple_satisfies_snapshot?