Merge pull request #367 from EngineeredVirus/main

PG-601: Histogram ranges are not correct
pull/370/head
Ibrar Ahmed 2023-01-26 14:59:17 +05:00 committed by GitHub
commit a4e60b97bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 7 deletions

View File

@ -295,7 +295,7 @@ _PG_init(void)
* for max outlier queries. However, for min, bucket should only be added * for max outlier queries. However, for min, bucket should only be added
* if the minimum value provided by user is greater than 0 * if the minimum value provided by user is greater than 0
*/ */
hist_bucket_count_total = (hist_bucket_count_user + 1 + (int)(hist_bucket_min > 0)); hist_bucket_count_total = (hist_bucket_count_user + (int)(hist_bucket_max < INT_MAX) + (int)(hist_bucket_min > 0));
if (b_count != hist_bucket_count_user) if (b_count != hist_bucket_count_user)
ereport(WARNING, ereport(WARNING,
@ -3340,7 +3340,7 @@ histogram_bucket_timings(int index, int64 *b_start, int64 *b_end)
*b_end = q_min; *b_end = q_min;
return; return;
} }
else if (index == (b_count - 1)) else if (index == (b_count - 1) && q_max < INT_MAX)
{ {
*b_start = q_max; *b_start = q_max;
*b_end = -1; *b_end = -1;
@ -3355,8 +3355,8 @@ histogram_bucket_timings(int index, int64 *b_start, int64 *b_end)
bucket_size = log(q_max - q_min) / (double) b_count_user; bucket_size = log(q_max - q_min) / (double) b_count_user;
/* Can't do exp(0) as that returns 1. So handling the case of first entry specifically */ /* Can't do exp(0) as that returns 1. So handling the case of first entry specifically */
*b_start = q_min + ((index == 0 || (index == 1 && q_min > 0)) ? 0 : exp(bucket_size * (index - 1))); *b_start = q_min + ((index == 0 || (index == 1 && q_min > 0)) ? 0 : exp(bucket_size * (index - 1 + (q_min == 0))));
*b_end = q_min + exp(bucket_size * index); *b_end = q_min + exp(bucket_size * (index + (q_min == 0)));
} }
/* /*
@ -3405,16 +3405,16 @@ get_histogram_timings(PG_FUNCTION_ARGS)
if (index == 0) if (index == 0)
{ {
snprintf(text_str, MAX_STRING_LEN, "(%ld - %ld)}", b_start, b_end); snprintf(text_str, MAX_STRING_LEN, "{{%ld - %ld}", b_start, b_end);
} }
else if (index == (b_count - 1)) else if (index == (b_count - 1))
{ {
snprintf(tmp_str, MAX_STRING_LEN, "%s, (%ld - ...)}", text_str, b_start); snprintf(tmp_str, MAX_STRING_LEN, "%s, (%ld - ...}}", text_str, b_start);
snprintf(text_str, MAX_STRING_LEN, "%s", tmp_str); snprintf(text_str, MAX_STRING_LEN, "%s", tmp_str);
} }
else else
{ {
snprintf(tmp_str, MAX_STRING_LEN, "%s, (%ld - %ld)}", text_str, b_start, b_end); snprintf(tmp_str, MAX_STRING_LEN, "%s, (%ld - %ld}", text_str, b_start, b_end);
snprintf(text_str, MAX_STRING_LEN, "%s", tmp_str); snprintf(text_str, MAX_STRING_LEN, "%s", tmp_str);
} }
} }