Add length check to prevent index out of range (#4864)

This commit is contained in:
Rain Li
2017-10-23 00:21:34 -05:00
committed by Shen Li
parent ed7f68ca9b
commit eba15dc3f5

View File

@ -74,7 +74,7 @@ func (p *DataSource) getStatsProfileByFilter(conds expression.CNFExprs) *statsPr
}
for i, col := range p.Columns {
hist, ok := p.statisticTable.Columns[col.ID]
if ok && hist.NDV > 0 {
if ok && hist.NDV > 0 && len(hist.Buckets) > 0 {
factor := float64(p.statisticTable.Count) / float64(hist.Buckets[len(hist.Buckets)-1].Count)
profile.cardinality[i] = float64(hist.NDV) * factor
} else {