diff options
author | Michael Paquier <michael@paquier.xyz> | 2021-08-19 10:42:44 +0900 |
---|---|---|
committer | Michael Paquier <michael@paquier.xyz> | 2021-08-19 10:42:44 +0900 |
commit | 32cf7f7acce3891cbc3de53327704372bdd36d38 (patch) | |
tree | 6bce685687873526523c6059fccc348cd4f53c30 /contrib/btree_gist/btree_float8.c | |
parent | 2576dcfb76aa71e4222bac5a3a43f71875bfa9e8 (diff) | |
download | postgresql-32cf7f7acce3891cbc3de53327704372bdd36d38.tar.gz postgresql-32cf7f7acce3891cbc3de53327704372bdd36d38.zip |
Improve performance of float overflow checks in btree_gist
The current code could do unnecessary calls to isinf() (two for the
argument values all the time while one could be sufficient in some
cases). zero_is_valid was never used but the result value was still
checked on 0 in the first position of the check.
This is similar to 607f8ce. btree_gist has just copy-pasted the code
doing those checks from the backend float4/8 code, as of the macro
CHECKFLOATVAL(), to do the work.
Author: Haiying Tang
Discussion: https://postgr.es/m/OS0PR01MB611358E3A7BC3C2F874AC36BFBF39@OS0PR01MB6113.jpnprd01.prod.outlook.com
Diffstat (limited to 'contrib/btree_gist/btree_float8.c')
-rw-r--r-- | contrib/btree_gist/btree_float8.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/contrib/btree_gist/btree_float8.c b/contrib/btree_gist/btree_float8.c index 10a5262aaa7..8fe1fedeef8 100644 --- a/contrib/btree_gist/btree_float8.c +++ b/contrib/btree_gist/btree_float8.c @@ -5,6 +5,7 @@ #include "btree_gist.h" #include "btree_utils_num.h" +#include "utils/float.h" typedef struct float8key { @@ -76,8 +77,8 @@ gbt_float8_dist(const void *a, const void *b, FmgrInfo *flinfo) float8 r; r = arg1 - arg2; - CHECKFLOATVAL(r, isinf(arg1) || isinf(arg2), true); - + if (unlikely(isinf(r)) && !isinf(arg1) && !isinf(arg2)) + float_overflow_error(); return Abs(r); } @@ -106,7 +107,8 @@ float8_dist(PG_FUNCTION_ARGS) float8 r; r = a - b; - CHECKFLOATVAL(r, isinf(a) || isinf(b), true); + if (unlikely(isinf(r)) && !isinf(a) && !isinf(b)) + float_overflow_error(); PG_RETURN_FLOAT8(Abs(r)); } |