Skip to content

Commit

Permalink
test: added a complex select
Browse files Browse the repository at this point in the history
Signed-off-by: Harshit Gangal <[email protected]>
  • Loading branch information
harshit-gangal committed Jan 2, 2025
1 parent e749db8 commit 8c74592
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions go/test/endtoend/preparestmt/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8c74592

Please sign in to comment.