Bug #60968 Cancelled queries not reported in slow query log
Submitted: 24 Apr 2011 18:40 Modified: 25 Apr 2011 19:50
Reporter: Greg Kemnitz Email Updates:
Status: Verified Impact on me:
Category:MySQL Server: Errors Severity:S3 (Non-critical)
Version:5.1.43sp1-enterprise-gpl-advanced-log OS:Any
Assigned to: CPU Architecture:Any
Triage: Needs Triage: D5 (Feature request)

[24 Apr 2011 18:40] Greg Kemnitz
We have an interactive data-browser product that occasionally produces slow queries that users can cancel.  Currently, there's no easy way to trap these queries if they get cancelled before they complete.

How to repeat:
1.  start a slow query, ie a count(*) from a big table.
2.  cancel it using control-c in mysql cmd line
3.  the query won't show up in the slow query log.

Suggested fix:
log slow cancelled queries in the slow query log.
[25 Apr 2011 9:59] Valeriy Kravchuk
Please, clarify the following details:

1. What exact version of server, x.y.z, you are working with.
2. What exact SQL statement you tried to cancel?
3. How your tool cancels SQL statement? Does it send some KILL command to the server?
[25 Apr 2011 17:02] Greg Kemnitz
1. The version is as above
2. The SQL is dynamically generated, but is usually "insert (into temp table) select" or "select" queries.
3. The "kill" is done using Hibernate or JDBC APIs, although you can see the same behavior by running two "mysql" command lines, executing a slow query on one, and execute an explicit "kill <conn>" on the other.

We made a simple slow query logger that catches very slow cancelled queries by using a query against the information schema.  It runs every minute to avoid loading the system, but we'd strongly prefer that the slow query log itself capture this info.
[25 Apr 2011 19:50] Sveta Smirnova
Thank you for the reasonable feature request.

Alternatively you can use general query log.