@@ -4,7 +4,6 @@ package lookupplan
44
55import (
66 "context"
7- "fmt"
87
98 "github.com/prometheus/prometheus/model/labels"
109 "github.com/prometheus/prometheus/tsdb/index"
@@ -27,26 +26,18 @@ type planPredicate struct {
2726 indexScanCost float64
2827}
2928
30- func newPlanPredicate (ctx context.Context , m * labels.Matcher , stats index.Statistics ) (planPredicate , error ) {
31- var err error
29+ func newPlanPredicate (ctx context.Context , m * labels.Matcher , stats index.Statistics ) planPredicate {
3230 pred := planPredicate {
3331 matcher : m ,
3432 singleMatchCost : m .SingleMatchCost (),
3533 }
3634 pred .labelNameUniqueVals = stats .LabelValuesCount (ctx , m .Name )
37- if err != nil {
38- return planPredicate {}, fmt .Errorf ("error getting label values count for label %s: %w" , m .Name , err )
39- }
4035 pred .selectivity = m .EstimateSelectivity (pred .labelNameUniqueVals )
4136
42- pred .cardinality , err = estimatePredicateCardinality (ctx , m , stats , pred .selectivity )
43- if err != nil {
44- return planPredicate {}, fmt .Errorf ("error estimating cardinality for label %s: %w" , m .Name , err )
45- }
46-
37+ pred .cardinality = estimatePredicateCardinality (ctx , m , stats , pred .selectivity )
4738 pred .indexScanCost = estimatePredicateIndexScanCost (pred , m )
4839
49- return pred , nil
40+ return pred
5041}
5142
5243func estimatePredicateIndexScanCost (pred planPredicate , m * labels.Matcher ) float64 {
@@ -75,11 +66,10 @@ func estimatePredicateIndexScanCost(pred planPredicate, m *labels.Matcher) float
7566 panic ("estimatePredicateIndexScanCost called with unhandled matcher type: " + m .Type .String () + m .String ())
7667}
7768
78- func estimatePredicateCardinality (ctx context.Context , m * labels.Matcher , stats index.Statistics , selectivity float64 ) ( uint64 , error ) {
69+ func estimatePredicateCardinality (ctx context.Context , m * labels.Matcher , stats index.Statistics , selectivity float64 ) uint64 {
7970 var (
8071 seriesBehindSelectedValues uint64
8172 matchesAnyValues bool
82- err error
8373 )
8474
8575 switch m .Type {
@@ -107,18 +97,15 @@ func estimatePredicateCardinality(ctx context.Context, m *labels.Matcher, stats
10797 seriesBehindSelectedValues += uint64 (float64 (labelNameCardinality ) * selectivity )
10898 }
10999 }
110- if err != nil {
111- return 0 , fmt .Errorf ("error getting series per label value for label %s: %w" , m .Name , err )
112- }
113100 switch m .Type {
114101 case labels .MatchNotEqual , labels .MatchNotRegexp :
115102 if ! matchesAnyValues {
116103 // This label name doesn't exist. This means that negating this will select everything.
117- return stats .TotalSeries (), nil
104+ return stats .TotalSeries ()
118105 }
119- return stats .TotalSeries () - seriesBehindSelectedValues , nil
106+ return stats .TotalSeries () - seriesBehindSelectedValues
120107 }
121- return seriesBehindSelectedValues , nil
108+ return seriesBehindSelectedValues
122109}
123110
124111func (pr planPredicate ) indexLookupCost () float64 {
0 commit comments