Skip to content

Commit

Permalink
metrics,planner: add 'pseudo estimation' reason in the metrics (#21911)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiancaiamao authored Jan 4, 2021
1 parent afcf637 commit b45fa8b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions metrics/grafana/tidb.json
Original file line number Diff line number Diff line change
Expand Up @@ -9673,10 +9673,10 @@
"steppedLine": false,
"targets": [
{
"expr": "sum(rate(tidb_statistics_pseudo_estimation_total[1m]))",
"expr": "sum(rate(tidb_statistics_pseudo_estimation_total[30s])) by (type)",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": "Pseudo OPS",
"legendFormat": "{{type}}",
"refId": "A",
"step": 30
}
Expand Down
4 changes: 2 additions & 2 deletions metrics/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ var (
Buckets: prometheus.ExponentialBuckets(0.01, 2, 14),
})

PseudoEstimation = prometheus.NewCounter(
PseudoEstimation = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "tidb",
Subsystem: "statistics",
Name: "pseudo_estimation_total",
Help: "Counter of pseudo estimation caused by outdated stats.",
})
}, []string{LblType})

DumpFeedbackCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Expand Down
8 changes: 7 additions & 1 deletion planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3497,6 +3497,11 @@ func (ds *DataSource) newExtraHandleSchemaCol() *expression.Column {
}
}

var (
pseudoEstimationNotAvailable = metrics.PseudoEstimation.WithLabelValues("nodata")
pseudoEstimationOutdate = metrics.PseudoEstimation.WithLabelValues("outdate")
)

// getStatsTable gets statistics information for a table specified by "tableID".
// A pseudo statistics table is returned in any of the following scenario:
// 1. tidb-server started and statistics handle has not been initialized.
Expand All @@ -3519,6 +3524,7 @@ func getStatsTable(ctx sessionctx.Context, tblInfo *model.TableInfo, pid int64)

// 2. table row count from statistics is zero.
if statsTbl.Count == 0 {
pseudoEstimationNotAvailable.Inc()
return statistics.PseudoTable(tblInfo)
}

Expand All @@ -3527,7 +3533,7 @@ func getStatsTable(ctx sessionctx.Context, tblInfo *model.TableInfo, pid int64)
tbl := *statsTbl
tbl.Pseudo = true
statsTbl = &tbl
metrics.PseudoEstimation.Inc()
pseudoEstimationOutdate.Inc()
}
return statsTbl
}
Expand Down

0 comments on commit b45fa8b

Please sign in to comment.