Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbfd1ffa

Browse files
committed
Change patternsel (LIKE/regex selectivity estimation) so that if there
is a large enough histogram, it will use the number of matches in thehistogram to derive a selectivity estimate, rather than the admittedlypretty bogus heuristics involving examining the pattern contents. I set'large enough' at 100, but perhaps we should change that later. Alsoapply the same technique in contrib/ltree's <@ and @> estimator. Perdiscussion with Stefan Kaltenbrunner and Matteo Beccati.
1 parent06b33f0 commitbfd1ffa

File tree

3 files changed

+242
-113
lines changed

3 files changed

+242
-113
lines changed

‎contrib/ltree/ltree_op.c

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
/*
22
* op function for ltree
33
* Teodor Sigaev <teodor@stack.net>
4-
* $PostgreSQL: pgsql/contrib/ltree/ltree_op.c,v 1.12 2006/05/30 22:12:13 tgl Exp $
4+
* $PostgreSQL: pgsql/contrib/ltree/ltree_op.c,v 1.13 2006/09/20 19:50:21 tgl Exp $
55
*/
66

77
#include"ltree.h"
88

99
#include<ctype.h>
1010

11+
#include"catalog/pg_statistic.h"
1112
#include"utils/lsyscache.h"
1213
#include"utils/selfuncs.h"
1314
#include"utils/syscache.h"
@@ -606,6 +607,7 @@ ltreeparentsel(PG_FUNCTION_ARGS)
606607
FmgrInfocontproc;
607608
doublemcvsum;
608609
doublemcvsel;
610+
doublenullfrac;
609611

610612
fmgr_info(get_opcode(operator),&contproc);
611613

@@ -616,10 +618,40 @@ ltreeparentsel(PG_FUNCTION_ARGS)
616618
&mcvsum);
617619

618620
/*
619-
* We have the exact selectivity for values appearing in the MCV list;
620-
* use the default selectivity for the rest of the population.
621+
* If the histogram is large enough, see what fraction of it the
622+
* constant is "<@" to, and assume that's representative of the
623+
* non-MCV population. Otherwise use the default selectivity for
624+
* the non-MCV population.
621625
*/
622-
selec=mcvsel+DEFAULT_PARENT_SEL* (1.0-mcvsum);
626+
selec=histogram_selectivity(&vardata,&contproc,
627+
constval,varonleft,
628+
100,1);
629+
if (selec<0)
630+
{
631+
/* Nope, fall back on default */
632+
selec=DEFAULT_PARENT_SEL;
633+
}
634+
else
635+
{
636+
/* Yes, but don't believe extremely small or large estimates. */
637+
if (selec<0.0001)
638+
selec=0.0001;
639+
elseif (selec>0.9999)
640+
selec=0.9999;
641+
}
642+
643+
if (HeapTupleIsValid(vardata.statsTuple))
644+
nullfrac= ((Form_pg_statistic)GETSTRUCT(vardata.statsTuple))->stanullfrac;
645+
else
646+
nullfrac=0.0;
647+
648+
/*
649+
* Now merge the results from the MCV and histogram calculations,
650+
* realizing that the histogram covers only the non-null values that
651+
* are not listed in MCV.
652+
*/
653+
selec *=1.0-nullfrac-mcvsum;
654+
selec+=mcvsel;
623655
}
624656
else
625657
selec=DEFAULT_PARENT_SEL;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp