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

Commit7f3eba3

Browse files
committed
When estimating without benefit of MCV lists (suggesting that one or both
inputs is unique or nearly so), make eqjoinsel() clamp the ndistinct estimatesto be not more than the estimated number of rows coming from the inputrelations. This allows the estimate to change in response to the selectivityof restriction conditions on the inputs.This is a pretty narrow patch and maybe we should be more aggressive aboutsimilarly clamping ndistinct in other cases; but I'm worried aboutdouble-counting the effects of the restriction conditions. However, it seemsto help for the case exhibited by Grzegorz Jaskiewicz (antijoin against asmall subset of a relation), so let's try this for awhile.
1 parent31468d0 commit7f3eba3

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

‎src/backend/utils/adt/selfuncs.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
* $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.256 2008/10/21 20:42:53 tgl Exp $
18+
* $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.257 2008/10/23 00:24:50 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -2143,10 +2143,22 @@ eqjoinsel_inner(Oid operator,
21432143
* XXX Can we be smarter if we have an MCV list for just one side? It
21442144
* seems that if we assume equal distribution for the other side, we
21452145
* end up with the same answer anyway.
2146+
*
2147+
* An additional hack we use here is to clamp the nd1 and nd2 values
2148+
* to not more than what we are estimating the input relation sizes
2149+
* to be, providing a crude correction for the selectivity of
2150+
* restriction clauses on those relations. (We don't do that in the
2151+
* other path since there we are comparing the nd values to stats for
2152+
* the whole relations.)
21462153
*/
21472154
doublenullfrac1=stats1 ?stats1->stanullfrac :0.0;
21482155
doublenullfrac2=stats2 ?stats2->stanullfrac :0.0;
21492156

2157+
if (vardata1->rel)
2158+
nd1=Min(nd1,vardata1->rel->rows);
2159+
if (vardata2->rel)
2160+
nd2=Min(nd2,vardata2->rel->rows);
2161+
21502162
selec= (1.0-nullfrac1)* (1.0-nullfrac2);
21512163
if (nd1>nd2)
21522164
selec /=nd1;
@@ -2305,6 +2317,11 @@ eqjoinsel_semi(Oid operator,
23052317
*/
23062318
doublenullfrac1=stats1 ?stats1->stanullfrac :0.0;
23072319

2320+
if (vardata1->rel)
2321+
nd1=Min(nd1,vardata1->rel->rows);
2322+
if (vardata2->rel)
2323+
nd2=Min(nd2,vardata2->rel->rows);
2324+
23082325
if (nd1 <=nd2||nd2 <=0)
23092326
selec=1.0-nullfrac1;
23102327
else

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp