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

Commit1f171a1

Browse files
committed
Fix thinko in estimate_num_groups
The code for the reworked n-distinct estimation on commit7b504eb waswritten differently in a previous version of the patch, prior to commit;on rewriting it, we missed updating an initializer. This caused thecode to (mistakenly) apply a fudge factor even in the case where asingle value is applied, leading to incorrect results.This means that the 'relvarcount' variable name is now wrong. Add acomment to try and make the situation clearer, and remove an incorrectcomment I added.Problem noticed, and code patch, by Tomas Vondra. Additional commentaryby Álvaro.
1 parent827d6f9 commit1f171a1

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3404,7 +3404,7 @@ estimate_num_groups(PlannerInfo *root, List *groupExprs, double input_rows,
34043404
RelOptInfo*rel=varinfo1->rel;
34053405
doublereldistinct=1;
34063406
doublerelmaxndistinct=reldistinct;
3407-
intrelvarcount=1;
3407+
intrelvarcount=0;
34083408
List*newvarinfos=NIL;
34093409
List*relvarinfos=NIL;
34103410

@@ -3436,6 +3436,10 @@ estimate_num_groups(PlannerInfo *root, List *groupExprs, double input_rows,
34363436
* we multiply them together. Any remaining relvarinfos after
34373437
* no more multivariate matches are found are assumed independent too,
34383438
* so their individual ndistinct estimates are multiplied also.
3439+
*
3440+
* While iterating, count how many separate numdistinct values we
3441+
* apply. We apply a fudge factor below, but only if we multiplied
3442+
* more than one such values.
34393443
*/
34403444
while (relvarinfos)
34413445
{
@@ -3447,7 +3451,7 @@ estimate_num_groups(PlannerInfo *root, List *groupExprs, double input_rows,
34473451
reldistinct *=mvndistinct;
34483452
if (relmaxndistinct<mvndistinct)
34493453
relmaxndistinct=mvndistinct;
3450-
relvarcount++;/* inaccurate, but doesn't matter */
3454+
relvarcount++;
34513455
}
34523456
else
34533457
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp