]> granicus.if.org Git - postgresql/commit
Implement multivariate n-distinct coefficients
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Fri, 24 Mar 2017 17:06:10 +0000 (14:06 -0300)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Fri, 24 Mar 2017 17:06:10 +0000 (14:06 -0300)
commit7b504eb282ca2f5104b5c00b4f05a3ef6bb1385b
tree4b12f53c5bd25a03f1016f1daa0809606b47df3a
parentf120b614e070aed39586d1443193738a149a90d4
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
77 files changed:
doc/src/sgml/catalogs.sgml
doc/src/sgml/func.sgml
doc/src/sgml/ref/allfiles.sgml
doc/src/sgml/ref/alter_statistics.sgml [new file with mode: 0644]
doc/src/sgml/ref/alter_table.sgml
doc/src/sgml/ref/comment.sgml
doc/src/sgml/ref/create_statistics.sgml [new file with mode: 0644]
doc/src/sgml/ref/drop_statistics.sgml [new file with mode: 0644]
doc/src/sgml/reference.sgml
src/backend/Makefile
src/backend/catalog/Makefile
src/backend/catalog/aclchk.c
src/backend/catalog/dependency.c
src/backend/catalog/heap.c
src/backend/catalog/namespace.c
src/backend/catalog/objectaddress.c
src/backend/catalog/pg_shdepend.c
src/backend/catalog/system_views.sql
src/backend/commands/Makefile
src/backend/commands/alter.c
src/backend/commands/analyze.c
src/backend/commands/dropcmds.c
src/backend/commands/event_trigger.c
src/backend/commands/statscmds.c [new file with mode: 0644]
src/backend/nodes/copyfuncs.c
src/backend/nodes/equalfuncs.c
src/backend/nodes/outfuncs.c
src/backend/optimizer/util/plancat.c
src/backend/parser/gram.y
src/backend/statistics/Makefile [new file with mode: 0644]
src/backend/statistics/README [new file with mode: 0644]
src/backend/statistics/extended_stats.c [new file with mode: 0644]
src/backend/statistics/mvdistinct.c [new file with mode: 0644]
src/backend/tcop/utility.c
src/backend/utils/adt/ruleutils.c
src/backend/utils/adt/selfuncs.c
src/backend/utils/cache/relcache.c
src/backend/utils/cache/syscache.c
src/bin/pg_dump/common.c
src/bin/pg_dump/pg_backup_archiver.c
src/bin/pg_dump/pg_dump.c
src/bin/pg_dump/pg_dump.h
src/bin/pg_dump/pg_dump_sort.c
src/bin/psql/describe.c
src/include/catalog/catversion.h
src/include/catalog/dependency.h
src/include/catalog/heap.h
src/include/catalog/indexing.h
src/include/catalog/namespace.h
src/include/catalog/pg_cast.h
src/include/catalog/pg_proc.h
src/include/catalog/pg_statistic_ext.h [new file with mode: 0644]
src/include/catalog/pg_type.h
src/include/catalog/toasting.h
src/include/commands/defrem.h
src/include/nodes/nodes.h
src/include/nodes/parsenodes.h
src/include/nodes/relation.h
src/include/statistics/extended_stats_internal.h [new file with mode: 0644]
src/include/statistics/statistics.h [new file with mode: 0644]
src/include/utils/acl.h
src/include/utils/rel.h
src/include/utils/relcache.h
src/include/utils/syscache.h
src/test/regress/expected/alter_generic.out
src/test/regress/expected/object_address.out
src/test/regress/expected/opr_sanity.out
src/test/regress/expected/rules.out
src/test/regress/expected/sanity_check.out
src/test/regress/expected/stats_ext.out [new file with mode: 0644]
src/test/regress/expected/type_sanity.out
src/test/regress/parallel_schedule
src/test/regress/serial_schedule
src/test/regress/sql/alter_generic.sql
src/test/regress/sql/object_address.sql
src/test/regress/sql/stats_ext.sql [new file with mode: 0644]
src/test/regress/sql/type_sanity.sql