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>
This commit is contained in:
Bryan Boreham 2022-12-23 13:33:14 +00:00
parent aafef011b7
commit 1b0a29701b
1 changed files with 6 additions and 2 deletions

View File

@ -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,