mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-01-10 15:14:09 +00:00
lib/storage: move non-matching tag filters to the top at matchTagFilters
This should reduce the amount of useless work needed for matching the next metricNames.
This commit is contained in:
parent
33d9d63393
commit
b9e53490b9
1 changed files with 17 additions and 1 deletions
|
@ -1560,7 +1560,8 @@ func (is *indexSearch) getTagFilterWithMinMetricIDsCount(tfs *TagFilters, maxMet
|
|||
|
||||
func matchTagFilters(mn *MetricName, tfs []*tagFilter, kb *bytesutil.ByteBuffer) (bool, error) {
|
||||
kb.B = marshalCommonPrefix(kb.B[:0], nsPrefixTagToMetricIDs, mn.AccountID, mn.ProjectID)
|
||||
for _, tf := range tfs {
|
||||
|
||||
for i, tf := range tfs {
|
||||
if len(tf.key) == 0 {
|
||||
// Match against mn.MetricGroup.
|
||||
b := marshalTagValue(kb.B, nil)
|
||||
|
@ -1571,6 +1572,11 @@ func matchTagFilters(mn *MetricName, tfs []*tagFilter, kb *bytesutil.ByteBuffer)
|
|||
return false, fmt.Errorf("cannot match MetricGroup %q with tagFilter %s: %s", mn.MetricGroup, tf, err)
|
||||
}
|
||||
if !ok {
|
||||
// Move failed tf to start.
|
||||
// This should reduce the amount of useless work for the next mn.
|
||||
if i > 0 {
|
||||
tfs[0], tfs[i] = tfs[i], tfs[0]
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
continue
|
||||
|
@ -1592,6 +1598,11 @@ func matchTagFilters(mn *MetricName, tfs []*tagFilter, kb *bytesutil.ByteBuffer)
|
|||
return false, fmt.Errorf("cannot match tag %q with tagFilter %s: %s", tag, tf, err)
|
||||
}
|
||||
if !ok {
|
||||
// Move failed tf to start.
|
||||
// This should reduce the amount of useless work for the next mn.
|
||||
if i > 0 {
|
||||
tfs[0], tfs[i] = tfs[i], tfs[0]
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
tagMatched = true
|
||||
|
@ -1599,6 +1610,11 @@ func matchTagFilters(mn *MetricName, tfs []*tagFilter, kb *bytesutil.ByteBuffer)
|
|||
}
|
||||
if !tagMatched && !tf.isNegative {
|
||||
// Matching tag name wasn't found.
|
||||
// Move failed tf to start.
|
||||
// This should reduce the amount of useless work for the next mn.
|
||||
if i > 0 {
|
||||
tfs[0], tfs[i] = tfs[i], tfs[0]
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue