diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2000-01-09 00:26:47 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2000-01-09 00:26:47 +0000 |
commit | 166b5c1def56a8c43536ac64bd0ba92517f67765 (patch) | |
tree | 09a047af2ae3b27e0c071a2fd1fbd32785a66190 /src/backend/utils/adt/selfuncs.c | |
parent | 69d4299e3e534686274480ba245566914932c017 (diff) | |
download | postgresql-166b5c1def56a8c43536ac64bd0ba92517f67765.tar.gz postgresql-166b5c1def56a8c43536ac64bd0ba92517f67765.zip |
Another round of planner/optimizer work. This is just restructuring and
code cleanup; no major improvements yet. However, EXPLAIN does produce
more intuitive outputs for nested loops with indexscans now...
Diffstat (limited to 'src/backend/utils/adt/selfuncs.c')
-rw-r--r-- | src/backend/utils/adt/selfuncs.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c index 0d1ee7b64b8..3424155dfb3 100644 --- a/src/backend/utils/adt/selfuncs.c +++ b/src/backend/utils/adt/selfuncs.c @@ -10,7 +10,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.44 1999/11/25 00:21:34 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.45 2000/01/09 00:26:20 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -36,6 +36,9 @@ /* are we looking at a functional index selectivity request? */ #define FunctionalSelectivity(nIndKeys,attNum) ((attNum)==InvalidAttrNumber) +/* default selectivity estimate for equalities such as "A = b" */ +#define DEFAULT_EQ_SEL 0.01 + /* default selectivity estimate for inequalities such as "A < b" */ #define DEFAULT_INEQ_SEL (1.0 / 3.0) @@ -75,7 +78,7 @@ eqsel(Oid opid, result = (float64) palloc(sizeof(float64data)); if (NONVALUE(attno) || NONVALUE(relid)) - *result = 0.1; + *result = DEFAULT_EQ_SEL; else { Oid typid; @@ -369,15 +372,16 @@ eqjoinsel(Oid opid, float64data num1, num2, min; + bool unknown1 = NONVALUE(relid1) || NONVALUE(attno1); + bool unknown2 = NONVALUE(relid2) || NONVALUE(attno2); result = (float64) palloc(sizeof(float64data)); - if (NONVALUE(attno1) || NONVALUE(relid1) || - NONVALUE(attno2) || NONVALUE(relid2)) - *result = 0.1; + if (unknown1 && unknown2) + *result = DEFAULT_EQ_SEL; else { - num1 = get_attdisbursion(relid1, attno1, 0.01); - num2 = get_attdisbursion(relid2, attno2, 0.01); + num1 = unknown1 ? 1.0 : get_attdisbursion(relid1, attno1, 0.01); + num2 = unknown2 ? 1.0 : get_attdisbursion(relid2, attno2, 0.01); /* * The join selectivity cannot be more than num2, since each * tuple in table 1 could match no more than num2 fraction of @@ -386,6 +390,9 @@ eqjoinsel(Oid opid, * less). By the same reasoning it is not more than num1. * The min is therefore an upper bound. * + * If we know the disbursion of only one side, use it; the reasoning + * above still works. + * * XXX can we make a better estimate here? Using the nullfrac * statistic might be helpful, for example. Assuming the operator * is strict (does not succeed for null inputs) then the selectivity |