app/vmselect/promql: properly handle foo or bar queries

Such queries may miss `bar` results after the commit e7f1ceeb84
because common label filters from `foo` could be mistakenly applied to `bar`.
This commit is contained in:
Aliaksandr Valialkin 2022-02-01 17:40:48 +02:00
parent d4b09896fa
commit 2016a2c899
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1

View file

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