Re: nbtree: reduce code redundancy by using _bt_getmeta() in _bt_gettrueroot() - Mailing list pgsql-hackers

From Neil Chen
Subject Re: nbtree: reduce code redundancy by using _bt_getmeta() in _bt_gettrueroot()
Date
Msg-id CAA3qoJk3KxJ_aCwj1RHwFL53GEUHHu=szh_8j=3+GWE5JPcKUQ@mail.gmail.com
Whole thread Raw
In response to nbtree: reduce code redundancy by using _bt_getmeta() in _bt_gettrueroot()  (Chao Li <li.evan.chao@gmail.com>)
List pgsql-hackers
Hi Chao,

On Thu, Jan 15, 2026 at 4:11 PM Chao Li <li.evan.chao@gmail.com> wrote:

I noticed this while reviewing [1]. _bt_gettrueroot() performs the same metapage checks as _bt_getmeta(), so using _bt_getmeta() here removes the duplicated code.


It looks good to me. These two code snippets are exactly identical, 
so removing the redundant code is reasonable.

As can be seen from the contextual comments, this is not a performance-critical path either, 
so we don’t need to worry about the performance overhead caused by function calls.

I also checked the changes made in commit dd299df, which essentially does the same thing for the function _bt_getrootheight.

pgsql-hackers by date:

Previous
From: Neil Chen
Date:
Subject: Re: Optimize SnapBuildPurgeOlderTxn: use in-place compaction instead of temporary array
Next
From: Zsolt Parragi
Date:
Subject: Re: Custom oauth validator options