query timeout

263 views
Skip to first unread message

Olivier Poppon

unread,
Apr 7, 2016, 3:29:29 PM4/7/16
to ScalikeJDBC Users Group
Hello,

I have using 2.3.+ in a play framework application.
I have a long query that I would like to stop after 3seconds (as an example) and throw an exception if it takes longer than that to execute.

I have use queryTimeout( 3 ) on my query:
val rawPositions = NamedDB(Symbol(aFilter.database.label)) readOnly { implicit session =>
sql"$mySQL"
.one( PositionEntity as "p" )
.toMany(**)
.map((pos:Position, evt:Seq[Event]) => pos.copy(events=evt.toList))
.queryTimeout(3)
.list.apply()

But on the logs statement, I can see that the request can still take longer than 3 seconds.

Maybe I don't understand the correct meaning of this method ?

Thank for your help
Olivier

Kazuhiro Sera

unread,
Apr 7, 2016, 7:27:15 PM4/7/16
to Olivier Poppon, ScalikeJDBC Users Group
If the timeout seconds is ignored, it should be a problem of JDBC
driver side. But I couldn't find MySQL JDBC driver's unresolved issue.

https://docs.oracle.com/javase/8/docs/api/java/sql/Statement.html#setQueryTimeout-int-

The following page tells us what the query timeout does.

http://download.nust.na/pub6/mysql/doc/refman/5.5/en/connector-j-reference-implementation-notes.html

>require a separate connection to issue the KILL QUERY statement. In the case of setQueryTimeout(), the implementation creates an additional thread to handle the timeout functionality.

Something happens when issuing kill query?

Please share us if you find more information about this issue.

-Kaz
> --
> You received this message because you are subscribed to the Google Groups
> "ScalikeJDBC Users Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to scalikejdbc-users...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Olivier Poppon

unread,
Apr 19, 2016, 11:58:45 AM4/19/16
to ScalikeJDBC Users Group, opo...@gmail.com
Hi,

Sorry for the delay. I had to work on other projects.

I think I got something interesting...

Doing this :
sql"SELECT * from test"
.queryTimeout(1)
map( ... ).list.apply

generates the MySQLTimeoutException

BUT when doing this:
sql'SELECT * from test join test2 on test..."
.queryTimeout(1)
.one(...)
.toMany(...)
.map(...).list.apply

The query is executed beyond the timeout and no exception is thrown


PS : I hope you or your friends/family havn't suffered from the earthquakes.


Kazuhiro Sera

unread,
Apr 19, 2016, 12:08:14 PM4/19/16
to Olivier Poppon, ScalikeJDBC Users Group
>The query is executed beyond the timeout and no exception is thrown

Hmm, it may be a bug.

>PS : I hope you or your friends/family havn't suffered from the earthquakes.

Thank you for your kindness.

-Kaz

Kazuhiro Sera

unread,
May 3, 2016, 9:13:39 PM5/3/16
to Olivier Poppon, ScalikeJDBC Users Group
>>The query is executed beyond the timeout and no exception is thrown
>Hmm, it may be a bug.

Fixed this since 2.4.0. https://github.com/scalikejdbc/scalikejdbc/pull/517
Reply all
Reply to author
Forward
0 new messages