]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix calculation in brin_minmax_multi_distance_date
authorTomas Vondra <tomas.vondra@postgresql.org>
Fri, 27 Oct 2023 15:57:11 +0000 (17:57 +0200)
committerTomas Vondra <tomas.vondra@postgresql.org>
Fri, 27 Oct 2023 16:28:19 +0000 (18:28 +0200)
commite7965226d5518796cb2c1a48635ae92b5fe4e6ef
tree14e74f984efc3e0cf43cfe96be0761f9a3433682
parent0635fe02b426573d62e2389cf90b688c285f072a
Fix calculation in brin_minmax_multi_distance_date

When calculating the distance between date values, make sure to subtract
them in the right order, i.e. (larger - smaller).

The distance is used to determine which values to merge, and is expected
to be a positive value. The code unfortunately did the subtraction in
the opposite order, i.e. (smaller - larger), thus producing negative
values and merging values the most distant values first.

The resulting index is correct (i.e. produces correct results), but may
be significantly less efficient. This affects all minmax-multi indexes
on date columns.

Backpatch to 14, where minmax-multi indexes were introduced.

Reported-by: Ashutosh Bapat
Reviewed-by: Ashutosh Bapat, Dean Rasheed
Backpatch-through: 14
Discussion: https://postgr.es/m/eef0ea8c-4aaa-8d0d-027f-58b1f35dd170@enterprisedb.com
src/backend/access/brin/brin_minmax_multi.c
src/test/regress/expected/brin_multi.out
src/test/regress/sql/brin_multi.sql