aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/common
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/access/common
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/access/common')
-rw-r--r--src/backend/access/common/reloptions.c50
-rw-r--r--src/backend/access/common/tupdesc.c9
2 files changed, 52 insertions, 7 deletions
diff --git a/src/backend/access/common/reloptions.c b/src/backend/access/common/reloptions.c
index 28eacb4e478..65328a9f288 100644
--- a/src/backend/access/common/reloptions.c
+++ b/src/backend/access/common/reloptions.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/common/reloptions.c,v 1.31 2010/01/05 21:53:58 rhaas Exp $
+ * $PostgreSQL: pgsql/src/backend/access/common/reloptions.c,v 1.32 2010/01/22 16:40:18 rhaas Exp $
*
*-------------------------------------------------------------------------
*/
@@ -24,6 +24,7 @@
#include "commands/tablespace.h"
#include "nodes/makefuncs.h"
#include "utils/array.h"
+#include "utils/attoptcache.h"
#include "utils/builtins.h"
#include "utils/guc.h"
#include "utils/memutils.h"
@@ -196,6 +197,22 @@ static relopt_real realRelOpts[] =
},
-1, 0.0, DBL_MAX
},
+ {
+ {
+ "n_distinct",
+ "Sets the planner's estimate of the number of distinct values appearing in a column (excluding child relations).",
+ RELOPT_KIND_ATTRIBUTE
+ },
+ 0, -1.0, DBL_MAX
+ },
+ {
+ {
+ "n_distinct_inherited",
+ "Sets the planner's estimate of the number of distinct values appearing in a column (including child relations).",
+ RELOPT_KIND_ATTRIBUTE
+ },
+ 0, -1.0, DBL_MAX
+ },
/* list terminator */
{{NULL}}
};
@@ -1187,6 +1204,37 @@ index_reloptions(RegProcedure amoptions, Datum reloptions, bool validate)
}
/*
+ * Option parser for attribute reloptions
+ */
+bytea *
+attribute_reloptions(Datum reloptions, bool validate)
+{
+ relopt_value *options;
+ AttributeOpts *aopts;
+ int numoptions;
+ static const relopt_parse_elt tab[] = {
+ {"n_distinct", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct)},
+ {"n_distinct_inherited", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct_inherited)}
+ };
+
+ options = parseRelOptions(reloptions, validate, RELOPT_KIND_ATTRIBUTE,
+ &numoptions);
+
+ /* if none set, we're done */
+ if (numoptions == 0)
+ return NULL;
+
+ aopts = allocateReloptStruct(sizeof(AttributeOpts), options, numoptions);
+
+ fillRelOptions((void *) aopts, sizeof(AttributeOpts), options, numoptions,
+ validate, tab, lengthof(tab));
+
+ pfree(options);
+
+ return (bytea *) aopts;
+}
+
+/*
* Option parser for tablespace reloptions
*/
bytea *
diff --git a/src/backend/access/common/tupdesc.c b/src/backend/access/common/tupdesc.c
index a39b4922d87..9edecda2d88 100644
--- a/src/backend/access/common/tupdesc.c
+++ b/src/backend/access/common/tupdesc.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/common/tupdesc.c,v 1.131 2010/01/02 16:57:33 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/access/common/tupdesc.c,v 1.132 2010/01/22 16:40:18 rhaas Exp $
*
* NOTES
* some of the executor utility code such as "ExecTypeFromTL" should be
@@ -338,8 +338,6 @@ equalTupleDescs(TupleDesc tupdesc1, TupleDesc tupdesc2)
return false;
if (attr1->attstattarget != attr2->attstattarget)
return false;
- if (attr1->attdistinct != attr2->attdistinct)
- return false;
if (attr1->attlen != attr2->attlen)
return false;
if (attr1->attndims != attr2->attndims)
@@ -362,7 +360,7 @@ equalTupleDescs(TupleDesc tupdesc1, TupleDesc tupdesc2)
return false;
if (attr1->attinhcount != attr2->attinhcount)
return false;
- /* attacl is ignored, since it's not even present... */
+ /* attacl and attoptions are not even present... */
}
if (tupdesc1->constr != NULL)
@@ -467,7 +465,6 @@ TupleDescInitEntry(TupleDesc desc,
MemSet(NameStr(att->attname), 0, NAMEDATALEN);
att->attstattarget = -1;
- att->attdistinct = 0;
att->attcacheoff = -1;
att->atttypmod = typmod;
@@ -479,7 +476,7 @@ TupleDescInitEntry(TupleDesc desc,
att->attisdropped = false;
att->attislocal = true;
att->attinhcount = 0;
- /* attacl is not set because it's not present in tupledescs */
+ /* attacl and attoptions are not present in tupledescs */
tuple = SearchSysCache(TYPEOID,
ObjectIdGetDatum(oidtypeid),