From ac25bdc712da8f752147aeeb68e95dfdc17e30de Mon Sep 17 00:00:00 2001 From: "Xiaochao Dong (@damnever)" Date: Fri, 12 Aug 2022 10:06:09 +0800 Subject: [PATCH] Ref: https://github.com/thanos-io/thanos/pull/5588 --- pkg/store/bucket.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/store/bucket.go b/pkg/store/bucket.go index e6bc594cee7..4299754058b 100644 --- a/pkg/store/bucket.go +++ b/pkg/store/bucket.go @@ -1809,6 +1809,10 @@ func (r *bucketIndexReader) ExpandedPostings(ctx context.Context, ms []*labels.M keys = append(keys, allPostingsLabel) } + // Sorting will improve the performance dramatically if the dataset is relatively large + // since entries in the postings offset table was sorted by label name and value, + // the sequential reading is much faster. + sort.Sort(labels.Labels(keys)) fetchedPostings, err := r.fetchPostings(ctx, keys) if err != nil { return nil, errors.Wrap(err, "get postings") @@ -1890,7 +1894,6 @@ func checkNilPosting(l labels.Label, p index.Postings) index.Postings { func toPostingGroup(lvalsFn func(name string) ([]string, error), m *labels.Matcher) (*postingGroup, error) { if m.Type == labels.MatchRegexp { if vals := findSetMatches(m.Value); len(vals) > 0 { - sort.Strings(vals) toAdd := make([]labels.Label, 0, len(vals)) for _, val := range vals { toAdd = append(toAdd, labels.Label{Name: m.Name, Value: val})