optimize regex matching for empty label values in posting match (#14075)
Also update tests. Signed-off-by: Ben Ye <benye@amazon.com>
This commit is contained in:
parent
a6316a5dcb
commit
6683895620
|
@ -357,8 +357,8 @@ func inversePostingsForMatcher(ctx context.Context, ix IndexReader, m *labels.Ma
|
|||
}
|
||||
|
||||
res := vals[:0]
|
||||
// If the inverse match is ="", we just want all the values.
|
||||
if m.Type == labels.MatchEqual && m.Value == "" {
|
||||
// If the match before inversion was !="" or !~"", we just want all the values.
|
||||
if m.Value == "" && (m.Type == labels.MatchRegexp || m.Type == labels.MatchEqual) {
|
||||
res = vals
|
||||
} else {
|
||||
count := 1
|
||||
|
|
|
@ -2808,6 +2808,13 @@ func TestPostingsForMatchers(t *testing.T) {
|
|||
},
|
||||
},
|
||||
// Not regex.
|
||||
{
|
||||
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchNotRegexp, "i", "")},
|
||||
exp: []labels.Labels{
|
||||
labels.FromStrings("n", "1", "i", "a"),
|
||||
labels.FromStrings("n", "1", "i", "b"),
|
||||
},
|
||||
},
|
||||
{
|
||||
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchNotRegexp, "n", "^1$")},
|
||||
exp: []labels.Labels{
|
||||
|
|
Loading…
Reference in New Issue