]> granicus.if.org Git - postgresql/commit
Collect and use element-frequency statistics for arrays.
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 4 Mar 2012 01:20:19 +0000 (20:20 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 4 Mar 2012 01:20:57 +0000 (20:20 -0500)
commit0e5e167aaea4ceb355a6e20eec96c4f7d05527ab
tree1b1b338461cba27a2d783db13b74d1b7b86b6681
parent34c978442c55dd13a3a8c6b90fd4380dad02f3da
Collect and use element-frequency statistics for arrays.

This patch improves selectivity estimation for the array <@, &&, and @>
(containment and overlaps) operators.  It enables collection of statistics
about individual array element values by ANALYZE, and introduces
operator-specific estimators that use these stats.  In addition,
ScalarArrayOpExpr constructs of the forms "const = ANY/ALL (array_column)"
and "const <> ANY/ALL (array_column)" are estimated by treating them as
variants of the containment operators.

Since we still collect scalar-style stats about the array values as a
whole, the pg_stats view is expanded to show both these stats and the
array-style stats in separate columns.  This creates an incompatible change
in how stats for tsvector columns are displayed in pg_stats: the stats
about lexemes are now displayed in the array-related columns instead of the
original scalar-related columns.

There are a few loose ends here, notably that it'd be nice to be able to
suppress either the scalar-style stats or the array-element stats for
columns for which they're not useful.  But the patch is in good enough
shape to commit for wider testing.

Alexander Korotkov, reviewed by Noah Misch and Nathan Boley
24 files changed:
doc/src/sgml/catalogs.sgml
src/backend/catalog/heap.c
src/backend/catalog/system_views.sql
src/backend/commands/analyze.c
src/backend/commands/typecmds.c
src/backend/tsearch/ts_selfuncs.c
src/backend/tsearch/ts_typanalyze.c
src/backend/utils/adt/Makefile
src/backend/utils/adt/array_selfuncs.c [new file with mode: 0644]
src/backend/utils/adt/array_typanalyze.c [new file with mode: 0644]
src/backend/utils/adt/selfuncs.c
src/include/catalog/catversion.h
src/include/catalog/pg_operator.h
src/include/catalog/pg_proc.h
src/include/catalog/pg_statistic.h
src/include/catalog/pg_type.h
src/include/commands/vacuum.h
src/include/utils/array.h
src/include/utils/selfuncs.h
src/test/regress/expected/arrays.out
src/test/regress/expected/rules.out
src/test/regress/expected/type_sanity.out
src/test/regress/sql/arrays.sql
src/test/regress/sql/type_sanity.sql