Skip to content

Commit

Permalink
Match the Postgres NaN behavior in vectorized filters (#7598)
Browse files Browse the repository at this point in the history
It has some nonstandard rules that don't match the IEEE floats.

(cherry picked from commit f0996a4)
  • Loading branch information
akuzm authored and timescale-automation committed Jan 22, 2025
1 parent 6f2aa30 commit 236ede2
Show file tree
Hide file tree
Showing 4 changed files with 1,365 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .unreleased/nan-vectorized-filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixes: #6884 Match the Postgres NaN comparison behavior in WHERE clause over compressed tables.
Thanks: @jakehedlund for reporting the incompatible NaN behavior in WHERE clause over compressed tables.
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,32 @@
*/

/*
* Vector-const predicates for one pair of arithmetic types.
* Vector-const predicates for one pair of arithmetic types. For NaN comparison,
* Postgres has its own nonstandard rules different from the IEEE floats.
*/

#define PREDICATE_NAME GE
#define PREDICATE_EXPRESSION(X, Y) ((X) >= (Y))
#define PREDICATE_EXPRESSION(X, Y) (isnan((double) (X)) || (!isnan((double) (Y)) && (X) >= (Y)))
#include "pred_vector_const_arithmetic_single.c"

#define PREDICATE_NAME LE
#define PREDICATE_EXPRESSION(X, Y) ((X) <= (Y))
#define PREDICATE_EXPRESSION(X, Y) (isnan((double) (Y)) || (!isnan((double) (X)) && (X) <= (Y)))
#include "pred_vector_const_arithmetic_single.c"

#define PREDICATE_NAME LT
#define PREDICATE_EXPRESSION(X, Y) ((X) < (Y))
#define PREDICATE_EXPRESSION(X, Y) (!isnan((double) (X)) && (isnan((double) (Y)) || (X) < (Y)))
#include "pred_vector_const_arithmetic_single.c"

#define PREDICATE_NAME GT
#define PREDICATE_EXPRESSION(X, Y) ((X) > (Y))
#define PREDICATE_EXPRESSION(X, Y) (!isnan((double) (Y)) && (isnan((double) (X)) || (X) > (Y)))
#include "pred_vector_const_arithmetic_single.c"

#define PREDICATE_NAME EQ
#define PREDICATE_EXPRESSION(X, Y) ((X) == (Y))
#define PREDICATE_EXPRESSION(X, Y) (isnan((double) (X)) ? isnan((double) (Y)) : ((X) == (Y)))
#include "pred_vector_const_arithmetic_single.c"

#define PREDICATE_NAME NE
#define PREDICATE_EXPRESSION(X, Y) ((X) != (Y))
#define PREDICATE_EXPRESSION(X, Y) (isnan((double) (X)) ? !isnan((double) (Y)) : ((X) != (Y)))
#include "pred_vector_const_arithmetic_single.c"

#undef VECTOR_CTYPE
Expand Down
Loading

0 comments on commit 236ede2

Please sign in to comment.