Skip to content
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

Improving "Sparse postings" intersection #13971

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion tsdb/index/postings.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,15 +487,19 @@ func (it *intersectPostings) At() storage.SeriesRef {
func (it *intersectPostings) doNext() bool {
Loop:
for {
cont := false
for _, p := range it.arr {
if !p.Seek(it.cur) {
return false
}
if p.At() > it.cur {
it.cur = p.At()
continue Loop
cont = true
}
}
if cont {
continue Loop
}
return true
}
}
Expand Down
10 changes: 9 additions & 1 deletion tsdb/querier_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func BenchmarkQuerier(b *testing.B) {
}

for n := 0; n < 10; n++ {
addSeries(labels.FromStrings("a", strconv.Itoa(n)+postingsBenchSuffix))
for i := 0; i < 100000; i++ {
addSeries(labels.FromStrings("i", strconv.Itoa(i)+postingsBenchSuffix, "n", strconv.Itoa(n)+postingsBenchSuffix, "j", "foo"))
// Have some series that won't be matched, to properly test inverted matches.
Expand Down Expand Up @@ -98,7 +99,9 @@ func BenchmarkQuerier(b *testing.B) {
func benchmarkPostingsForMatchers(b *testing.B, ir IndexReader) {
ctx := context.Background()

a1 := labels.MustNewMatcher(labels.MatchEqual, "a", "1"+postingsBenchSuffix)
n1 := labels.MustNewMatcher(labels.MatchEqual, "n", "1"+postingsBenchSuffix)
n0_1 := labels.MustNewMatcher(labels.MatchEqual, "n", "0_1"+postingsBenchSuffix)
nX := labels.MustNewMatcher(labels.MatchEqual, "n", "X"+postingsBenchSuffix)

jFoo := labels.MustNewMatcher(labels.MatchEqual, "j", "foo")
Expand Down Expand Up @@ -134,6 +137,7 @@ func benchmarkPostingsForMatchers(b *testing.B, ir IndexReader) {
{`j="foo",n="1"`, []*labels.Matcher{jFoo, n1}},
{`n="1",j!="foo"`, []*labels.Matcher{n1, jNotFoo}},
{`n="1",i!="2"`, []*labels.Matcher{n1, iNot2}},
{`n="0_1",j="foo,a="1"`, []*labels.Matcher{n0_1, jFoo, a1}},
{`n="X",j!="foo"`, []*labels.Matcher{nX, jNotFoo}},
{`i=~"1[0-9]",j=~"foo|bar"`, []*labels.Matcher{iCharSet, jFooBar}},
{`j=~"foo|bar"`, []*labels.Matcher{jFooBar}},
Expand Down Expand Up @@ -173,8 +177,12 @@ func benchmarkPostingsForMatchers(b *testing.B, ir IndexReader) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := PostingsForMatchers(ctx, ir, c.matchers...)
p, err := PostingsForMatchers(ctx, ir, c.matchers...)
require.NoError(b, err)
// Iterate over the postings
for p.Next() {
// Do nothing
}
}
})
}
Expand Down