pgsql: Fix REPACK with WITHOUT OVERLAPS replica identity indexes

From: Álvaro Herrera <alvherre(at)kurilemu(dot)de>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix REPACK with WITHOUT OVERLAPS replica identity indexes
Date: 2026-05-11 16:19:57
Message-ID: E1wMTMK-00041D-2U@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix REPACK with WITHOUT OVERLAPS replica identity indexes

REPACK replay builds scan keys for the replica identity index, but it
hard-coded BTEqualStrategyNumber when looking up the equality operator.
That is not correct for non-btree identity indexes, such as the GiST
indexes created for WITHOUT OVERLAPS primary keys. In addition,
find_target_tuple() accepted the first tuple returned by the identity
index scan, which is unsafe for lossy index scans because the index AM may
return false positives with xs_recheck set.

Fix this by using IndexAmTranslateCompareType() to translate COMPARE_EQ
to the equality strategy number for the index AM, and by continuing the
scan when recheck is required until a candidate tuple matches the locator
tuple on all replica identity key columns.

The recheck uses the same equality operator functions as the identity
index scan keys, preserving ScanKey argument ordering.

Author: Chao Li <lic(at)highgo(dot)com>
Reviewed-by: Kirill Reshke <reshkekirill(at)gmail(dot)com>
Reviewed-by: Álvaro Herrera <alvherre(at)kurilemu(dot)de>
Discussion: https://postgr.es/m/7B0EC0EC-5461-41EF-9B31-F9BBE608DEA5@gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/36f52a59b31502213a01fb4b0a89afc0f3bfd21d

Modified Files
--------------
src/backend/commands/repack.c | 85 +++++++++++++++--
src/test/modules/injection_points/Makefile | 2 +
.../injection_points/expected/repack_temporal.out | 68 ++++++++++++++
.../expected/repack_temporal_multirange.out | 74 +++++++++++++++
src/test/modules/injection_points/meson.build | 2 +
.../injection_points/specs/repack_temporal.spec | 90 ++++++++++++++++++
.../specs/repack_temporal_multirange.spec | 102 +++++++++++++++++++++
7 files changed, 417 insertions(+), 6 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Heikki Linnakangas 2026-05-11 18:41:57 pgsql: Use palloc_array() in a few more places to avoid overflow
Previous Message Tom Lane 2026-05-11 16:12:21 pgsql: Remove test cases for field overflows in intarray and ltree.