From 38bf5fc1362922aa2dbcd5f81fa7442211a99c3c Mon Sep 17 00:00:00 2001 From: weng zhao Date: Wed, 5 Jan 2022 21:57:54 +0800 Subject: [PATCH] vmstorage: fix query like `{foo=~"bar|"}` return extra timeseries cause by negative filter transformation malfunction (#2032) 1. L2749 make kb.B remain the value of comonPrefix instead of tf.prefix 2. L2762 avoid change tf.value from "bar|" to ".+r|" --- lib/storage/index_db.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/storage/index_db.go b/lib/storage/index_db.go index 5c9cf93509..6296de41aa 100644 --- a/lib/storage/index_db.go +++ b/lib/storage/index_db.go @@ -2719,10 +2719,9 @@ func (is *indexSearch) getMetricIDsForDateTagFilter(tf *tagFilter, date uint64, // Use global search if date isn't set. kb.B = is.marshalCommonPrefix(kb.B[:0], nsPrefixTagToMetricIDs) } - kb.B = append(kb.B, tf.prefix[len(commonPrefix):]...) tfNew := *tf tfNew.isNegative = false // isNegative for the original tf is handled by the caller. - tfNew.prefix = kb.B + tfNew.prefix = append(kb.B, tf.prefix[len(commonPrefix):]...) metricIDs, loopsCount, err := is.getMetricIDsForTagFilter(&tfNew, maxMetrics, maxLoopsCount) if err != nil { return nil, loopsCount, err @@ -2735,6 +2734,7 @@ func (is *indexSearch) getMetricIDsForDateTagFilter(tf *tagFilter, date uint64, // This fixes https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1601 // See also https://github.com/VictoriaMetrics/VictoriaMetrics/issues/395 maxLoopsCount -= loopsCount + tfNew = tagFilter{} if err := tfNew.Init(kb.B, tf.key, []byte(".+"), false, true); err != nil { logger.Panicf(`BUG: cannot init tag filter: {%q=~".+"}: %s`, tf.key, err) }