Skip to content

Commit 2f7be07

Browse files
committed
only set max row to 1 if lookup range len is also 1
1 parent 6ccffd3 commit 2f7be07

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

sql/analyzer/costed_index_scan.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,12 +313,14 @@ func getCostedIndexScan(ctx *sql.Context, statsProv sql.StatsProvider, rt sql.Ta
313313
if err != nil {
314314
return nil, nil, nil, err
315315
}
316-
if c.bestStat.FuncDeps().HasMax1Row() && !qFlags.JoinIsSet() && !qFlags.SubqueryIsSet() && lookup.Ranges.Len() == 1 {
317-
// Strict index lookup without a join or subquery scope will return
318-
// at most one row. We could also use some sort of scope counting
319-
// to check for single scope.
320-
qFlags.Set(sql.QFlagMax1Row)
316+
if c.bestStat.FuncDeps().HasMax1Row() && lookup.Ranges.Len() == 1 {
321317
bestStat = bestStat.WithRowCount(1).WithDistinctCount(1)
318+
if !qFlags.JoinIsSet() && !qFlags.SubqueryIsSet() {
319+
// Strict index lookup without a join or subquery scope will return
320+
// at most one row. We could also use some sort of scope counting
321+
// to check for single scope.
322+
qFlags.Set(sql.QFlagMax1Row)
323+
}
322324
} else {
323325
bestStat = stats.UpdateCounts(bestStat)
324326
}

0 commit comments

Comments
 (0)