Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 40608e7

Browse files
committed
When estimating the selectivity of an inequality "column > constant" or
"column < constant", and the comparison value is in the first or last histogram bin or outside the histogram entirely, try to fetch the actual column min or max value using an index scan (if there is an index on the column). If successful, replace the lower or upper histogram bound with that value before carrying on with the estimate. This limits the estimation error caused by moving min/max values when the comparison value is close to the min or max. Per a complaint from Josh Berkus. It is tempting to consider using this mechanism for mergejoinscansel as well, but that would inject index fetches into main-line join estimation not just endpoint cases. I'm refraining from that until we can get a better handle on the costs of doing this type of lookup.
1 parent 89a091e commit 40608e7

File tree

5 files changed

+322
-28
lines changed

5 files changed

+322
-28
lines changed

src/backend/executor/nodeHash.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/executor/nodeHash.c,v 1.125 2010/01/02 16:57:41 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/nodeHash.c,v 1.126 2010/01/04 02:44:39 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1006,6 +1006,7 @@ ExecHashBuildSkewHash(HashJoinTable hashtable, Hash *node, int mcvsToUse)
10061006

10071007
if (get_attstatsslot(statsTuple, node->skewColType, node->skewColTypmod,
10081008
STATISTIC_KIND_MCV, InvalidOid,
1009+
NULL,
10091010
&values, &nvalues,
10101011
&numbers, &nnumbers))
10111012
{

src/backend/tsearch/ts_selfuncs.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/tsearch/ts_selfuncs.c,v 1.6 2010/01/02 16:57:53 momjian Exp $
10+
* $PostgreSQL: pgsql/src/backend/tsearch/ts_selfuncs.c,v 1.7 2010/01/04 02:44:39 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -170,6 +170,7 @@ tsquerysel(VariableStatData *vardata, Datum constval)
170170
if (get_attstatsslot(vardata->statsTuple,
171171
TEXTOID, -1,
172172
STATISTIC_KIND_MCELEM, InvalidOid,
173+
NULL,
173174
&values, &nvalues,
174175
&numbers, &nnumbers))
175176
{

0 commit comments

Comments
 (0)