Fix BRIN numeric_minmax_multi_ops out of range value range merging

From: Kirill Reshke <reshkekirill(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Fix BRIN numeric_minmax_multi_ops out of range value range merging
Date: 2026-10-27 18:59:25
Message-ID: CALdSSPgBvXz-VSF0p-5k=_uFfN38cWrERmm_AC4K67N6MWQhmg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi
While reviewing some reports in pgsql-bugs I bumped into simple SQL
reproduced of BRIN out of range issue

CREATE TABLE t (n numeric);
INSERT INTO t VALUES (1), (1e1000);
CREATE INDEX ON t USING brin (n numeric_minmax_multi_ops);

This fails. brin_minmax_multi_distance_numeric computes heuristic, so
it can be approximated. Patch uses numeric_sub_safe with an
ErrorSaveContext and returns inf if any error occurred (which can only
be an overflow in current code base, see make_result_safe)

The numeric-distance overflow risk was discussed during the original
minmax-multi development in 2018 [0], with normalizing value into 0-1
range. I didn't fix that way, the issue fixed in the current
implementation.

[0] https://www.postgresql.org/message-id/9b7551f2-93fb-3708-2705-35c42f0e6734@2ndquadrant.com

--
Best regards,
Kirill Reshke

Attachment Content-Type Size
fix-t227-brin-minmax-multi-numeric-distance-v2.diff application/octet-stream 2.0 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message shihao zhong 2026-10-27 19:08:30 Re: First draft of PG 19 release notes
Previous Message Sami Imseih 2026-10-27 18:56:16 Re: Report buffer access strategies in EXPLAIN