Skip to content

Commit 8f72400

Browse files
committed
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
1 parent 7db4516 commit 8f72400

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/backend/access/gist/gistscan.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "access/gist_private.h"
1818
#include "access/gistscan.h"
1919
#include "access/relscan.h"
20+
#include "utils/builtins.h"
2021
#include "utils/lsyscache.h"
2122
#include "utils/memutils.h"
2223
#include "utils/rel.h"
@@ -36,8 +37,10 @@ pairingheap_GISTSearchItem_cmp(const pairingheap_node *a, const pairingheap_node
3637
/* Order according to distance comparison */
3738
for (i = 0; i < scan->numberOfOrderBys; i++)
3839
{
39-
if (sa->distances[i] != sb->distances[i])
40-
return (sa->distances[i] < sb->distances[i]) ? 1 : -1;
40+
int cmp = -float8_cmp_internal(sa->distances[i], sb->distances[i]);
41+
42+
if (cmp != 0)
43+
return cmp;
4144
}
4245

4346
/* Heap items go before inner pages, to ensure a depth-first search */

0 commit comments

Comments
 (0)