postgresql/src
Dean Rasheed 84f9a35e39 Improve estimate of distinct values in estimate_num_groups().
When adjusting the estimate for the number of distinct values from a
rel in a grouped query to take into account the selectivity of the
rel's restrictions, use a formula that is less likely to produce
under-estimates.

The old formula simply multiplied the number of distinct values in the
rel by the restriction selectivity, which would be correct if the
restrictions were fully correlated with the grouping expressions, but
can produce significant under-estimates in cases where they are not
well correlated.

The new formula is based on the random selection probability, and so
assumes that the restrictions are not correlated with the grouping
expressions. This is guaranteed to produce larger estimates, and of
course risks over-estimating in cases where the restrictions are
correlated, but that has less severe consequences than
under-estimating, which might lead to a HashAgg that consumes an
excessive amount of memory.

This could possibly be improved upon in the future by identifying
correlated restrictions and using a hybrid of the old and new
formulae.

Author: Tomas Vondra, with some hacking be me
Reviewed-by: Mark Dilger, Alexander Korotkov, Dean Rasheed and Tom Lane
Discussion: http://www.postgresql.org/message-id/flat/56CD0381.5060502@2ndquadrant.com
2016-04-04 12:41:56 +01:00
..
backend Improve estimate of distinct values in estimate_num_groups(). 2016-04-04 12:41:56 +01:00
bin Add psql \errverbose command to see last server error at full verbosity. 2016-04-03 12:29:55 -04:00
common Refer to a TOKEN_USER payload as a "token user," not as a "user token". 2016-04-01 21:53:18 -04:00
fe_utils Move psql's psqlscan.l into src/fe_utils. 2016-03-24 20:28:47 -04:00
include Add Generic WAL interface 2016-04-01 12:21:48 +03:00
interfaces Add libpq support for recreating an error message with different verbosity. 2016-04-03 12:24:54 -04:00
makefiles Fix typos in comments and doc 2016-01-28 16:47:36 +09:00
pl Copyedit comments and documentation. 2016-04-01 21:53:10 -04:00
port Avoid possibly-unsafe use of Windows' FormatMessage() function. 2016-03-29 11:55:19 -04:00
template Remove some remains from Alpha support removal 2015-10-29 16:40:14 -04:00
test Improve estimate of distinct values in estimate_num_groups(). 2016-04-04 12:41:56 +01:00
timezone Suppress compiler warning. 2016-04-02 13:49:17 -04:00
tools Copyedit comments and documentation. 2016-04-01 21:53:10 -04:00
tutorial Update copyright for 2016 2016-01-02 13:33:40 -05:00
.gitignore Convert cvsignore to gitignore, and add .gitignore for build targets. 2010-09-22 12:57:04 +02:00
bcc32.mak Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
DEVELOPERS
Makefile Create src/fe_utils/, and move stuff into there from pg_dump's dumputils. 2016-03-24 15:55:57 -04:00
Makefile.global.in Create src/fe_utils/, and move stuff into there from pg_dump's dumputils. 2016-03-24 15:55:57 -04:00
Makefile.shlib AIX: Link TRANSFORM modules with their dependencies. 2015-07-15 21:00:26 -04:00
nls-global.mk Setup error context callback for transaction lock waits 2014-03-19 15:10:36 -03:00
win32.mak Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00