Skip to content

Commit

Permalink
test: added join query with simple route
Browse files Browse the repository at this point in the history
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
  • Loading branch information
harshit-gangal committed Jan 2, 2025
1 parent e749db8 commit b948875
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions go/test/endtoend/preparestmt/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ func BenchmarkPreparedStmt(b *testing.B) {
updateStmt := `update sks.t1 set is_active = ? where id = ?`
deleteStmt := `delete from sks.t1 where is_active = ? and age = ?`

joinStmt := `SELECT
user.id AS user_id
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.id = ?
AND parent.id = ?
AND manager.id = ?`

iStmt, err := dbo.Prepare(insertStmt)
if err != nil {
b.Fatal(err)
Expand Down Expand Up @@ -73,6 +89,26 @@ func BenchmarkPreparedStmt(b *testing.B) {
}
})

jStmt, err := dbo.Prepare(joinStmt)
if err != nil {
b.Fatal(err)
}
defer jStmt.Close()

b.Run("Join Select:Simple Route", func(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
age := rand.IntN(80)
active := rand.IntN(2)
id := rand.IntN(2000)
r, err := jStmt.Query(age, active, active, id, id, id)
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 b948875

Please sign in to comment.