aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/gist
diff options
context:
space:
mode:
authorAlexander Korotkov <akorotkov@postgresql.org>2019-09-08 21:07:30 +0300
committerAlexander Korotkov <akorotkov@postgresql.org>2019-09-08 21:41:56 +0300
commit749b04d1d8b8ad63d365b8f6ad9d70843f3c1239 (patch)
treeaae42beca969a371f5af7733c67532d32445a418 /src/backend/access/gist
parent7babff18dc26506d4a05f75283ae621d3b8a1950 (diff)
downloadpostgresql-749b04d1d8b8ad63d365b8f6ad9d70843f3c1239.tar.gz
postgresql-749b04d1d8b8ad63d365b8f6ad9d70843f3c1239.zip
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
Diffstat (limited to 'src/backend/access/gist')
-rw-r--r--src/backend/access/gist/gistscan.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/backend/access/gist/gistscan.c b/src/backend/access/gist/gistscan.c
index 4d97ff1d5d2..deff8d59f7f 100644
--- a/src/backend/access/gist/gistscan.c
+++ b/src/backend/access/gist/gistscan.c
@@ -17,6 +17,7 @@
#include "access/gist_private.h"
#include "access/gistscan.h"
#include "access/relscan.h"
+#include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/rel.h"
@@ -36,8 +37,10 @@ pairingheap_GISTSearchItem_cmp(const pairingheap_node *a, const pairingheap_node
/* Order according to distance comparison */
for (i = 0; i < scan->numberOfOrderBys; i++)
{
- if (sa->distances[i] != sb->distances[i])
- return (sa->distances[i] < sb->distances[i]) ? 1 : -1;
+ int cmp = -float8_cmp_internal(sa->distances[i], sb->distances[i]);
+
+ if (cmp != 0)
+ return cmp;
}
/* Heap items go before inner pages, to ensure a depth-first search */