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 2cc5f2940f
commit 13c2692ca1
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1

View file

@ -369,9 +369,15 @@ func execBinaryOpArgs(ec *EvalConfig, exprFirst, exprSecond metricsql.Expr, be *
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
lfs := getCommonLabelFilters(tssFirst) switch strings.ToLower(be.Op) {
lfs = metricsql.TrimFiltersByGroupModifier(lfs, be) case "or":
exprSecond = metricsql.PushdownBinaryOpFilters(exprSecond, lfs) // 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) tssSecond, err := evalExpr(ec, exprSecond)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err