From eba15dc3f5014787c169cbf89a142c457d2cd900 Mon Sep 17 00:00:00 2001 From: Rain Li Date: Mon, 23 Oct 2017 00:21:34 -0500 Subject: [PATCH] Add length check to prevent index out of range (#4864) --- plan/stats.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plan/stats.go b/plan/stats.go index cf02153d74..75220c27dd 100644 --- a/plan/stats.go +++ b/plan/stats.go @@ -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 {