pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tomas Vondra <tomas.vondra@enterprisedb.com>
To: Justin Pryzby <pryzby@telsasoft.com>
To: Andreas Seltenreich <andreas.seltenreich@credativ.de>
Cc: pgsql-hackers@postgresql.org, Jaime Casanova <jcasanov@systemguards.com.ec>
Subject: Re: [sqlsmith] Failed assertion in brin_minmax_multi_distance_float4 on REL_14_STABLE
Date: Fri, 5 Nov 2021 02:10:55 +0100
Message-ID: <ee0f263c-5399-0810-dfeb-5edcd028e795@enterprisedb.com> (raw)
In-Reply-To: <668dc67a-9baf-e4ab-88b0-2c39c6a2f08e@enterprisedb.com>
References: <87r1bw9ukm.fsf@credativ.de>
	<20211104165357.GU17618@telsasoft.com>
	<83b2e911-ccd9-5503-fb32-369050a6e93d@enterprisedb.com>
	<668dc67a-9baf-e4ab-88b0-2c39c6a2f08e@enterprisedb.com>



On 11/5/21 02:09, Tomas Vondra wrote:
>
> Here's a patch that should fix this. 
 >

Meh, forgot the attachment, ofc.

-- 
Tomas Vondra
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

Attachments:

  [text/x-patch] brin-fix.patch (1.5K, ../ee0f263c-5399-0810-dfeb-5edcd028e795@enterprisedb.com/2-brin-fix.patch)
  download | inline diff:
diff --git a/src/backend/access/brin/brin_minmax_multi.c b/src/backend/access/brin/brin_minmax_multi.c
index ee6c4795f1..a85dfdfec4 100644
--- a/src/backend/access/brin/brin_minmax_multi.c
+++ b/src/backend/access/brin/brin_minmax_multi.c
@@ -73,6 +73,7 @@
 #include "utils/builtins.h"
 #include "utils/date.h"
 #include "utils/datum.h"
+#include "utils/float.h"
 #include "utils/inet.h"
 #include "utils/lsyscache.h"
 #include "utils/memutils.h"
@@ -1872,6 +1873,14 @@ brin_minmax_multi_distance_float4(PG_FUNCTION_ARGS)
 	float		a1 = PG_GETARG_FLOAT4(0);
 	float		a2 = PG_GETARG_FLOAT4(1);
 
+	/* if both values are NaN, then we consider them the same */
+	if (isnan(a1) && isnan(a2))
+		PG_RETURN_FLOAT8(0.0);
+
+	/* if one value is NaN, use infinite distance */
+	if (isnan(a1) || isnan(a2))
+		PG_RETURN_FLOAT8(get_float8_infinity());
+
 	/*
 	 * We know the values are range boundaries, but the range may be collapsed
 	 * (i.e. single points), with equal values.
@@ -1890,6 +1899,14 @@ brin_minmax_multi_distance_float8(PG_FUNCTION_ARGS)
 	double		a1 = PG_GETARG_FLOAT8(0);
 	double		a2 = PG_GETARG_FLOAT8(1);
 
+	/* if both values are NaN, then we consider them the same */
+	if (isnan(a1) && isnan(a2))
+		PG_RETURN_FLOAT8(0.0);
+
+	/* if one value is NaN, use infinite distance */
+	if (isnan(a1) || isnan(a2))
+		PG_RETURN_FLOAT8(get_float8_infinity());
+
 	/*
 	 * We know the values are range boundaries, but the range may be collapsed
 	 * (i.e. single points), with equal values.


view thread (5+ messages)

Message-ID: <ee0f263c-5399-0810-dfeb-5edcd028e795@enterprisedb.com>
Permalink:  ../ee0f263c-5399-0810-dfeb-5edcd028e795@enterprisedb.com/
Also on:    postgresql.org/message-id/ee0f263c-5399-0810-dfeb-5edcd028e795@enterprisedb.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: tomas.vondra@enterprisedb.com, pryzby@telsasoft.com, andreas.seltenreich@credativ.de, jcasanov@systemguards.com.ec
  Subject: Re: [sqlsmith] Failed assertion in brin_minmax_multi_distance_float4 on REL_14_STABLE
  In-Reply-To: <ee0f263c-5399-0810-dfeb-5edcd028e795@enterprisedb.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox