lib/storage: move composite filters to the top during sorting

This commit is contained in:
Aliaksandr Valialkin 2021-02-17 20:22:30 +02:00
parent 2005d8212a
commit b4c7d5992b

View File

@ -257,9 +257,19 @@ type tagFilter struct {
graphiteReverseSuffix []byte graphiteReverseSuffix []byte
} }
func (tf *tagFilter) isComposite() bool {
k := tf.key
return len(k) > 0 && k[0] == compositeTagKeyPrefix
}
func (tf *tagFilter) Less(other *tagFilter) bool { func (tf *tagFilter) Less(other *tagFilter) bool {
// Move regexp and negative filters to the end, since they require scanning // Move composite filters to the top, since they usually match lower number of time series.
// all the entries for the given label. // Move regexp filters to the bottom, since they require scanning all the entries for the given label.
isCompositeA := tf.isComposite()
isCompositeB := tf.isComposite()
if isCompositeA != isCompositeB {
return isCompositeA
}
if tf.matchCost != other.matchCost { if tf.matchCost != other.matchCost {
return tf.matchCost < other.matchCost return tf.matchCost < other.matchCost
} }