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

Commit8a32c94

Browse files
committed
Fix pgstatindex() to give consistent results for empty indexes.
For an empty index, the pgstatindex() function would compute 0.0/0.0 forits avg_leaf_density and leaf_fragmentation outputs. On machines thatfollow the IEEE float arithmetic standard with any care, that results ina NaN. However, per report from Rushabh Lathia, Microsoft couldn'tmanage 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 onthe division operator to give that or the snprintf function to print itcorrectly. I have some doubts that this is really the most usefuldefinition, but it seems better to remain backward-compatible withthose platforms for which the behavior wasn't completely broken.Back-patch to 8.2, since the code is like that in all current releases.
1 parent7ec0258 commit8a32c94

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

‎contrib/pgstattuple/pgstatindex.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,17 @@ pgstatindex(PG_FUNCTION_ARGS)
234234
values[j]=palloc(32);
235235
snprintf(values[j++],32,INT64_FORMAT,indexStat.deleted_pages);
236236
values[j]=palloc(32);
237-
snprintf(values[j++],32,"%.2f",100.0- (double)indexStat.free_space / (double)indexStat.max_avail*100.0);
237+
if (indexStat.max_avail>0)
238+
snprintf(values[j++],32,"%.2f",
239+
100.0- (double)indexStat.free_space / (double)indexStat.max_avail*100.0);
240+
else
241+
snprintf(values[j++],32,"NaN");
238242
values[j]=palloc(32);
239-
snprintf(values[j++],32,"%.2f", (double)indexStat.fragments / (double)indexStat.leaf_pages*100.0);
243+
if (indexStat.leaf_pages>0)
244+
snprintf(values[j++],32,"%.2f",
245+
(double)indexStat.fragments / (double)indexStat.leaf_pages*100.0);
246+
else
247+
snprintf(values[j++],32,"NaN");
240248

241249
tuple=BuildTupleFromCStrings(TupleDescGetAttInMetadata(tupleDesc),
242250
values);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp