Skip to content

Commit 3c7df8a

Browse files
committed
Recost LookUp joins: We assumed that an index which used every column in the lookup was a strong candidate, but that's not necessarily true.
1 parent 7fdf5b3 commit 3c7df8a

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

sql/memo/coster.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,8 @@ func (c *coster) costDistinct(_ *sql.Context, n *Distinct, _ sql.StatsReader) (f
233233
// of 1 will return n rows. It is possible for join selectivity to be below 1
234234
// if source table filters limit the number of rows returned by the left table.
235235
func lookupJoinSelectivity(l *Lookup) float64 {
236-
var sel float64 = 1
237-
if len(l.Index.SqlIdx().Expressions()) == len(l.KeyExprs) {
238-
sel = 0.1
239-
} else {
240-
sel = math.Pow(0.5, float64(len(l.KeyExprs)))
241-
}
236+
sel := math.Pow(0.5, float64(len(l.KeyExprs)))
237+
242238
if !l.Index.SqlIdx().IsUnique() {
243239
return sel
244240
}

0 commit comments

Comments
 (0)