Skip to content

Commit f699c7f

Browse files
committed
Only pick indexes based on a superset of filters when it's a strict superset, and fall back on ordinary tiebreakers otherwise.
This likely doesn't affect results in a meaningful way, but it produces cleaner output. (Example, when filtering on x, choose index [x] over [x, y], even though they match on the same number of filters.) But it could matter if the other tiebreaker rules pick an index that can provide additional information to other parts of the analysis (like picking a unique index)
1 parent cdf87c9 commit f699c7f

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

sql/analyzer/costed_index_scan.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -537,13 +537,14 @@ func (c *indexCoster) updateBest(s sql.Statistic, hist []sql.HistogramBucket, fd
537537
return
538538
}
539539

540-
// If one index uses a superset of the filters of the other, we should always pick the superset.
541-
if c.bestFilters.SubsetOf(filters) {
540+
// If one index uses a strict superset of the filters of the other, we should always pick the superset.
541+
// This is true even if the index with more filters isn't unique.
542+
if c.bestFilters.SubsetOf(filters) && !c.bestFilters.Equals(filters) {
542543
update = true
543544
return
544545
}
545546

546-
if filters.SubsetOf(c.bestFilters) {
547+
if filters.SubsetOf(c.bestFilters) && !filters.Equals(c.bestFilters) {
547548
return
548549
}
549550

0 commit comments

Comments
 (0)