amcheck: Fix checks of entry order for GIN indexes
authorTomas Vondra <tomas.vondra@postgresql.org>
Tue, 17 Jun 2025 12:55:27 +0000 (14:55 +0200)
committerTomas Vondra <tomas.vondra@postgresql.org>
Tue, 17 Jun 2025 12:55:29 +0000 (14:55 +0200)
commit0b54b392334b255abeac7c2718de7071600444ad
treeb9186d640a193a1fb6e22ff962a4a3bb9b763448
parent8dd41c0bff5b6944fb536cf8f2627d5f542581cd
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.mukhin.dev@gmail.com>
Reviewed-by: Andrey M. Borodin <x4mmm@yandex-team.ru>
Discussion: http://postgr.es/m/CAE7r3MJ611B9TE=YqBBncewp7-k64VWs+sjk7XF6fJUX77uFBA@mail.gmail.com
contrib/amcheck/meson.build
contrib/amcheck/t/006_verify_gin.pl [new file with mode: 0644]
contrib/amcheck/verify_gin.c