From eb9a542c1f4d489d6ac392847cd0a86e4b30b27f Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Sat, 7 Jan 2023 01:04:41 -0800 Subject: [PATCH] lib/storage: simplify the fix from 488940502c55b8ed0e693daf097a8eb96e2af70f Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3566 --- lib/storage/index_db.go | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/lib/storage/index_db.go b/lib/storage/index_db.go index 5b322eb61a..7a648cce1a 100644 --- a/lib/storage/index_db.go +++ b/lib/storage/index_db.go @@ -852,6 +852,7 @@ func (is *indexSearch) searchLabelNamesWithFiltersOnDate(qt *querytracer.Tracer, mp := &is.mp dmis := is.db.s.getDeletedMetricIDs() loopsPaceLimiter := 0 + underscoreNameSeen := false nsPrefixExpected := byte(nsPrefixDateTagToMetricIDs) if date == 0 { nsPrefixExpected = nsPrefixTagToMetricIDs @@ -878,9 +879,9 @@ func (is *indexSearch) searchLabelNamesWithFiltersOnDate(qt *querytracer.Tracer, } labelName := mp.Tag.Key if len(labelName) == 0 { - labelName = []byte("__name__") + underscoreNameSeen = true } - if isArtificialTagKey(labelName) { + if isArtificialTagKey(labelName) || string(labelName) == string(prevLabelName) { // Search for the next tag key. // The last char in kb.B must be tagSeparatorChar. // Just increment it in order to jump to the next tag key. @@ -895,20 +896,12 @@ func (is *indexSearch) searchLabelNamesWithFiltersOnDate(qt *querytracer.Tracer, ts.Seek(kb.B) continue } - if string(labelName) == string(prevLabelName) { - var tagValue []byte - if string(labelName) != "__name__" { - tagValue = labelName - } - kb.B = is.marshalCommonPrefixForDate(kb.B[:0], date) - kb.B = marshalTagValue(kb.B, tagValue) - kb.B[len(kb.B)-1]++ - ts.Seek(kb.B) - continue - } lns[string(labelName)] = struct{}{} prevLabelName = append(prevLabelName[:0], labelName...) } + if underscoreNameSeen { + lns["__name__"] = struct{}{} + } if err := ts.Error(); err != nil { return fmt.Errorf("error during search for prefix %q: %w", prefix, err) }