1
0
mirror of https://github.com/postgres/postgres.git synced 2025-05-06 19:59:18 +03:00

Fix handling Inf and Nan values in GiST pairing heap comparator

Previously plain float comparison was used in GiST pairing heap.  Such
comparison doesn't provide proper ordering for value sets containing Inf and Nan
values.  This commit fixes that by usage of float8_cmp_internal().  Note, there
is remaining problem with NULL distances, which are represented as Inf in
pairing heap.  It would be fixes in subsequent commit.

Backpatch to all supported versions.

Reported-by: Andrey Borodin
Discussion: https://postgr.es/m/CAPpHfdsNvNdA0DBS%2BwMpFrgwT6C3-q50sFVGLSiuWnV3FqOJuQ%40mail.gmail.com
Author: Alexander Korotkov
Reviewed-by: Heikki Linnakangas
Backpatch-through: 9.4
This commit is contained in:
Alexander Korotkov 2019-09-08 21:07:30 +03:00
parent 7babff18dc
commit 749b04d1d8

View File

@ -17,6 +17,7 @@
#include "access/gist_private.h" #include "access/gist_private.h"
#include "access/gistscan.h" #include "access/gistscan.h"
#include "access/relscan.h" #include "access/relscan.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h" #include "utils/lsyscache.h"
#include "utils/memutils.h" #include "utils/memutils.h"
#include "utils/rel.h" #include "utils/rel.h"
@ -36,8 +37,10 @@ pairingheap_GISTSearchItem_cmp(const pairingheap_node *a, const pairingheap_node
/* Order according to distance comparison */ /* Order according to distance comparison */
for (i = 0; i < scan->numberOfOrderBys; i++) for (i = 0; i < scan->numberOfOrderBys; i++)
{ {
if (sa->distances[i] != sb->distances[i]) int cmp = -float8_cmp_internal(sa->distances[i], sb->distances[i]);
return (sa->distances[i] < sb->distances[i]) ? 1 : -1;
if (cmp != 0)
return cmp;
} }
/* Heap items go before inner pages, to ensure a depth-first search */ /* Heap items go before inner pages, to ensure a depth-first search */