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 <[email protected]>
Reviewed-by: Kirill Reshke <[email protected]>
Reviewed-by: Álvaro Herrera <[email protected]>
Discussion: https://postgr.es/m/[email protected]

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(-)

Reply via email to