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

Commit391159e

Browse files
committed
Partially revert commit3d3bf62.
On reflection, the pre-existing logic in ANALYZE is specifically meant tocompare the frequency of a candidate MCV against the estimated frequency ofa random distinct value across the whole table. The change to compare itagainst the average frequency of values actually seen in the sample doesn'tseem very principled, and if anything it would make us less likely not morelikely to consider a value an MCV. So revert that, but keep the aspect ofconsidering 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 atan outer scope in compute_scalar_stats.
1 parentc9ff752 commit391159e

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

‎src/backend/commands/analyze.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2133,13 +2133,15 @@ compute_distinct_stats(VacAttrStatsP stats,
21332133
}
21342134
else
21352135
{
2136-
/* d here is the same as d in the Haas-Stokes formula */
2137-
intd=nonnull_cnt-summultiple+nmultiple;
2136+
doublendistinct_table=stats->stadistinct;
21382137
doubleavgcount,
21392138
mincount;
21402139

2140+
/* Re-extract estimate of # distinct nonnull values in table */
2141+
if (ndistinct_table<0)
2142+
ndistinct_table=-ndistinct_table*totalrows;
21412143
/* estimate # occurrences in sample of a typical nonnull value */
2142-
avgcount= (double)nonnull_cnt /(double)d;
2144+
avgcount= (double)nonnull_cnt /ndistinct_table;
21432145
/* set minimum threshold count to store a value */
21442146
mincount=avgcount*1.25;
21452147
if (mincount<2)
@@ -2493,14 +2495,16 @@ compute_scalar_stats(VacAttrStatsP stats,
24932495
}
24942496
else
24952497
{
2496-
/* d here is the same as d in the Haas-Stokes formula */
2497-
intd=ndistinct+toowide_cnt;
2498+
doublendistinct_table=stats->stadistinct;
24982499
doubleavgcount,
24992500
mincount,
25002501
maxmincount;
25012502

2503+
/* Re-extract estimate of # distinct nonnull values in table */
2504+
if (ndistinct_table<0)
2505+
ndistinct_table=-ndistinct_table*totalrows;
25022506
/* estimate # occurrences in sample of a typical nonnull value */
2503-
avgcount= (double)values_cnt /(double)d;
2507+
avgcount= (double)nonnull_cnt /ndistinct_table;
25042508
/* set minimum threshold count to store a value */
25052509
mincount=avgcount*1.25;
25062510
if (mincount<2)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp