Compiled Queries does not seem to reuse prepared statement

46 views
Skip to first unread message

Richeek Arya

unread,
Jan 17, 2017, 1:08:25 PM1/17/17
to Slick / ScalaQuery
Hello Slick folks,

I am trying to reuse my prepared statements use compiled queries but that does not seem to work.

I am trying to speed up "SELECT * FROM WHERE name=?" kind of queries in Play! + Scala app. I am using Play 2.4 + Scala 2.11 + play-slick-1.1.1 package. This package uses Slick-3.1 version.


My hypothesis was that slick generates Prepared statements from DBIO actions and they get executed. So I tried to cache them buy turning on flag cachePrepStmts=true However I still see "Preparing statement..." messages in the log which means that PS are not getting cached! How should one instructs slick to cache them?


Next I tried to use Compiled queries by output is still the same.

Here is my slick config:

slick.dbs.default {
 driver="slick.driver.MySQLDriver$"
 db {
 driver="com.mysql.jdbc.Driver"

 url="jdbc:mysql://localhost:3306/staging_db?useSSL=false&cachePrepStmts=true"

 user = "user"

 password = "passwd"

 numThreads = 1 // For not just one thread in HikariCP

 properties = {
   cachePrepStmts = true
   prepStmtCacheSize = 250
   prepStmtCacheSqlLimit = 2048
   }
 }
}



Here is the code:

val stTime = TimeUtil.getUtcTime
for (i <- 1 until 100) {
 
FutureUtils.blockFuture(db.run(compiledQuery(name).result), 10)
}
val endTime = TimeUtil.getUtcTime - stTime
Logger.info(s"Time Taken HERE $endTime")

And this is the kind of logs I get:
2017-01-16 21:34:00,510 DEBUG [db-1] s.j.J.statement [?:?] Preparing statement: select ...
Also timing of this is also remains the same. What is the desired output? Should I not see these statements anymore? How can I verify if Prepared statements are indeed reused.


Any help is greatly appreciated!


Reply all
Reply to author
Forward
0 new messages