diff --git a/statistics/histogram.go b/statistics/histogram.go index 6d70514575ec1..9bd1e685da0aa 100644 --- a/statistics/histogram.go +++ b/statistics/histogram.go @@ -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 } @@ -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) diff --git a/statistics/selectivity_test.go b/statistics/selectivity_test.go index a8af4509fa972..82488d591cec3 100644 --- a/statistics/selectivity_test.go +++ b/statistics/selectivity_test.go @@ -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 {