Browse Source

promql: optimise aggregation with no labels

For a query like 'sum (foo)', we can quickly skip to the empty labels that its result needs.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
pull/11766/head
Bryan Boreham 2 years ago
parent
commit
1b0a29701b
  1. 8
      promql/engine.go

8
promql/engine.go

@ -2384,14 +2384,18 @@ func (ev *evaluator) aggregation(op parser.ItemType, grouping []string, without
group, ok := result[groupingKey]
// Add a new group if it doesn't exist.
if !ok {
var m labels.Labels
enh.resetBuilder(metric)
if without {
enh.lb.Del(grouping...)
enh.lb.Del(labels.MetricName)
} else {
m = enh.lb.Labels(labels.EmptyLabels())
} else if len(grouping) > 0 {
enh.lb.Keep(grouping...)
m = enh.lb.Labels(labels.EmptyLabels())
} else {
m = labels.EmptyLabels()
}
m := enh.lb.Labels(labels.EmptyLabels())
newAgg := &groupedAggregation{
labels: m,
value: s.V,

Loading…
Cancel
Save