Skip to content

Commit 111fb7e

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 96db9d5 commit 111fb7e

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/memutils.h"
2122
#include "utils/rel.h"
2223

@@ -36,8 +37,10 @@ GISTSearchTreeItemComparator(const RBNode *a, const RBNode *b, void *arg)
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
return 0;

0 commit comments

Comments
 (0)