Skip to content

Commit 4db84f0

Browse files
committed
Fix ANALYZE to accumulate some minimal statistics for an all-null column.
Per gripes from Mike Mascari and Bernd Heller.
1 parent 42599b3 commit 4db84f0

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

src/backend/commands/analyze.c

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.81 2005/01/27 23:23:53 neilc Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.82 2005/02/11 00:41:12 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1548,7 +1548,7 @@ compute_minimal_stats(VacAttrStatsP stats,
15481548
}
15491549
}
15501550

1551-
/* We can only compute valid stats if we found some non-null values. */
1551+
/* We can only compute real stats if we found some non-null values. */
15521552
if (nonnull_cnt > 0)
15531553
{
15541554
int nmultiple,
@@ -1705,6 +1705,17 @@ compute_minimal_stats(VacAttrStatsP stats,
17051705
stats->numvalues[0] = num_mcv;
17061706
}
17071707
}
1708+
else if (null_cnt > 0)
1709+
{
1710+
/* We found only nulls; assume the column is entirely null */
1711+
stats->stats_valid = true;
1712+
stats->stanullfrac = 1.0;
1713+
if (is_varwidth)
1714+
stats->stawidth = 0; /* "unknown" */
1715+
else
1716+
stats->stawidth = stats->attrtype->typlen;
1717+
stats->stadistinct = 0.0; /* "unknown" */
1718+
}
17081719

17091720
/* We don't need to bother cleaning up any of our temporary palloc's */
17101721
}
@@ -1812,7 +1823,7 @@ compute_scalar_stats(VacAttrStatsP stats,
18121823
values_cnt++;
18131824
}
18141825

1815-
/* We can only compute valid stats if we found some sortable values. */
1826+
/* We can only compute real stats if we found some sortable values. */
18161827
if (values_cnt > 0)
18171828
{
18181829
int ndistinct, /* # distinct values in sample */
@@ -2162,6 +2173,17 @@ compute_scalar_stats(VacAttrStatsP stats,
21622173
slot_idx++;
21632174
}
21642175
}
2176+
else if (nonnull_cnt == 0 && null_cnt > 0)
2177+
{
2178+
/* We found only nulls; assume the column is entirely null */
2179+
stats->stats_valid = true;
2180+
stats->stanullfrac = 1.0;
2181+
if (is_varwidth)
2182+
stats->stawidth = 0; /* "unknown" */
2183+
else
2184+
stats->stawidth = stats->attrtype->typlen;
2185+
stats->stadistinct = 0.0; /* "unknown" */
2186+
}
21652187

21662188
/* We don't need to bother cleaning up any of our temporary palloc's */
21672189
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy