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

bench: add a benchmark for INSERT RETURNING #88831

Merged
merged 1 commit into from
Sep 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions pkg/bench/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,34 @@ func runBenchmarkInsertSecondaryIndex(b *testing.B, db *sqlutils.SQLRunner, coun
b.StopTimer()
}

// runBenchmarkInsertReturning benchmarks inserting count rows into a table
// while performing rendering for the RETURNING clause.
func runBenchmarkInsertReturning(b *testing.B, db *sqlutils.SQLRunner, count int) {
defer func() {
db.Exec(b, `DROP TABLE IF EXISTS bench.insert`)
}()

db.Exec(b, `CREATE TABLE bench.insert (k INT PRIMARY KEY)`)

b.ResetTimer()
var buf bytes.Buffer
val := 0
for i := 0; i < b.N; i++ {
buf.Reset()
buf.WriteString(`INSERT INTO bench.insert VALUES `)
for j := 0; j < count; j++ {
if j > 0 {
buf.WriteString(", ")
}
fmt.Fprintf(&buf, "(%d)", val)
val++
}
buf.WriteString(` RETURNING k + 1, k - 1, k * 2, k / 2`)
db.Exec(b, buf.String())
}
b.StopTimer()
}

func BenchmarkSQL(b *testing.B) {
skip.UnderShort(b)
defer log.Scope(b).Close(b)
Expand All @@ -386,6 +414,7 @@ func BenchmarkSQL(b *testing.B) {
runBenchmarkInsertDistinct,
runBenchmarkInsertFK,
runBenchmarkInsertSecondaryIndex,
runBenchmarkInsertReturning,
runBenchmarkTrackChoices,
runBenchmarkUpdate,
runBenchmarkUpdateWithAssignmentCast,
Expand Down