From 2016a2c899c5f0d2debb820d2a5bef68a01b7ca3 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 1 Feb 2022 17:40:48 +0200 Subject: [PATCH] app/vmselect/promql: properly handle `foo or bar` queries Such queries may miss `bar` results after the commit e7f1ceeb840fddbe7a98460b21a88642649a7354 because common label filters from `foo` could be mistakenly applied to `bar`. --- app/vmselect/promql/eval.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/vmselect/promql/eval.go b/app/vmselect/promql/eval.go index cf8322cc5..ade955e97 100644 --- a/app/vmselect/promql/eval.go +++ b/app/vmselect/promql/eval.go @@ -352,9 +352,15 @@ func execBinaryOpArgs(ec *EvalConfig, exprFirst, exprSecond metricsql.Expr, be * if err != nil { return nil, nil, err } - lfs := getCommonLabelFilters(tssFirst) - lfs = metricsql.TrimFiltersByGroupModifier(lfs, be) - exprSecond = metricsql.PushdownBinaryOpFilters(exprSecond, lfs) + switch strings.ToLower(be.Op) { + case "or": + // Do not pushdown common label filters from tssFirst for `or` operation, since this can filter out the needed time series from tssSecond. + // See https://prometheus.io/docs/prometheus/latest/querying/operators/#logical-set-binary-operators for details. + default: + lfs := getCommonLabelFilters(tssFirst) + lfs = metricsql.TrimFiltersByGroupModifier(lfs, be) + exprSecond = metricsql.PushdownBinaryOpFilters(exprSecond, lfs) + } tssSecond, err := evalExpr(ec, exprSecond) if err != nil { return nil, nil, err