aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/ruleutils.c
diff options
context:
space:
mode:
authorTomas Vondra <tomas.vondra@postgresql.org>2019-03-27 18:32:18 +0100
committerTomas Vondra <tomas.vondra@postgresql.org>2019-03-27 18:32:18 +0100
commit7300a699502fe5432b05fbc75baca534b080bebb (patch)
tree2fa5740b9cf8363068e8a575ae569ca172ffb66a /src/backend/utils/adt/ruleutils.c
parent333ed246c6f351c4e8fe22c764b97793c4101b00 (diff)
downloadpostgresql-7300a699502fe5432b05fbc75baca534b080bebb.tar.gz
postgresql-7300a699502fe5432b05fbc75baca534b080bebb.zip
Add support for multivariate MCV lists
Introduce a third extended statistic type, supported by the CREATE STATISTICS command - MCV lists, a generalization of the statistic already built and used for individual columns. Compared to the already supported types (n-distinct coefficients and functional dependencies), MCV lists are more complex, include column values and allow estimation of much wider range of common clauses (equality and inequality conditions, IS NULL, IS NOT NULL etc.). Similarly to the other types, a new pseudo-type (pg_mcv_list) is used. Author: Tomas Vondra Reviewed-by: Dean Rasheed, David Rowley, Mark Dilger, Alvaro Herrera Discussion: https://postgr.es/m/dfdac334-9cf2-2597-fb27-f0fb3753f435@2ndquadrant.com
Diffstat (limited to 'src/backend/utils/adt/ruleutils.c')
-rw-r--r--src/backend/utils/adt/ruleutils.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 85055bbb95a..88dc09cae68 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -1509,6 +1509,7 @@ pg_get_statisticsobj_worker(Oid statextid, bool missing_ok)
bool isnull;
bool ndistinct_enabled;
bool dependencies_enabled;
+ bool mcv_enabled;
int i;
statexttup = SearchSysCache1(STATEXTOID, ObjectIdGetDatum(statextid));
@@ -1544,6 +1545,7 @@ pg_get_statisticsobj_worker(Oid statextid, bool missing_ok)
ndistinct_enabled = false;
dependencies_enabled = false;
+ mcv_enabled = false;
for (i = 0; i < ARR_DIMS(arr)[0]; i++)
{
@@ -1551,6 +1553,8 @@ pg_get_statisticsobj_worker(Oid statextid, bool missing_ok)
ndistinct_enabled = true;
if (enabled[i] == STATS_EXT_DEPENDENCIES)
dependencies_enabled = true;
+ if (enabled[i] == STATS_EXT_MCV)
+ mcv_enabled = true;
}
/*
@@ -1560,13 +1564,27 @@ pg_get_statisticsobj_worker(Oid statextid, bool missing_ok)
* statistics types on a newer postgres version, if the statistics had all
* options enabled on the original version.
*/
- if (!ndistinct_enabled || !dependencies_enabled)
+ if (!ndistinct_enabled || !dependencies_enabled || !mcv_enabled)
{
+ bool gotone = false;
+
appendStringInfoString(&buf, " (");
+
if (ndistinct_enabled)
+ {
appendStringInfoString(&buf, "ndistinct");
- else if (dependencies_enabled)
- appendStringInfoString(&buf, "dependencies");
+ gotone = true;
+ }
+
+ if (dependencies_enabled)
+ {
+ appendStringInfo(&buf, "%sdependencies", gotone ? ", " : "");
+ gotone = true;
+ }
+
+ if (mcv_enabled)
+ appendStringInfo(&buf, "%smcv", gotone ? ", " : "");
+
appendStringInfoChar(&buf, ')');
}