mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/storage: try potentially faster tag filters at first, then apply slower tag filters
The fastest tag filters are non-negative non-regexp, since they are the most specific. The slowest tag filters are negative regexp, since they require scanning all the entries for the given label.
This commit is contained in:
parent
d6ade02fd3
commit
e53f9e553d
1 changed files with 16 additions and 1 deletions
|
@ -1544,7 +1544,22 @@ func (is *indexSearch) searchMetricIDs(tfss []*TagFilters, tr TimeRange, maxMetr
|
|||
|
||||
func (is *indexSearch) updateMetricIDsForTagFilters(metricIDs *uint64set.Set, tfs *TagFilters, tr TimeRange, maxMetrics int) error {
|
||||
// Sort tag filters for faster ts.Seek below.
|
||||
sort.Slice(tfs.tfs, func(i, j int) bool { return bytes.Compare(tfs.tfs[i].prefix, tfs.tfs[j].prefix) < 0 })
|
||||
sort.Slice(tfs.tfs, func(i, j int) bool {
|
||||
// Move regexp and negative filters to the end, since they require scanning
|
||||
// all the entries for the given label.
|
||||
a := &tfs.tfs[i]
|
||||
b := &tfs.tfs[j]
|
||||
if a.isRegexp != b.isRegexp {
|
||||
return !a.isRegexp
|
||||
}
|
||||
if a.isNegative != b.isNegative {
|
||||
return !a.isNegative
|
||||
}
|
||||
if len(a.orSuffixes) != len(b.orSuffixes) {
|
||||
return len(a.orSuffixes) < len(b.orSuffixes)
|
||||
}
|
||||
return bytes.Compare(a.prefix, b.prefix) < 0
|
||||
})
|
||||
|
||||
minTf, minMetricIDs, err := is.getTagFilterWithMinMetricIDsCountOptimized(tfs, tr, maxMetrics)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue