mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +03:00
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
This commit is contained in:
@ -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, ')');
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user