aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/analyze.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2010-01-22 16:40:19 +0000
committerRobert Haas <rhaas@postgresql.org>2010-01-22 16:40:19 +0000
commit76a47c0e7423891d4b4f0977312f46fec6c5c416 (patch)
tree8c9ad15f5c0bf5b2c129ec78fece1780eb430c0d /src/backend/commands/analyze.c
parent9ca0989037602d9835eec04c2a9b6016a7b55740 (diff)
downloadpostgresql-76a47c0e7423891d4b4f0977312f46fec6c5c416.tar.gz
postgresql-76a47c0e7423891d4b4f0977312f46fec6c5c416.zip
Replace ALTER TABLE ... SET STATISTICS DISTINCT with a more general mechanism.
Attributes can now have options, just as relations and tablespaces do, and the reloptions code is used to parse, validate, and store them. For simplicity and because these options are not performance critical, we store them in a separate cache rather than the main relcache. Thanks to Alex Hunsaker for the review.
Diffstat (limited to 'src/backend/commands/analyze.c')
-rw-r--r--src/backend/commands/analyze.c34
1 files changed, 27 insertions, 7 deletions
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c
index 7d4087c915b..f27a6dad2e6 100644
--- a/src/backend/commands/analyze.c
+++ b/src/backend/commands/analyze.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.147 2010/01/02 16:57:36 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.148 2010/01/22 16:40:18 rhaas Exp $
*
*-------------------------------------------------------------------------
*/
@@ -39,6 +39,7 @@
#include "storage/proc.h"
#include "storage/procarray.h"
#include "utils/acl.h"
+#include "utils/attoptcache.h"
#include "utils/datum.h"
#include "utils/guc.h"
#include "utils/lsyscache.h"
@@ -493,6 +494,8 @@ do_analyze_rel(Relation onerel, VacuumStmt *vacstmt,
for (i = 0; i < attr_cnt; i++)
{
VacAttrStats *stats = vacattrstats[i];
+ AttributeOpts *aopt =
+ get_attribute_options(onerel->rd_id, stats->attr->attnum);
stats->rows = rows;
stats->tupDesc = onerel->rd_att;
@@ -501,9 +504,17 @@ do_analyze_rel(Relation onerel, VacuumStmt *vacstmt,
numrows,
totalrows);
- /* If attdistinct is set, override with that value */
- if (stats->attr->attdistinct != 0)
- stats->stadistinct = stats->attr->attdistinct;
+ /*
+ * If the appropriate flavor of the n_distinct option is
+ * specified, override with the corresponding value.
+ */
+ if (aopt != NULL)
+ {
+ float8 n_distinct =
+ inh ? aopt->n_distinct_inherited : aopt->n_distinct;
+ if (n_distinct != 0.0)
+ stats->stadistinct = n_distinct;
+ }
MemoryContextResetAndDeleteChildren(col_context);
}
@@ -751,6 +762,9 @@ compute_index_stats(Relation onerel, double totalrows,
for (i = 0; i < attr_cnt; i++)
{
VacAttrStats *stats = thisdata->vacattrstats[i];
+ AttributeOpts *aopt =
+ get_attribute_options(stats->attr->attrelid,
+ stats->attr->attnum);
stats->exprvals = exprvals + i;
stats->exprnulls = exprnulls + i;
@@ -759,9 +773,15 @@ compute_index_stats(Relation onerel, double totalrows,
ind_fetch_func,
numindexrows,
totalindexrows);
- /* If attdistinct is set, override with that value */
- if (stats->attr->attdistinct != 0)
- stats->stadistinct = stats->attr->attdistinct;
+
+ /*
+ * If the n_distinct option is specified, it overrides the
+ * above computation. For indices, we always use just
+ * n_distinct, not n_distinct_inherited.
+ */
+ if (aopt != NULL && aopt->n_distinct != 0.0)
+ stats->stadistinct = aopt->n_distinct;
+
MemoryContextResetAndDeleteChildren(col_context);
}
}