postgres.git / summary / log / commit / refs

commit    0b0d3c19bf077e96ac4a175bf7ea7093e0eac416
Author:   Tom Lane <tgl@sss.pgh.pa.us>
Date:     Tue Aug 05 20:51:10 2025 +0000
First released in: 14.19, 15.14, 16.10, 17.6, 18.0

    Fix incorrect return value in brin_minmax_multi_distance_numeric().
    
    The result of "DirectFunctionCall1(numeric_float8, d)" is already in
    Datum form, but the code was incorrectly applying PG_RETURN_FLOAT8()
    to it.  On machines where float8 is pass-by-reference, this would
    result in complete garbage, since an unpredictable pointer value
    would be treated as an integer and then converted to float.  It's not
    entirely clear how much of a problem would ensue on 64-bit hardware,
    but certainly interpreting a float8 bitpattern as uint64 and then
    converting that to float isn't the intended behavior.
    
    As luck would have it, even the complete-garbage case doesn't break
    BRIN indexes, since the results are only used to make choices about
    how to merge values into ranges: at worst, we'd make poor choices
    resulting in an inefficient index.  Doubtless that explains the lack
    of field complaints.  However, users with BRIN indexes that use the
    numeric_minmax_multi_ops opclass may wish to reindex in hopes of
    making their indexes more efficient.
    
    Author: Peter Eisentraut <peter@eisentraut.org>
    Co-authored-by: Tom Lane <tgl@sss.pgh.pa.us>
    Discussion: https://postgr.es/m/2093712.1753983215@sss.pgh.pa.us
    Backpatch-through: 14


src/backend/access/brin/brin_minmax_multi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/access/brin/brin_minmax_multi.c b/src/backend/access/brin/brin_minmax_multi.c index 8a13cd59c0b..b88e9b2d7cc 100644 --- a/src/backend/access/brin/brin_minmax_multi.c +++ b/src/backend/access/brin/brin_minmax_multi.c @@ -2032,7 +2032,7 @@ brin_minmax_multi_distance_numeric(PG_FUNCTION_ARGS) d = DirectFunctionCall2(numeric_sub, a2, a1); /* a2 - a1 */ - PG_RETURN_FLOAT8(DirectFunctionCall1(numeric_float8, d)); + PG_RETURN_DATUM(DirectFunctionCall1(numeric_float8, d)); } /* [parent: 74dffe5c14ac]