1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-22 23:02:54 +03:00

Partially revert commit 3d3bf62f30200500637b24fdb7b992a99f9704c3.

On reflection, the pre-existing logic in ANALYZE is specifically meant to
compare the frequency of a candidate MCV against the estimated frequency of
a random distinct value across the whole table.  The change to compare it
against the average frequency of values actually seen in the sample doesn't
seem very principled, and if anything it would make us less likely not more
likely to consider a value an MCV.  So revert that, but keep the aspect of
considering only nonnull values, which definitely is correct.

In passing, rename the local variables in these stanzas to
"ndistinct_table", to avoid confusion with the "ndistinct" that appears at
an outer scope in compute_scalar_stats.
This commit is contained in:
Tom Lane 2016-04-04 16:48:13 -04:00
parent c9ff752a85
commit 391159e03a

View File

@ -2133,13 +2133,15 @@ compute_distinct_stats(VacAttrStatsP stats,
} }
else else
{ {
/* d here is the same as d in the Haas-Stokes formula */ double ndistinct_table = stats->stadistinct;
int d = nonnull_cnt - summultiple + nmultiple;
double avgcount, double avgcount,
mincount; mincount;
/* Re-extract estimate of # distinct nonnull values in table */
if (ndistinct_table < 0)
ndistinct_table = -ndistinct_table * totalrows;
/* estimate # occurrences in sample of a typical nonnull value */ /* estimate # occurrences in sample of a typical nonnull value */
avgcount = (double) nonnull_cnt / (double) d; avgcount = (double) nonnull_cnt / ndistinct_table;
/* set minimum threshold count to store a value */ /* set minimum threshold count to store a value */
mincount = avgcount * 1.25; mincount = avgcount * 1.25;
if (mincount < 2) if (mincount < 2)
@ -2493,14 +2495,16 @@ compute_scalar_stats(VacAttrStatsP stats,
} }
else else
{ {
/* d here is the same as d in the Haas-Stokes formula */ double ndistinct_table = stats->stadistinct;
int d = ndistinct + toowide_cnt;
double avgcount, double avgcount,
mincount, mincount,
maxmincount; maxmincount;
/* Re-extract estimate of # distinct nonnull values in table */
if (ndistinct_table < 0)
ndistinct_table = -ndistinct_table * totalrows;
/* estimate # occurrences in sample of a typical nonnull value */ /* estimate # occurrences in sample of a typical nonnull value */
avgcount = (double) values_cnt / (double) d; avgcount = (double) nonnull_cnt / ndistinct_table;
/* set minimum threshold count to store a value */ /* set minimum threshold count to store a value */
mincount = avgcount * 1.25; mincount = avgcount * 1.25;
if (mincount < 2) if (mincount < 2)