git.postgresql.org Git - postgresql.git/commitdiff

git projects / postgresql.git / commitdiff
? search:
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f18795e)
Fix pgstatindex() to give consistent results for empty indexes.
2011年8月25日 03:50:10 +0000 (23:50 -0400)
2011年8月25日 03:50:10 +0000 (23:50 -0400)
For an empty index, the pgstatindex() function would compute 0.0/0.0 for
its avg_leaf_density and leaf_fragmentation outputs. On machines that
follow the IEEE float arithmetic standard with any care, that results in
a NaN. However, per report from Rushabh Lathia, Microsoft couldn't
manage to get this right, so you'd get a bizarre error on Windows.

Fix by forcing the results to be NaN explicitly, rather than relying on
the division operator to give that or the snprintf function to print it
correctly. I have some doubts that this is really the most useful
definition, but it seems better to remain backward-compatible with
those platforms for which the behavior wasn't completely broken.

Back-patch to 8.2, since the code is like that in all current releases.


diff --git a/contrib/pgstattuple/pgstatindex.c b/contrib/pgstattuple/pgstatindex.c
index f0d6341bd16145847a32f6c0a024086ff39a3f07..178065ceda57f91142675966a939889a4d2eed29 100644 (file)
--- a/contrib/pgstattuple/pgstatindex.c
+++ b/contrib/pgstattuple/pgstatindex.c
@@ -235,9 +235,17 @@ pgstatindex(PG_FUNCTION_ARGS)
values[j] = palloc(32);
snprintf(values[j++], 32, INT64_FORMAT, indexStat.deleted_pages);
values[j] = palloc(32);
- snprintf(values[j++], 32, "%.2f", 100.0 - (double) indexStat.free_space / (double) indexStat.max_avail * 100.0);
+ if (indexStat.max_avail > 0)
+ snprintf(values[j++], 32, "%.2f",
+ 100.0 - (double) indexStat.free_space / (double) indexStat.max_avail * 100.0);
+ else
+ snprintf(values[j++], 32, "NaN");
values[j] = palloc(32);
- snprintf(values[j++], 32, "%.2f", (double) indexStat.fragments / (double) indexStat.leaf_pages * 100.0);
+ if (indexStat.leaf_pages > 0)
+ snprintf(values[j++], 32, "%.2f",
+ (double) indexStat.fragments / (double) indexStat.leaf_pages * 100.0);
+ else
+ snprintf(values[j++], 32, "NaN");
tuple = BuildTupleFromCStrings(TupleDescGetAttInMetadata(tupleDesc),
values);
This is the main PostgreSQL git repository.
RSS Atom

AltStyle によって変換されたページ (->オリジナル) /