Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbc67f41

Browse files
committed
Fix handling Inf and Nan values in GiST pairing heap comparator
Previously plain float comparison was used in GiST pairing heap. Suchcomparison doesn't provide proper ordering for value sets containing Inf and Nanvalues. This commit fixes that by usage of float8_cmp_internal(). Note, thereis remaining problem with NULL distances, which are represented as Inf inpairing heap. It would be fixes in subsequent commit.Backpatch to all supported versions.Reported-by: Andrey BorodinDiscussion:https://postgr.es/m/CAPpHfdsNvNdA0DBS%2BwMpFrgwT6C3-q50sFVGLSiuWnV3FqOJuQ%40mail.gmail.comAuthor: Alexander KorotkovReviewed-by: Heikki LinnakangasBackpatch-through: 9.4
1 parentb6d72dd commitbc67f41

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
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/float.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+
intcmp=-float8_cmp_internal(sa->distances[i],sb->distances[i]);
41+
42+
if (cmp!=0)
43+
returncmp;
4144
}
4245

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

‎src/test/regress/expected/create_index.out

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -523,16 +523,16 @@ SELECT * FROM point_tbl ORDER BY f1 <-> '0,1';
523523
SELECT * FROM point_tbl ORDER BY f1 <-> '0,1';
524524
f1
525525
-------------------
526-
(10,10)
527-
(NaN,NaN)
528526
(0,0)
529527
(1e-300,-1e-300)
530528
(-3,4)
531529
(-10,0)
530+
(10,10)
532531
(-5,-12)
533532
(5.1,34.5)
534-
535533
(1e+300,Infinity)
534+
535+
(NaN,NaN)
536536
(10 rows)
537537

538538
EXPLAIN (COSTS OFF)
@@ -561,15 +561,15 @@ SELECT * FROM point_tbl WHERE f1 IS NOT NULL ORDER BY f1 <-> '0,1';
561561
SELECT * FROM point_tbl WHERE f1 IS NOT NULL ORDER BY f1 <-> '0,1';
562562
f1
563563
-------------------
564-
(10,10)
565-
(NaN,NaN)
566564
(0,0)
567565
(1e-300,-1e-300)
568566
(-3,4)
569567
(-10,0)
568+
(10,10)
570569
(-5,-12)
571570
(5.1,34.5)
572571
(1e+300,Infinity)
572+
(NaN,NaN)
573573
(9 rows)
574574

575575
EXPLAIN (COSTS OFF)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp