public inbox for [email protected]  
help / color / mirror / Atom feed
From: lakshmi <[email protected]>
To: Kirill Reshke <[email protected]>
Cc: pgsql-hackers <[email protected]>
Subject: Re: Use log_newpage_range in HASH index build
Date: Tue, 23 Dec 2025 17:23:07 +0530
Message-ID: <CAEvyyTjUTLXvrme3CNMjJYwA9j4usrq53PyBPv47Apk58Qz+GA@mail.gmail.com> (raw)
In-Reply-To: <CALdSSPgu6fnoOYzgiFF4_Etr96zEHvSwvYJDemc3o++EZbUQMA@mail.gmail.com>
References: <CALdSSPgu6fnoOYzgiFF4_Etr96zEHvSwvYJDemc3o++EZbUQMA@mail.gmail.com>

Hi Kirill,

I tested your patch on the current master and confirmed the WAL reduction
during HASH index build.

While testing, I noticed a possible small follow-up improvement in HASH
overflow handling. Currently, any free overflow page may be reused, which
can scatter overflow chains and hurt cache locality. Reusing recently freed
overflow pages first could help, without changing WAL behavior or on-disk
format.

I would like to work on this as a follow-up enhancement and would welcome
any suggestions.

Best regards,
Lakshmi

On Tue, Dec 23, 2025 at 2:31 PM Kirill Reshke <[email protected]>
wrote:

> There exists an optimization to index creation process, when we omit
> to write any WAL
> for index build. It is currently supported in B Tree, GIN, GiST, spg
> indexes.
> It works because we do not need to recover anything if index creation
> fails, because if was not used by any query. So, the index can be
> built on-disk, and then, just before making the index alive, we can
> simply log all pages to WAL.
>
> Hash index currently lacks this optimization.
> PFA implementation.
>
> During my testing, I checked the amount of WAL generated by index
> build before and after patch applied. My script was something like:
>
> select pg_current_wal_insert_lsn();
>
> create index on t using hash (i);
>
> select pg_current_wal_insert_lsn();
>
> select pg_lsn_wal_diff(lsn1, lsn2);
>
> Resulting numbers depend on index size, but I got 2.5-3.5 times less
> WAL with this patch and 8 times less WAL with this patch +
> wal_compression=on.
> Index creation time, however, did not change much...
>
> About implementation:
> These are many types of record that can be generated during index build.
> I know for sure these are possible (double-checked using pg_waldump):
>
> SPLIT_COMPLETE
> INSERT
> SPLIT_ALLOCATE_PAGE
> SPLIT_PAGE
> ADD_OVFL_PAGE
> SQUEEZE_PAGE
> INIT_META_PAGE
> INIT_BITMAP_PAGE
>
>
> Looks like  SPLIT_COMPLETE and VACUUM_ONE_PAGE are never generated
> during index build. I'm not sure about  MOVE_PAGE_CONTENTS.
>
> So, implementation is simply pass isbuild flag everywhere something is
> wal-logged. Looks like it is less invasive than alternatives.
>
> --
> Best regards,
> Kirill Reshke
>


view thread (5+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: Use log_newpage_range in HASH index build
  In-Reply-To: <CAEvyyTjUTLXvrme3CNMjJYwA9j4usrq53PyBPv47Apk58Qz+GA@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox