Bug #12229 executeQuery() hangs when using explainSlowQueries
Submitted: 27 Jul 2005 21:00 Modified: 17 Oct 2005 19:43
Reporter: Boris Burtin Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version:3.1.10 OS:Any (*)
Assigned to: Mark Matthews CPU Architecture:Any

[27 Jul 2005 21:00] Boris Burtin
Description:
I'm seeing a hang in the JDBC driver when using the "explainSlowQueries" property.

I'm trying to do a debug run of my application and gather performance numbers for all the queries in the system. So I set the following JDBC connection properties:

props.put("profileSQL", "true");
props.put("logger", MySqlTraceLogger.class.getName());
props.put("slowQueryThresholdMillis", "0");
props.put("logSlowQueries", "true");

Everything works great. Then when I add the following line:

props.put("explainSlowQueries", "true");

and rerun the same test, my application hangs. I spent a few minutes debugging the problem. It looks like the EXPLAIN succeeds, but then the subsequent call to executeQuery() hangs. I copied the stack trace below.

---------------------

SocketInputStream.socketRead0(FileDescriptor, byte[], int, int, int) line: not available [native method]
SocketInputStream.read(byte[], int, int) line: not available
ReadAheadInputStream.fill(int) line: 105
ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(byte[], int, int) line: 148
ReadAheadInputStream.read(byte[], int, int) line: 176
MysqlIO.readFully(InputStream, byte[], int, int) line: 1899
MysqlIO.readPacket() line: 481
MysqlIO.readAllResults(Statement, int, int, int, boolean, String, Buffer, boolean, long, boolean) line: 1410
ServerPreparedStatement.serverExecute(int, boolean) line: 1133
ServerPreparedStatement.executeInternal(int, Buffer, boolean, boolean, boolean) line: 670
ServerPreparedStatement(PreparedStatement).executeQuery() line: 1024
DelegatingPreparedStatement.executeQuery() line: 205

How to repeat:
Set the following properties on the connection:

props.put("profileSQL", "true");
props.put("logger", MySqlTraceLogger.class.getName());
props.put("slowQueryThresholdMillis", "0");
props.put("logSlowQueries", "true");
props.put("explainSlowQueries", "true");

and run executeQuery() several times for a PreparedStatement.

Suggested fix:
Setting "explainSlowQueries" should not affect the functionality of the JDBC driver.
[28 Jul 2005 14:33] Aleksey Kishkin
testcase attached
[28 Jul 2005 14:34] Aleksey Kishkin
testcase

Attachment: Bug12229.java (text/x-java), 1.39 KiB.