Skip to content

Commit 45013e1

Browse files
authored
skip match label values for certain matchers (#8084)
Signed-off-by: yeya24 <[email protected]>
1 parent 2367777 commit 45013e1

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pkg/store/bucket.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2978,6 +2978,12 @@ func toPostingGroup(ctx context.Context, lvalsFn func(name string) ([]string, er
29782978
return nil, nil, err
29792979
}
29802980

2981+
// If the matcher is ="" or =~"", it is the same as removing all values for the label.
2982+
// We can skip calling `Matches` here.
2983+
if m.Value == "" && (m.Type == labels.MatchEqual || m.Type == labels.MatchRegexp) {
2984+
return newPostingGroup(true, m.Name, nil, vals), vals, nil
2985+
}
2986+
29812987
for i, val := range vals {
29822988
if (i+1)%checkContextEveryNIterations == 0 && ctx.Err() != nil {
29832989
return nil, nil, ctx.Err()
@@ -3006,6 +3012,12 @@ func toPostingGroup(ctx context.Context, lvalsFn func(name string) ([]string, er
30063012
return nil, nil, err
30073013
}
30083014

3015+
// If the matcher is !="" or !~"", it is the same as adding all values for the label.
3016+
// We can skip calling `Matches` here.
3017+
if m.Value == "" && (m.Type == labels.MatchNotEqual || m.Type == labels.MatchNotRegexp) {
3018+
return newPostingGroup(false, m.Name, vals, nil), vals, nil
3019+
}
3020+
30093021
var toAdd []string
30103022
for i, val := range vals {
30113023
if (i+1)%checkContextEveryNIterations == 0 && ctx.Err() != nil {

0 commit comments

Comments
 (0)