pgsql: amcheck: Fix checks of entry order for GIN indexes

From: Tomas Vondra <tomas(dot)vondra(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: amcheck: Fix checks of entry order for GIN indexes
Date: 2025-06-17 12:55:51
Message-ID: [email protected]
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

amcheck: Fix checks of entry order for GIN indexes

This tightens a couple checks in checking GIN indexes, which might have
resulted in incorrect results (false positives/negatives).

* The code skipped ordering checks if the entries were for different
attributes (for multi-column GIN indexes), possibly missing some cases
of data corruption. But the attribute number is part of the ordering,
so we can check that.

* The root page was skipped when checking entry order, but that is
unnecessary. The root page is subject to the same ordering rules, we
can process it just like any other page.

* The high key on the right-most page was not checked, but that is
needed only for inner pages (we don't store the high key for those).
For leaf pages we can check the high key just fine.

* Correct the detection of split pages. If the page gets split, the
cached parent key is greater than the current child key (not less, as
the code incorrectly expected).

Issues reported by Arseniy Mukhin, along with a proposed patch. Review
by Andrey M. Borodin, cleanup and improvements by me.

Author: Arseniy Mukhin <arseniy(dot)mukhin(dot)dev(at)gmail(dot)com>
Reviewed-by: Andrey M. Borodin <x4mmm(at)yandex-team(dot)ru>
Discussion: https://postgr.es/m/CAE7r3MJ611B9TE=YqBBncewp7-k64VWs+sjk7XF6fJUX77uFBA@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/0b54b392334b255abeac7c2718de7071600444ad

Modified Files
--------------
contrib/amcheck/meson.build | 1 +
contrib/amcheck/t/006_verify_gin.pl | 199 ++++++++++++++++++++++++++++++++++++
contrib/amcheck/verify_gin.c | 53 +++++-----
3 files changed, 229 insertions(+), 24 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tomas Vondra 2025-06-17 13:48:24 pgsql: amcheck: Fix parent key check in gin_index_check()
Previous Message Tomas Vondra 2025-06-17 12:23:55 pgsql: amcheck: Test gin_index_check on a multicolumn index