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....@gmail.com>
Reviewed-by: Andrey M. Borodin <x4...@yandex-team.ru>
Discussion: 
https://postgr.es/m/CAE7r3MJ611B9TE=yqbbncewp7-k64vws+sjk7xf6fjux77u...@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(-)

Reply via email to