|
49 | 49 | * Portions Copyright (c) 1994, Regents of the University of California
|
50 | 50 | *
|
51 | 51 | * 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 $ |
53 | 53 | *
|
54 | 54 | *-------------------------------------------------------------------------
|
55 | 55 | */
|
|
64 | 64 | #include"optimizer/clauses.h"
|
65 | 65 | #include"optimizer/cost.h"
|
66 | 66 | #include"optimizer/pathnode.h"
|
| 67 | +#include"optimizer/plancat.h" |
67 | 68 | #include"parser/parsetree.h"
|
68 | 69 | #include"utils/selfuncs.h"
|
69 | 70 | #include"utils/lsyscache.h"
|
@@ -1343,6 +1344,13 @@ estimate_hash_bucketsize(Query *root, Var *var, int nbuckets)
|
1343 | 1344 | 0,0);
|
1344 | 1345 | if (!HeapTupleIsValid(tuple))
|
1345 | 1346 | {
|
| 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 | +return1.0 / (double)nbuckets; |
| 1353 | + |
1346 | 1354 | /*
|
1347 | 1355 | * Perhaps the Var is a system attribute; if so, it will have no
|
1348 | 1356 | * entry in pg_statistic, but we may be able to guess something
|
|