diff --git a/go/test/endtoend/preparestmt/benchmark_test.go b/go/test/endtoend/preparestmt/benchmark_test.go index 925068f17cc..78f8649f2e5 100644 --- a/go/test/endtoend/preparestmt/benchmark_test.go +++ b/go/test/endtoend/preparestmt/benchmark_test.go @@ -38,6 +38,32 @@ func BenchmarkPreparedStmt(b *testing.B) { selectStmt := `select id, name, age, email from sks.t1 where age between ? and ? and is_active = ? limit ?` updateStmt := `update sks.t1 set is_active = ? where id = ?` deleteStmt := `delete from sks.t1 where is_active = ? and age = ?` + complexStmt := `SELECT + user.id AS user_id, + user.name AS user_name, + user.age AS user_age, + user.email AS user_email, + parent.name AS parent_name, + manager.name AS manager_name, + COUNT(child.id) AS total_children +FROM + sks.t1 AS user +LEFT JOIN + sks.t1 AS parent ON user.id = parent.id AND parent.age = ? +LEFT JOIN + sks.t1 AS manager ON user.id = manager.id AND manager.is_active = ? +LEFT JOIN + sks.t1 AS child ON user.id = child.id +WHERE + user.is_active = ? + AND user.age BETWEEN ? AND ? +GROUP BY + user.id, parent.name, manager.name +HAVING + total_children > ? +ORDER BY + total_children DESC, user.created_at ASC +LIMIT ?;` iStmt, err := dbo.Prepare(insertStmt) if err != nil { @@ -73,6 +99,25 @@ func BenchmarkPreparedStmt(b *testing.B) { } }) + cStmt, err := dbo.Prepare(complexStmt) + if err != nil { + b.Fatal(err) + } + defer sStmt.Close() + + b.Run("Complex Select", func(b *testing.B) { + b.ResetTimer() + for i := 0; i < b.N; i++ { + age := rand.IntN(80) + active := rand.IntN(2) + r, err := cStmt.Query(age, active, active, age, age+20, rand.IntN(10), rand.IntN(5)) + if err != nil { + b.Fatal(err) + } + r.Close() + } + }) + uStmt, err := dbo.Prepare(updateStmt) if err != nil { b.Fatal(err)