|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * 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 $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
@@ -1548,7 +1548,7 @@ compute_minimal_stats(VacAttrStatsP stats,
|
1548 | 1548 | }
|
1549 | 1549 | }
|
1550 | 1550 |
|
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. */ |
1552 | 1552 | if (nonnull_cnt > 0)
|
1553 | 1553 | {
|
1554 | 1554 | int nmultiple,
|
@@ -1705,6 +1705,17 @@ compute_minimal_stats(VacAttrStatsP stats,
|
1705 | 1705 | stats->numvalues[0] = num_mcv;
|
1706 | 1706 | }
|
1707 | 1707 | }
|
| 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 | + } |
1708 | 1719 |
|
1709 | 1720 | /* We don't need to bother cleaning up any of our temporary palloc's */
|
1710 | 1721 | }
|
@@ -1812,7 +1823,7 @@ compute_scalar_stats(VacAttrStatsP stats,
|
1812 | 1823 | values_cnt++;
|
1813 | 1824 | }
|
1814 | 1825 |
|
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. */ |
1816 | 1827 | if (values_cnt > 0)
|
1817 | 1828 | {
|
1818 | 1829 | int ndistinct, /* # distinct values in sample */
|
@@ -2162,6 +2173,17 @@ compute_scalar_stats(VacAttrStatsP stats,
|
2162 | 2173 | slot_idx++;
|
2163 | 2174 | }
|
2164 | 2175 | }
|
| 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 | + } |
2165 | 2187 |
|
2166 | 2188 | /* We don't need to bother cleaning up any of our temporary palloc's */
|
2167 | 2189 | }
|
|
0 commit comments