New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
optimize to posting group label value matching #7343
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Ben Ye <benye@amazon.com>
pkg/store/bucket.go
Outdated
@@ -2726,7 +2726,7 @@ func matchersToPostingGroups(ctx context.Context, lvalsFn func(name string) ([]s | |||
// Merge PostingGroups with the same matcher into 1 to | |||
// avoid fetching duplicate postings. | |||
for _, val := range values { | |||
pg, vals, err = toPostingGroup(ctx, lvalsFunc, val) | |||
pg, vals, err = toPostingGroup(ctx, lvalsFunc, val, len(values) == 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to check for len(values) == 1
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the difference we have with prometheus/prometheus#13958 is that we cache results of label values. So we cannot reuse vals
only if it is the last value we have. I have updated the condition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am actually a little bit unsure now if it reuses the values array causes any issue or not.
Updated: OK I think it is not safe to reuse the values other than reusing it once at the last value.
Changes
The optimization comes from prometheus/prometheus#13958 and https://github.com/prometheus/prometheus/blob/main/tsdb/querier.go#L358.
With latest Prometheus regex matcher optimization, now empty value
""
is optimized intoemptyStringMatcher
which only checks the value length https://github.com/prometheus/prometheus/blob/main/model/labels/regexp.go#L325.Since label values should be always non empty, we can optimize some cases to not run matching at all.
Verification