Skip to content

Commit 2c33e0f

Browse files
committed
Better fix for misuse of Float8GetDatumFast().
We can use that macro as long as we put the value into a local variable. Commit 735cd61 was not wrong on its own terms, but I think this way looks nicer, and it should save a few cycles on 32-bit machines.
1 parent 7655f4c commit 2c33e0f

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

contrib/pg_stat_statements/pg_stat_statements.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,7 +1246,6 @@ pgss_store(const char *query, uint32 queryId,
12461246
e->counters.min_time = total_time;
12471247
if (e->counters.max_time < total_time)
12481248
e->counters.max_time = total_time;
1249-
12501249
}
12511250
e->counters.rows += rows;
12521251
e->counters.shared_blks_hit += bufusage->shared_blks_hit;
@@ -1491,6 +1490,7 @@ pg_stat_statements_internal(FunctionCallInfo fcinfo,
14911490
bool nulls[PG_STAT_STATEMENTS_COLS];
14921491
int i = 0;
14931492
Counters tmp;
1493+
double stddev;
14941494
int64 queryid = entry->key.queryid;
14951495

14961496
memset(values, 0, sizeof(values));
@@ -1577,15 +1577,12 @@ pg_stat_statements_internal(FunctionCallInfo fcinfo,
15771577
* sample variance, as we have data for the whole population,
15781578
* so Bessel's correction is not used, and we don't divide by
15791579
* tmp.calls - 1.
1580-
*
1581-
* We're calculating the stddev on the fly, so it's not in the tmp
1582-
* structure, so we can't use the Float8GetDatumFast macro here.
15831580
*/
15841581
if (tmp.calls > 1)
1585-
values[i++] =
1586-
Float8GetDatum(sqrt(tmp.sum_var_time / tmp.calls));
1582+
stddev = sqrt(tmp.sum_var_time / tmp.calls);
15871583
else
1588-
values[i++] = Float8GetDatum(0.0);
1584+
stddev = 0.0;
1585+
values[i++] = Float8GetDatumFast(stddev);
15891586
}
15901587
values[i++] = Int64GetDatumFast(tmp.rows);
15911588
values[i++] = Int64GetDatumFast(tmp.shared_blks_hit);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy