diff options
| author | Tom Lane | 2008-03-09 00:32:09 +0000 |
|---|---|---|
| committer | Tom Lane | 2008-03-09 00:32:09 +0000 |
| commit | f4230d29377556a350866f17ebb2e16ac907fa50 (patch) | |
| tree | 76d1422c8b029f26994b5c60ac6ac76587efe08a /contrib/ltree | |
| parent | 422495d0da79d8a36d6f3700a96c6acddd3e1d50 (diff) | |
Change patternsel() so that instead of switching from a pure
pattern-examination heuristic method to purely histogram-driven selectivity at
histogram size 100, we compute both estimates and use a weighted average.
The weight put on the heuristic estimate decreases linearly with histogram
size, dropping to zero for 100 or more histogram entries.
Likewise in ltreeparentsel(). After a patch by Greg Stark, though I
reorganized the logic a bit to give the caller of histogram_selectivity()
more control.
Diffstat (limited to 'contrib/ltree')
| -rw-r--r-- | contrib/ltree/ltree_op.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/contrib/ltree/ltree_op.c b/contrib/ltree/ltree_op.c index be2733273fb..3eb854fbdc9 100644 --- a/contrib/ltree/ltree_op.c +++ b/contrib/ltree/ltree_op.c @@ -1,7 +1,7 @@ /* * op function for ltree * Teodor Sigaev <teodor@stack.net> - * $PostgreSQL: pgsql/contrib/ltree/ltree_op.c,v 1.16 2007/02/28 22:44:38 tgl Exp $ + * $PostgreSQL: pgsql/contrib/ltree/ltree_op.c,v 1.17 2008/03/09 00:32:09 tgl Exp $ */ #include "ltree.h" @@ -609,6 +609,7 @@ ltreeparentsel(PG_FUNCTION_ARGS) double mcvsum; double mcvsel; double nullfrac; + int hist_size; fmgr_info(get_opcode(operator), &contproc); @@ -626,21 +627,31 @@ ltreeparentsel(PG_FUNCTION_ARGS) */ selec = histogram_selectivity(&vardata, &contproc, constval, varonleft, - 100, 1); + 10, 1, &hist_size); if (selec < 0) { /* Nope, fall back on default */ selec = DEFAULT_PARENT_SEL; } - else + else if (hist_size < 100) { - /* Yes, but don't believe extremely small or large estimates. */ - if (selec < 0.0001) - selec = 0.0001; - else if (selec > 0.9999) - selec = 0.9999; + /* + * For histogram sizes from 10 to 100, we combine the + * histogram and default selectivities, putting increasingly + * more trust in the histogram for larger sizes. + */ + double hist_weight = hist_size / 100.0; + + selec = selec * hist_weight + + DEFAULT_PARENT_SEL * (1.0 - hist_weight); } + /* In any case, don't believe extremely small or large estimates. */ + if (selec < 0.0001) + selec = 0.0001; + else if (selec > 0.9999) + selec = 0.9999; + if (HeapTupleIsValid(vardata.statsTuple)) nullfrac = ((Form_pg_statistic) GETSTRUCT(vardata.statsTuple))->stanullfrac; else |
