Skip to content

Commit

Permalink
exec: fix calculation of selectivity stat when num batches is zero
Browse files Browse the repository at this point in the history
Release note: None
  • Loading branch information
yuzefovich committed Jul 18, 2019
1 parent 4b1eb4d commit 7529e3c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkg/sql/execpb/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
}
}
Expand All @@ -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)),
}
}

0 comments on commit 7529e3c

Please sign in to comment.