Skip to content

Commit

Permalink
perf: TSDB: Add fast-path to inversePostingsForMatcher (#12679)
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanGuedes authored Apr 19, 2024
1 parent 19bfef4 commit 402d1d7
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pkg/storage/stores/shipper/indexshipper/tsdb/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,22 @@ func postingsForMatcher(ix IndexReader, fpFilter index.FingerprintFilter, m *lab

// inversePostingsForMatcher returns the postings for the series with the label name set but not matching the matcher.
func inversePostingsForMatcher(ix IndexReader, fpFilter index.FingerprintFilter, m *labels.Matcher) (index.Postings, error) {
// Fast-path for MatchNotRegexp matching.
// Inverse of a MatchNotRegexp is MatchRegexp (double negation).
// Fast-path for set matching.
if m.Type == labels.MatchNotRegexp {
setMatches := findSetMatches(m.GetRegexString())
if len(setMatches) > 0 {
return ix.Postings(m.Name, fpFilter, setMatches...)
}
}

// Fast-path for MatchNotEqual matching.
// Inverse of a MatchNotEqual is MatchEqual (double negation).
if m.Type == labels.MatchNotEqual {
return ix.Postings(m.Name, fpFilter, m.Value)
}

vals, err := ix.LabelValues(m.Name)
if err != nil {
return nil, err
Expand Down

0 comments on commit 402d1d7

Please sign in to comment.