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

Commit a1dcd8f

Browse files
committed
Add a little more smarts to estimate_hash_bucketsize(): if there's no
statistics, but there is a unique index on the column, we can safely assume it's well-distributed.
1 parent 22347dc commit a1dcd8f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/backend/optimizer/path/costsize.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
* Portions Copyright (c) 1994, Regents of the University of California
5050
*
5151
* IDENTIFICATION
52-
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.114 2003/08/08 21:41:44 momjian Exp $
52+
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.115 2003/10/05 22:44:25 tgl Exp $
5353
*
5454
*-------------------------------------------------------------------------
5555
*/
@@ -64,6 +64,7 @@
6464
#include "optimizer/clauses.h"
6565
#include "optimizer/cost.h"
6666
#include "optimizer/pathnode.h"
67+
#include "optimizer/plancat.h"
6768
#include "parser/parsetree.h"
6869
#include "utils/selfuncs.h"
6970
#include "utils/lsyscache.h"
@@ -1343,6 +1344,13 @@ estimate_hash_bucketsize(Query *root, Var *var, int nbuckets)
13431344
0, 0);
13441345
if (!HeapTupleIsValid(tuple))
13451346
{
1347+
/*
1348+
* If the attribute is known unique because of an index,
1349+
* we can treat it as well-distributed.
1350+
*/
1351+
if (has_unique_index(rel, var->varattno))
1352+
return 1.0 / (double) nbuckets;
1353+
13461354
/*
13471355
* Perhaps the Var is a system attribute; if so, it will have no
13481356
* entry in pg_statistic, but we may be able to guess something

0 commit comments

Comments
 (0)