Skip to content

Commit

Permalink
stats: fix estimation in between row count (#5135) (#5140)
Browse files Browse the repository at this point in the history
  • Loading branch information
alivxxx authored and shenli committed Nov 17, 2017
1 parent 07db8cd commit 73b4c98
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 11 deletions.
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

0 comments on commit 73b4c98

Please sign in to comment.