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

Commitcfe1276

Browse files
committed
Use standard librart sqrt function in pg_stat_statements
The stddev calculation included a faster but unportable sqrt function.This is not worth the extra effort, and won't work everywhere. If thestandard library function is good enough for the SQL function itshould be good enough here too.
1 parent3a20b0e commitcfe1276

File tree

1 file changed

+2
-19
lines changed

1 file changed

+2
-19
lines changed

‎contrib/pg_stat_statements/pg_stat_statements.c

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
*/
5858
#include"postgres.h"
5959

60+
#include<math.h>
6061
#include<sys/stat.h>
6162
#include<unistd.h>
6263

@@ -326,7 +327,6 @@ static char *generate_normalized_query(pgssJumbleState *jstate, const char *quer
326327
int*query_len_p,intencoding);
327328
staticvoidfill_in_constant_lengths(pgssJumbleState*jstate,constchar*query);
328329
staticintcomp_location(constvoid*a,constvoid*b);
329-
staticinlinedoublesqrtd(constdoublex);
330330

331331

332332
/*
@@ -1583,7 +1583,7 @@ pg_stat_statements_internal(FunctionCallInfo fcinfo,
15831583
*/
15841584
if (tmp.calls>1)
15851585
values[i++]=
1586-
Float8GetDatum(sqrtd(tmp.sum_var_time /tmp.calls));
1586+
Float8GetDatum(sqrt(tmp.sum_var_time /tmp.calls));
15871587
else
15881588
values[i++]=Float8GetDatum(0.0);
15891589
}
@@ -2968,20 +2968,3 @@ comp_location(const void *a, const void *b)
29682968
else
29692969
return0;
29702970
}
2971-
2972-
/*
2973-
* fast sqrt algorithm: reference from Fast inverse square root algorithms.
2974-
*/
2975-
staticinlinedouble
2976-
sqrtd(constdoublex)
2977-
{
2978-
doublex_half=0.5*x;
2979-
long longinttmp=0x5FE6EB50C7B537AAl- (*(long longint*)&x >>1);
2980-
doublex_result=* (double*)&tmp;
2981-
2982-
x_result *= (1.5- (x_half*x_result*x_result));
2983-
/* If retry this calculation, it becomes higher precision at sqrt */
2984-
x_result *= (1.5- (x_half*x_result*x_result));
2985-
2986-
returnx_result*x;
2987-
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp