mirror of
https://github.com/postgres/postgres.git
synced 2025-08-22 21:53:06 +03:00
Collect and use multi-column dependency stats
Follow on patch in the multi-variate statistics patch series.
CREATE STATISTICS s1 WITH (dependencies) ON (a, b) FROM t;
ANALYZE;
will collect dependency stats on (a, b) and then use the measured
dependency in subsequent query planning.
Commit 7b504eb282
added
CREATE STATISTICS with n-distinct coefficients. These are now
specified using the mutually exclusive option WITH (ndistinct).
Author: Tomas Vondra, David Rowley
Reviewed-by: Kyotaro HORIGUCHI, Álvaro Herrera, Dean Rasheed, Robert Haas
and many other comments and contributions
Discussion: https://postgr.es/m/56f40b20-c464-fad2-ff39-06b668fac47c@2ndquadrant.com
This commit is contained in:
@@ -62,10 +62,11 @@ CreateStatistics(CreateStatsStmt *stmt)
|
||||
Oid relid;
|
||||
ObjectAddress parentobject,
|
||||
childobject;
|
||||
Datum types[1]; /* only ndistinct defined now */
|
||||
Datum types[2]; /* one for each possible type of statistics */
|
||||
int ntypes;
|
||||
ArrayType *staenabled;
|
||||
bool build_ndistinct;
|
||||
bool build_dependencies;
|
||||
bool requested_type = false;
|
||||
|
||||
Assert(IsA(stmt, CreateStatsStmt));
|
||||
@@ -159,7 +160,7 @@ CreateStatistics(CreateStatsStmt *stmt)
|
||||
errmsg("statistics require at least 2 columns")));
|
||||
|
||||
/*
|
||||
* Sort the attnums, which makes detecting duplicies somewhat easier, and
|
||||
* Sort the attnums, which makes detecting duplicities somewhat easier, and
|
||||
* it does not hurt (it does not affect the efficiency, unlike for
|
||||
* indexes, for example).
|
||||
*/
|
||||
@@ -182,6 +183,7 @@ CreateStatistics(CreateStatsStmt *stmt)
|
||||
* recognized.
|
||||
*/
|
||||
build_ndistinct = false;
|
||||
build_dependencies = false;
|
||||
foreach(l, stmt->options)
|
||||
{
|
||||
DefElem *opt = (DefElem *) lfirst(l);
|
||||
@@ -191,6 +193,11 @@ CreateStatistics(CreateStatsStmt *stmt)
|
||||
build_ndistinct = defGetBoolean(opt);
|
||||
requested_type = true;
|
||||
}
|
||||
else if (strcmp(opt->defname, "dependencies") == 0)
|
||||
{
|
||||
build_dependencies = defGetBoolean(opt);
|
||||
requested_type = true;
|
||||
}
|
||||
else
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
@@ -199,12 +206,17 @@ CreateStatistics(CreateStatsStmt *stmt)
|
||||
}
|
||||
/* If no statistic type was specified, build them all. */
|
||||
if (!requested_type)
|
||||
{
|
||||
build_ndistinct = true;
|
||||
build_dependencies = true;
|
||||
}
|
||||
|
||||
/* construct the char array of enabled statistic types */
|
||||
ntypes = 0;
|
||||
if (build_ndistinct)
|
||||
types[ntypes++] = CharGetDatum(STATS_EXT_NDISTINCT);
|
||||
if (build_dependencies)
|
||||
types[ntypes++] = CharGetDatum(STATS_EXT_DEPENDENCIES);
|
||||
Assert(ntypes > 0);
|
||||
staenabled = construct_array(types, ntypes, CHAROID, 1, true, 'c');
|
||||
|
||||
@@ -222,6 +234,7 @@ CreateStatistics(CreateStatsStmt *stmt)
|
||||
|
||||
/* no statistics build yet */
|
||||
nulls[Anum_pg_statistic_ext_standistinct - 1] = true;
|
||||
nulls[Anum_pg_statistic_ext_stadependencies - 1] = true;
|
||||
|
||||
/* insert it into pg_statistic_ext */
|
||||
statrel = heap_open(StatisticExtRelationId, RowExclusiveLock);
|
||||
|
Reference in New Issue
Block a user