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

Commita8fe109

Browse files
committed
Fix thinko in hash cost estimation: average frequency
should be computed from total number of distinct values in wholerelation, not # distinct values we expect to have after restrictionclauses are applied.
1 parent26c94c5 commita8fe109

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

‎src/backend/optimizer/path/costsize.c

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
* Portions Copyright (c) 1994, Regents of the University of California
4343
*
4444
* IDENTIFICATION
45-
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.75 2001/06/05 05:26:04 tgl Exp $
45+
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.76 2001/06/10 02:59:35 tgl Exp $
4646
*
4747
*-------------------------------------------------------------------------
4848
*/
@@ -873,6 +873,9 @@ estimate_hash_bucketsize(Query *root, Var *var)
873873
if (ndistinct<0.0)
874874
ndistinct=-ndistinct*rel->tuples;
875875

876+
/* Also compute avg freq of all distinct data values in raw relation */
877+
avgfreq= (1.0-stats->stanullfrac) /ndistinct;
878+
876879
/*
877880
* Adjust ndistinct to account for restriction clauses. Observe we are
878881
* assuming that the data distribution is affected uniformly by the
@@ -883,17 +886,6 @@ estimate_hash_bucketsize(Query *root, Var *var)
883886
*/
884887
ndistinct *=rel->rows /rel->tuples;
885888

886-
/*
887-
* Discourage use of hash join if there seem not to be very many distinct
888-
* data values. The threshold here is somewhat arbitrary, as is the
889-
* fraction used to "discourage" the choice.
890-
*/
891-
if (ndistinct<50.0)
892-
{
893-
ReleaseSysCache(tuple);
894-
return0.5;
895-
}
896-
897889
/*
898890
* Form initial estimate of bucketsize fraction. Here we use rel->rows,
899891
* ie the number of rows after applying restriction clauses, because
@@ -903,8 +895,8 @@ estimate_hash_bucketsize(Query *root, Var *var)
903895
estfract= (double)NTUP_PER_BUCKET /rel->rows;
904896

905897
/*
906-
* Adjust estimated bucketsize if too few distinct valuesto fill
907-
* all the buckets.
898+
* Adjust estimated bucketsize if too few distinct values(after
899+
*restriction clauses) to fillall the buckets.
908900
*/
909901
needdistinct=rel->rows / (double)NTUP_PER_BUCKET;
910902
if (ndistinct<needdistinct)
@@ -931,8 +923,6 @@ estimate_hash_bucketsize(Query *root, Var *var)
931923
/*
932924
* Adjust estimated bucketsize upward to account for skewed distribution.
933925
*/
934-
avgfreq= (1.0-stats->stanullfrac) /ndistinct;
935-
936926
if (avgfreq>0.0&&mcvfreq>avgfreq)
937927
estfract *=mcvfreq /avgfreq;
938928

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp