Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stats: fix estimation in between row count (#5135) #5140

Merged
merged 1 commit into from
Nov 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions statistics/histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func (hg *Histogram) betweenRowCount(sc *variable.StatementContext, a, b types.D
return 0, errors.Trace(err)
}
if lessCountA >= lessCountB {
return hg.inBucketBetweenCount(), nil
return hg.totalRowCount() / float64(hg.NDV), nil
}
return lessCountB - lessCountA, nil
}
Expand All @@ -295,15 +295,6 @@ func (hg *Histogram) totalRowCount() float64 {
return float64(hg.Buckets[len(hg.Buckets)-1].Count)
}

func (hg *Histogram) bucketRowCount() float64 {
return hg.totalRowCount() / float64(len(hg.Buckets))
}

func (hg *Histogram) inBucketBetweenCount() float64 {
// TODO: Make this estimation more accurate using uniform spread assumption.
return hg.bucketRowCount()/3 + 1
}

func (hg *Histogram) lowerBound(sc *variable.StatementContext, target types.Datum) (index int, match bool, err error) {
index = sort.Search(len(hg.Buckets), func(i int) bool {
cmp, err1 := hg.Buckets[i].UpperBound.CompareDatum(sc, &target)
Expand Down
2 changes: 1 addition & 1 deletion statistics/selectivity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (s *testSelectivitySuite) TestSelectivity(c *C) {
},
{
exprs: "a > 1 and b < 2 and c > 3 and d < 4 and e > 5",
selectivity: 0.00123287439,
selectivity: 0.00352249826,
},
}
for _, tt := range tests {
Expand Down