From 7529e3cf013065656d2bacc08f89f06a59fb2fd1 Mon Sep 17 00:00:00 2001 From: Yahor Yuzefovich Date: Thu, 18 Jul 2019 13:46:29 -0700 Subject: [PATCH] exec: fix calculation of selectivity stat when num batches is zero Release note: None --- pkg/sql/execpb/stats.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/sql/execpb/stats.go b/pkg/sql/execpb/stats.go index 7e4d87ecf781..7a6707970d3a 100644 --- a/pkg/sql/execpb/stats.go +++ b/pkg/sql/execpb/stats.go @@ -38,10 +38,14 @@ func (vs *VectorizedStats) Stats() map[string]string { } else { timeSuffix = executionTimeTagSuffix } + selectivity := float64(0) + if vs.NumBatches > 0 { + selectivity = float64(vs.NumTuples) / float64(coldata.BatchSize*vs.NumBatches) + } return map[string]string{ batchesOutputTagSuffix: fmt.Sprintf("%d", vs.NumBatches), tuplesOutputTagSuffix: fmt.Sprintf("%d", vs.NumTuples), - selectivityTagSuffix: fmt.Sprintf("%.2f", float64(vs.NumTuples)/float64(coldata.BatchSize*vs.NumBatches)), + selectivityTagSuffix: fmt.Sprintf("%.2f", selectivity), timeSuffix: fmt.Sprintf("%v", vs.Time.Round(time.Microsecond)), } } @@ -62,10 +66,14 @@ func (vs *VectorizedStats) StatsForQueryPlan() []string { } else { timeSuffix = executionTimeQueryPlanSuffix } + selectivity := float64(0) + if vs.NumBatches > 0 { + selectivity = float64(vs.NumTuples) / float64(coldata.BatchSize*vs.NumBatches) + } return []string{ fmt.Sprintf("%s: %d", batchesOutputQueryPlanSuffix, vs.NumBatches), fmt.Sprintf("%s: %d", tuplesOutputQueryPlanSuffix, vs.NumTuples), - fmt.Sprintf("%s: %.2f", selectivityQueryPlanSuffix, float64(vs.NumTuples)/float64(coldata.BatchSize*vs.NumBatches)), + fmt.Sprintf("%s: %.2f", selectivityQueryPlanSuffix, selectivity), fmt.Sprintf("%s: %v", timeSuffix, vs.Time.Round(time.Microsecond)), } }