mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-12 14:27:27 -08:00
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]
|
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…
Reference in a new issue