diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2003-10-05 22:44:25 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2003-10-05 22:44:25 +0000 |
commit | a1dcd8f6dd80cfa3e2670d5f1f09fc7eec5d6e53 (patch) | |
tree | b4cc54aa7d865e36426ac04119bcc03a8e81eb73 /src/backend | |
parent | 22347dc10221f5f308dda2f858d5b43d71c9b2d5 (diff) | |
download | postgresql-a1dcd8f6dd80cfa3e2670d5f1f09fc7eec5d6e53.tar.gz postgresql-a1dcd8f6dd80cfa3e2670d5f1f09fc7eec5d6e53.zip |
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.
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/optimizer/path/costsize.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c index 6b0179c8539..65eed58c9fb 100644 --- a/src/backend/optimizer/path/costsize.c +++ b/src/backend/optimizer/path/costsize.c @@ -49,7 +49,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.114 2003/08/08 21:41:44 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.115 2003/10/05 22:44:25 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -64,6 +64,7 @@ #include "optimizer/clauses.h" #include "optimizer/cost.h" #include "optimizer/pathnode.h" +#include "optimizer/plancat.h" #include "parser/parsetree.h" #include "utils/selfuncs.h" #include "utils/lsyscache.h" @@ -1344,6 +1345,13 @@ estimate_hash_bucketsize(Query *root, Var *var, int nbuckets) if (!HeapTupleIsValid(tuple)) { /* + * If the attribute is known unique because of an index, + * we can treat it as well-distributed. + */ + if (has_unique_index(rel, var->varattno)) + return 1.0 / (double) nbuckets; + + /* * Perhaps the Var is a system attribute; if so, it will have no * entry in pg_statistic, but we may be able to guess something * about its distribution anyway. |