diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c new file mode 100644 index 366c4af..42ba7c3 *** a/src/backend/commands/analyze.c --- b/src/backend/commands/analyze.c *************** compute_scalar_stats(VacAttrStatsP stats *** 2592,2597 **** --- 2592,2598 ---- else { double ndistinct = stats->stadistinct; + double sr = (double) samplerows; double avgcount, mincount, maxmincount; *************** compute_scalar_stats(VacAttrStatsP stats *** 2599,2622 **** if (ndistinct < 0) ndistinct = -ndistinct * totalrows; /* estimate # of occurrences in sample of a typical value */ - avgcount = (double) samplerows / ndistinct; - /* set minimum threshold count to store a value */ - mincount = avgcount * 1.25; - if (mincount < 2) - mincount = 2; - /* don't let threshold exceed 1/K, however */ - maxmincount = (double) samplerows / (double) num_bins; - if (mincount > maxmincount) - mincount = maxmincount; - if (num_mcv > track_cnt) - num_mcv = track_cnt; for (i = 0; i < num_mcv; i++) { if (track[i].count < mincount) { num_mcv = i; break; } } } --- 2600,2625 ---- if (ndistinct < 0) ndistinct = -ndistinct * totalrows; /* estimate # of occurrences in sample of a typical value */ for (i = 0; i < num_mcv; i++) { + avgcount = sr / ndistinct; + /* set minimum threshold count to store a value */ + mincount = avgcount * 1.25; + if (mincount < 2) + mincount = 2; + /* don't let threshold exceed 1/K, however */ + maxmincount = (double) sr / (double) (num_bins-1); + if (mincount > maxmincount) + mincount = maxmincount; + if (num_mcv > track_cnt) + num_mcv = track_cnt; if (track[i].count < mincount) { num_mcv = i; break; } + sr -= track[i].count; + ndistinct--; } }