Skip to content

Commit 57cb8d2

Browse files
committed
use selfJoinCard to calculate expectedRightRows
1 parent 5c2e4da commit 57cb8d2

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

sql/memo/coster.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,14 @@ func (c *coster) costRel(ctx *sql.Context, n RelExpr, s sql.StatsProvider) (floa
129129

130130
// If LookupJoin is injective, then there will only be one right lookup per left row
131131
if n.Injective || matchRate == 0 {
132-
return lBest*seqIOCostFactor + lBest*randIOCostFactor, nil
132+
return lBest*seqIOCostFactor + lBest*(seqIOCostFactor+randIOCostFactor), nil
133133
}
134134
// Fanout is the average number of right-side rows that match each left-side row
135135
fanout := 2.0
136136
// The total expected number of right row lookups
137-
expectedRightRows := lBest * matchRate * fanout
137+
expectedRightRows := selfJoinCard * matchRate * fanout
138138
// Estimate for reading each left row and each expected right row
139-
return lBest*seqIOCostFactor + expectedRightRows*randIOCostFactor, nil
139+
return lBest*seqIOCostFactor + expectedRightRows*(seqIOCostFactor+randIOCostFactor), nil
140140
case *ConcatJoin:
141141
return c.costConcatJoin(ctx, n, s)
142142
}

0 commit comments

Comments
 (0)