Fix BRIN minmax-multi distance calculation for OID The oid_minmax_multi_ops opclass simply calculated the distance using brin_minmax_multi_distance_int4. That however interprets the values as int32, so OIDs above PG_INT32_MAX were treated as negative values, and ranges crossing the boundary ended with a negative distance.
With assert-enabled guild, this tripped the (a1 <= a2) check. Without asserts, the index was less efficient. Fix by introducing brin_minmax_multi_distance_oid, correctly treating the OID values as unsigned. This required a catalog change (and catversion bump), so it can't be backpatched. It'd be possible to adjust brin_minmax_multi_distance_int4 to handle the (a1 > a2) case differently. But that'd lose the assert, and it does not seem worth it (indexes on OIDs don't seem very common). Author: Tomas Vondra <[email protected]> Reviewed-by: Kirill Reshke <[email protected]> Reviewed-by: shihao zhong <[email protected]> Discussion: https://postgr.es/m/CALdSSPgBvXz-VSF0p-5k%3D_uFfN38cWrERmm_AC4K67N6MWQhmg%40mail.gmail.com Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/4b6735c21fa4c43be041c6c610d7be6463c2c1f9 Modified Files -------------- src/backend/access/brin/brin_minmax_multi.c | 21 +++++++++++++++++++++ src/include/catalog/pg_amproc.dat | 2 +- src/include/catalog/pg_proc.dat | 4 ++++ src/test/regress/expected/brin_multi.out | 5 +++++ src/test/regress/sql/brin_multi.sql | 8 ++++++++ 5 files changed, 39 insertions(+), 1 deletion(-)
