Fix BRIN minmax-multi distance for tid values

The distance function for tid values maps item pointers to float8 as

  (block * MaxHeapTuplesPerPage + offset)

but the multiplication was done in uint32 arithmetic, so for high block
values (above 14759338, ~112GB) the result wrapped around. The distance
would then be very inaccurate (possibly negative), resulting in a less
efficient index.

Fix by doing the arithmetics in double.

It's also possible the (user-supplied) item pointers have offsets
greater than MaxHeapTuplesPerPage, confusing the mapping to double
value. This commit does not try to address that, it's not clear what
would be a better mapping.

Author: Tomas Vondra <[email protected]>
Backpatch-through: 14
Discussion: 
https://postgr.es/m/CALdSSPgBvXz-VSF0p-5k%3D_uFfN38cWrERmm_AC4K67N6MWQhmg%40mail.gmail.com

Branch
------
REL_14_STABLE

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

Modified Files
--------------
src/backend/access/brin/brin_minmax_multi.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

Reply via email to