mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-03 09:13:20 +03:00 
			
		
		
		
	Implement multivariate n-distinct coefficients
Add support for explicitly declared statistic objects (CREATE STATISTICS), allowing collection of statistics on more complex combinations that individual table columns. Companion commands DROP STATISTICS and ALTER STATISTICS ... OWNER TO / SET SCHEMA / RENAME are added too. All this DDL has been designed so that more statistic types can be added later on, such as multivariate most-common-values and multivariate histograms between columns of a single table, leaving room for permitting columns on multiple tables, too, as well as expressions. This commit only adds support for collection of n-distinct coefficient on user-specified sets of columns in a single table. This is useful to estimate number of distinct groups in GROUP BY and DISTINCT clauses; estimation errors there can cause over-allocation of memory in hashed aggregates, for instance, so it's a worthwhile problem to solve. A new special pseudo-type pg_ndistinct is used. (num-distinct estimation was deemed sufficiently useful by itself that this is worthwhile even if no further statistic types are added immediately; so much so that another version of essentially the same functionality was submitted by Kyotaro Horiguchi: https://postgr.es/m/20150828.173334.114731693.horiguchi.kyotaro@lab.ntt.co.jp though this commit does not use that code.) Author: Tomas Vondra. Some code rework by Álvaro. Reviewed-by: Dean Rasheed, David Rowley, Kyotaro Horiguchi, Jeff Janes, Ideriha Takeshi Discussion: https://postgr.es/m/543AFA15.4080608@fuzzy.cz https://postgr.es/m/20170320190220.ixlaueanxegqd5gr@alvherre.pgsql
This commit is contained in:
		@@ -529,6 +529,7 @@ typedef struct RelOptInfo
 | 
			
		||||
	List	   *lateral_vars;	/* LATERAL Vars and PHVs referenced by rel */
 | 
			
		||||
	Relids		lateral_referencers;	/* rels that reference me laterally */
 | 
			
		||||
	List	   *indexlist;		/* list of IndexOptInfo */
 | 
			
		||||
	List	   *statlist;		/* list of StatisticExtInfo */
 | 
			
		||||
	BlockNumber pages;			/* size estimates derived from pg_class */
 | 
			
		||||
	double		tuples;
 | 
			
		||||
	double		allvisfrac;
 | 
			
		||||
@@ -668,6 +669,24 @@ typedef struct ForeignKeyOptInfo
 | 
			
		||||
	List	   *rinfos[INDEX_MAX_KEYS];
 | 
			
		||||
} ForeignKeyOptInfo;
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * StatisticExtInfo
 | 
			
		||||
 *		Information about extended statistics for planning/optimization
 | 
			
		||||
 *
 | 
			
		||||
 * This contains information about which columns are covered by the
 | 
			
		||||
 * statistics (stakeys), which options were requested while adding the
 | 
			
		||||
 * statistics (*_enabled), and which kinds of statistics were actually
 | 
			
		||||
 * built and are available for the optimizer (*_built).
 | 
			
		||||
 */
 | 
			
		||||
typedef struct StatisticExtInfo
 | 
			
		||||
{
 | 
			
		||||
	NodeTag		type;
 | 
			
		||||
 | 
			
		||||
	Oid			statOid;		/* OID of the statistics row */
 | 
			
		||||
	RelOptInfo *rel;			/* back-link to index's table */
 | 
			
		||||
	char		kind;			/* statistic kind of this entry */
 | 
			
		||||
	Bitmapset  *keys;			/* attnums of the columns covered */
 | 
			
		||||
} StatisticExtInfo;
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * EquivalenceClasses
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user