diff options
Diffstat (limited to 'src/backend/commands/analyze.c')
-rw-r--r-- | src/backend/commands/analyze.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c index 87993069830..9800d762fba 100644 --- a/src/backend/commands/analyze.c +++ b/src/backend/commands/analyze.c @@ -2044,8 +2044,11 @@ compute_minimal_stats(VacAttrStatsP stats, if (nmultiple == 0) { - /* If we found no repeated values, assume it's a unique column */ - stats->stadistinct = -1.0; + /* + * If we found no repeated non-null values, assume it's a unique + * column; but be sure to discount for any nulls we found. + */ + stats->stadistinct = -1.0 * (1.0 - stats->stanullfrac); } else if (track_cnt < track_max && toowide_cnt == 0 && nmultiple == track_cnt) @@ -2390,8 +2393,11 @@ compute_scalar_stats(VacAttrStatsP stats, if (nmultiple == 0) { - /* If we found no repeated values, assume it's a unique column */ - stats->stadistinct = -1.0; + /* + * If we found no repeated non-null values, assume it's a unique + * column; but be sure to discount for any nulls we found. + */ + stats->stadistinct = -1.0 * (1.0 - stats->stanullfrac); } else if (toowide_cnt == 0 && nmultiple == ndistinct) { @@ -2695,7 +2701,7 @@ compute_scalar_stats(VacAttrStatsP stats, else stats->stawidth = stats->attrtype->typlen; /* Assume all too-wide values are distinct, so it's a unique column */ - stats->stadistinct = -1.0; + stats->stadistinct = -1.0 * (1.0 - stats->stanullfrac); } else if (null_cnt > 0) { |