Skip to content

Commit

Permalink
bench: add a benchmark of index join with ordering
Browse files Browse the repository at this point in the history
Release note: None
  • Loading branch information
yuzefovich committed Jul 18, 2022
1 parent a8568d2 commit 1f04334
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions pkg/bench/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1136,13 +1136,10 @@ func BenchmarkPlanning(b *testing.B) {
})
}

// BenchmarkIndexJoin measure an index-join with 1000 rows.
func BenchmarkIndexJoin(b *testing.B) {
defer log.Scope(b).Close(b)
ForEachDB(b, func(b *testing.B, db *sqlutils.SQLRunner) {
// The table will have an extra column not contained in the index to force a
// join with the PK.
create := `
func setupIndexJoinBenchmark(b *testing.B, db *sqlutils.SQLRunner) {
// The table will have an extra column not contained in the index to force a
// join with the PK.
create := `
CREATE TABLE tidx (
k INT NOT NULL,
v INT NULL,
Expand All @@ -1152,13 +1149,20 @@ func BenchmarkIndexJoin(b *testing.B) {
FAMILY "primary" (k, v, extra)
)
`
// We'll insert 1000 rows with random values below 1000 in the index.
// We'll then force scanning of the secondary index which will require
// performing an index join to get 'extra' column.
insert := "insert into tidx(k,v) select generate_series(1,1000), (random()*1000)::int"
// We'll insert 1000 rows with random values below 1000 in the index.
// We'll then force scanning of the secondary index which will require
// performing an index join to get 'extra' column.
insert := "insert into tidx(k,v) select generate_series(1,1000), (random()*1000)::int"

db.Exec(b, create)
db.Exec(b, insert)
db.Exec(b, create)
db.Exec(b, insert)
}

// BenchmarkIndexJoin measure an index-join with 1000 rows.
func BenchmarkIndexJoin(b *testing.B) {
defer log.Scope(b).Close(b)
ForEachDB(b, func(b *testing.B, db *sqlutils.SQLRunner) {
setupIndexJoinBenchmark(b, db)
b.ResetTimer()

for i := 0; i < b.N; i++ {
Expand All @@ -1167,6 +1171,20 @@ func BenchmarkIndexJoin(b *testing.B) {
})
}

// BenchmarkIndexJoinOrdering is the same as BenchmarkIndexJoin when the
// ordering needs to be maintained.
func BenchmarkIndexJoinOrdering(b *testing.B) {
defer log.Scope(b).Close(b)
ForEachDB(b, func(b *testing.B, db *sqlutils.SQLRunner) {
setupIndexJoinBenchmark(b, db)
b.ResetTimer()

for i := 0; i < b.N; i++ {
db.Exec(b, "select * from bench.tidx@idx where v < 1000 order by v")
}
})
}

// BenchmarkIndexJoinColumnFamilies is the same as BenchmarkIndexJoin, only with
// the table having two column families.
func BenchmarkIndexJoinColumnFamilies(b *testing.B) {
Expand Down

0 comments on commit 1f04334

Please sign in to comment.