pgsql: amcheck: Fix parent key check in gin_index_check()

From: Tomas Vondra <tomas(dot)vondra(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: amcheck: Fix parent key check in gin_index_check()
Date: 2025-06-17 13:48:24
Message-ID: [email protected]
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

amcheck: Fix parent key check in gin_index_check()

The checks introduced by commit 14ffaece0fb5 did not get the parent key
checks quite right, missing some data corruption cases. In particular:

* The "rightlink" check was not working as intended, because rightlink
is a BlockNumber, and InvalidBlockNumber is 0xFFFFFFFF, so

!GinPageGetOpaque(page)->rightlink

almost always evaluates to false (except for rightlink=0). So in most
cases parenttup was left NULL, preventing any checks against parent.

* Use GinGetDownlink() to retrieve child blkno to avoid triggering
Assert, same as the core GIN code.

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/cdd1a431f21dbd2b7b675a9db1c24b97d713f38b

Modified Files
--------------
contrib/amcheck/t/006_verify_gin.pl | 78 +++++++++++++++++++++++++++++++++++++
contrib/amcheck/verify_gin.c | 8 ++--
2 files changed, 82 insertions(+), 4 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tomas Vondra 2025-06-17 14:52:24 pgsql: amcheck: Fix posting tree checks in gin_index_check()
Previous Message Tomas Vondra 2025-06-17 12:55:51 pgsql: amcheck: Fix checks of entry order for GIN indexes