mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-01-05 14:22:15 +01:00
lib/storage: speed up time series search for queries with multiple filters
Use optimized specialized binary search for uint64 metricIDs instead of generic sort.Search.
This commit is contained in:
parent
926290d73e
commit
33d9d63393
@ -1967,9 +1967,7 @@ func (is *indexSearch) updateMetricIDsForOrSuffixWithFilter(prefix []byte, metri
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
if metricID > sf[0] {
|
if metricID > sf[0] {
|
||||||
n := sort.Search(len(sf), func(i int) bool {
|
n := uint64BinarySearch(sf, metricID)
|
||||||
return i >= 0 && i < len(sf) && sf[i] >= metricID
|
|
||||||
})
|
|
||||||
sf = sf[n:]
|
sf = sf[n:]
|
||||||
if len(sf) == 0 {
|
if len(sf) == 0 {
|
||||||
break
|
break
|
||||||
@ -1992,6 +1990,20 @@ func (is *indexSearch) updateMetricIDsForOrSuffixWithFilter(prefix []byte, metri
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func uint64BinarySearch(a []uint64, v uint64) uint {
|
||||||
|
// Copy-pasted sort.Search from https://golang.org/src/sort/search.go?s=2246:2286#L49
|
||||||
|
i, j := uint(0), uint(len(a))
|
||||||
|
for i < j {
|
||||||
|
h := (i + j) >> 1
|
||||||
|
if h < uint(len(a)) && a[h] < v {
|
||||||
|
i = h + 1
|
||||||
|
} else {
|
||||||
|
j = h
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
|
||||||
var errFallbackToMetricNameMatch = errors.New("fall back to updateMetricIDsByMetricNameMatch because of too many index scan loops")
|
var errFallbackToMetricNameMatch = errors.New("fall back to updateMetricIDsByMetricNameMatch because of too many index scan loops")
|
||||||
|
|
||||||
var errMissingMetricIDsForDate = errors.New("missing metricIDs for date")
|
var errMissingMetricIDsForDate = errors.New("missing metricIDs for date")
|
||||||
|
Loading…
Reference in New Issue
Block a user