Re: [GSoC 2026] - B-tree Index Bloat Reduction - Approach & Questions

From: Salma Elsayed <salmasayed182003(at)gmail(dot)com>
To: Nikolay Samokhvalov <nik(at)postgres(dot)ai>
Cc: pgsql-hackers mailing list <pgsql-hackers(at)postgresql(dot)org>, Kirk Wolak <wolakk(at)gmail(dot)com>, obartunov(at)gmail(dot)com, Peter Geoghegan <pg(at)bowt(dot)ie>, Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com>, Andrey Borodin <x4mmm(at)yandex-team(dot)ru>, Andreas Karlsson <andreas(at)proxel(dot)se>
Subject: Re: [GSoC 2026] - B-tree Index Bloat Reduction - Approach & Questions
Date: 2026-11-25 13:36:02
Message-ID: CANBEAPFtn=1W0VzyqZyxo8q5YgrfTOXksy4LzGbqX3M4D2Hegw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Nik,

Thanks for retesting v4 and for the report about test 007. Attached is
v5 (3 patches), rebased on current master.

1.) What changed since v4

a. Test 007 now starts pg_waldump without the shell, so it works when
the data directory has a space in its path. Thanks for the report.

b. The backward parallel scan deadlock I mentioned in v4. The worker
that walks the merge group kept the shared scan while the other
workers waited for it. Now it releases the shared scan first. I added
a test with wide rows.

c. amcheck now checks merge groups (#110 [1]). It reports an error if
an MA page has bad links or a bad boundary key, if an M page points to
a page that is not an MA page, or if an M page does not come right
after its MA page. Test 009 breaks each case on disk and checks that
amcheck finds it.

---

2.) VACUUM did not clean up MA pages

Oleg Bartunov found that VACUUM never cleans up MA pages when there
are no dead heap tuples. Then VACUUM does not scan the index, and
bt_merge() did not tell it that there is work to do. With 272 merged
pages, three VACUUMs left all of them behind.

Now the metapage keeps a count of MA pages. bt_merge() adds to it,
VACUUM subtracts one for each MA page it cleans up, and VACUUM scans
the index while the count is above zero. My old test always had a dead
tuple before VACUUM, so it hid this. Test 008 now uses plain VACUUMs.

---

Known limit: if bt_merge() is cancelled, the pages it already merged
are not counted.

All tests pass on top of master. Most of the tests were written with
the help of AI.

Thanks to Nik for the issues and the tests, and to Oleg Bartunov for
finding the VACUUM problem.

[1] https://github.com/NikolayS/postgres/issues/110

Best regards,
Salma Elsayed

Attachment Content-Type Size
v5-0002-pageinspect-add-functions-to-find-and-merge-B-tre.patch text/x-patch 37.9 KB
v5-0001-nbtree-merge-nearly-empty-leaf-pages.patch text/x-patch 122.6 KB
v5-0003-amcheck-verify-merged-B-tree-pages-and-add-merge-.patch text/x-patch 105.0 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Previous Message Jim Jones 2026-11-25 13:34:57 Re: OOM kill in xmlelement() with large arrays