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

Commit32cf7f7

Browse files
committed
Improve performance of float overflow checks in btree_gist
The current code could do unnecessary calls to isinf() (two for theargument values all the time while one could be sufficient in somecases). zero_is_valid was never used but the result value was stillchecked on 0 in the first position of the check.This is similar to607f8ce. btree_gist has just copy-pasted the codedoing those checks from the backend float4/8 code, as of the macroCHECKFLOATVAL(), to do the work.Author: Haiying TangDiscussion:https://postgr.es/m/OS0PR01MB611358E3A7BC3C2F874AC36BFBF39@OS0PR01MB6113.jpnprd01.prod.outlook.com
1 parent2576dcf commit32cf7f7

File tree

3 files changed

+8
-21
lines changed

3 files changed

+8
-21
lines changed

‎contrib/btree_gist/btree_float4.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include"btree_gist.h"
77
#include"btree_utils_num.h"
8+
#include"utils/float.h"
89

910
typedefstructfloat4key
1011
{
@@ -98,7 +99,8 @@ float4_dist(PG_FUNCTION_ARGS)
9899
float4r;
99100

100101
r=a-b;
101-
CHECKFLOATVAL(r,isinf(a)||isinf(b), true);
102+
if (unlikely(isinf(r))&& !isinf(a)&& !isinf(b))
103+
float_overflow_error();
102104

103105
PG_RETURN_FLOAT4(Abs(r));
104106
}

‎contrib/btree_gist/btree_float8.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include"btree_gist.h"
77
#include"btree_utils_num.h"
8+
#include"utils/float.h"
89

910
typedefstructfloat8key
1011
{
@@ -76,8 +77,8 @@ gbt_float8_dist(const void *a, const void *b, FmgrInfo *flinfo)
7677
float8r;
7778

7879
r=arg1-arg2;
79-
CHECKFLOATVAL(r,isinf(arg1)||isinf(arg2), true);
80-
80+
if (unlikely(isinf(r))&& !isinf(arg1)&& !isinf(arg2))
81+
float_overflow_error();
8182
returnAbs(r);
8283
}
8384

@@ -106,7 +107,8 @@ float8_dist(PG_FUNCTION_ARGS)
106107
float8r;
107108

108109
r=a-b;
109-
CHECKFLOATVAL(r,isinf(a)||isinf(b), true);
110+
if (unlikely(isinf(r))&& !isinf(a)&& !isinf(b))
111+
float_overflow_error();
110112

111113
PG_RETURN_FLOAT8(Abs(r));
112114
}

‎contrib/btree_gist/btree_utils_num.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,23 +89,6 @@ typedef struct
8989

9090
#defineGET_FLOAT_DISTANCE(t,arg1,arg2)Abs( ((float8) *((const t *) (arg1))) - ((float8) *((const t *) (arg2))) )
9191

92-
/*
93-
* check to see if a float4/8 val has underflowed or overflowed
94-
* borrowed from src/backend/utils/adt/float.c
95-
*/
96-
#defineCHECKFLOATVAL(val,inf_is_valid,zero_is_valid)\
97-
do {\
98-
if (isinf(val) && !(inf_is_valid))\
99-
ereport(ERROR,\
100-
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),\
101-
errmsg("value out of range: overflow")));\
102-
\
103-
if ((val) == 0.0 && !(zero_is_valid))\
104-
ereport(ERROR,\
105-
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),\
106-
errmsg("value out of range: underflow")));\
107-
} while(0)
108-
10992

11093
externInterval*abs_interval(Interval*a);
11194

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp