pgsql: Fix calculation in brin_minmax_multi_distance_date

From: Tomas Vondra <tomas(dot)vondra(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix calculation in brin_minmax_multi_distance_date
Date: 2023-10-27 16:59:57
Message-ID: E1qwQBg-002dLW-N3@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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

Branch
------
REL_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/d1740e169d950d457907bbfa32f39f79c8504e20

Modified Files
--------------
src/backend/access/brin/brin_minmax_multi.c | 7 ++++++-
src/test/regress/expected/brin_multi.out | 20 ++++++++++++++++++++
src/test/regress/sql/brin_multi.sql | 18 ++++++++++++++++++
3 files changed, 44 insertions(+), 1 deletion(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Alexander Korotkov 2023-10-27 20:52:41 pgsql: Split event_trigger_login test from event_trigger test
Previous Message Tomas Vondra 2023-10-27 16:59:40 pgsql: Fix minmax-multi distance for extreme interval values