optimize regex matching for empty label values in posting match (#14075)

Also update tests.

Signed-off-by: Ben Ye <benye@amazon.com>
pull/14112/head
Ben Ye 6 months ago committed by GitHub
parent a6316a5dcb
commit 6683895620
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -357,8 +357,8 @@ func inversePostingsForMatcher(ctx context.Context, ix IndexReader, m *labels.Ma
} }
res := vals[:0] res := vals[:0]
// If the inverse match is ="", we just want all the values. // If the match before inversion was !="" or !~"", we just want all the values.
if m.Type == labels.MatchEqual && m.Value == "" { if m.Value == "" && (m.Type == labels.MatchRegexp || m.Type == labels.MatchEqual) {
res = vals res = vals
} else { } else {
count := 1 count := 1

@ -2808,6 +2808,13 @@ func TestPostingsForMatchers(t *testing.T) {
}, },
}, },
// Not regex. // 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$")}, matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchNotRegexp, "n", "^1$")},
exp: []labels.Labels{ exp: []labels.Labels{

Loading…
Cancel
Save