Description:
There are a couple of problems with the messages that are logged when I set the "logSlowQueries" option:
1) The execution time of the query is not logged.
2) The logged SQL has "?" in place of bind variables. This makes it impossible to run slow queries through EXPLAIN.
I made the changes below in my version of the JDBC driver to get around these problems. See the lines that begin with ">>>". I believe doing something similar in the core code would be useful to other developers.
--------------------
&& (elapsedTime > this.connection
.getSlowQueryThresholdMillis())) {
StringBuffer mesgBuf = new StringBuffer(
48 + this.originalSql.length());
mesgBuf.append(Messages
.getString("ServerPreparedStatement.15")); //$NON-NLS-1$
mesgBuf.append(this.connection
.getSlowQueryThresholdMillis());
>>> mesgBuf.append(" ms, duration: " + elapsedTime);
mesgBuf.append(Messages
.getString("ServerPreparedStatement.16")); //$NON-NLS-1$
mesgBuf.append(asSql(true));
this.connection.getLog().logWarn(mesgBuf.toString());
if (this.connection.getExplainSlowQueries()) {
>>> String queryAsString = asSql(true);
mysql.explainSlowQuery(queryAsString.getBytes(),
queryAsString);
}
}
How to repeat:
Set the logSlowQueries and slowQueryThresholdMillis properties and run a query that takes longer than the threshold to execute.
Suggested fix:
Log the SQL with the bound values in place, as well as the execution time.
Page generated in 0.049 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders. It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.
Description: There are a couple of problems with the messages that are logged when I set the "logSlowQueries" option: 1) The execution time of the query is not logged. 2) The logged SQL has "?" in place of bind variables. This makes it impossible to run slow queries through EXPLAIN. I made the changes below in my version of the JDBC driver to get around these problems. See the lines that begin with ">>>". I believe doing something similar in the core code would be useful to other developers. -------------------- && (elapsedTime > this.connection .getSlowQueryThresholdMillis())) { StringBuffer mesgBuf = new StringBuffer( 48 + this.originalSql.length()); mesgBuf.append(Messages .getString("ServerPreparedStatement.15")); //$NON-NLS-1$ mesgBuf.append(this.connection .getSlowQueryThresholdMillis()); >>> mesgBuf.append(" ms, duration: " + elapsedTime); mesgBuf.append(Messages .getString("ServerPreparedStatement.16")); //$NON-NLS-1$ mesgBuf.append(asSql(true)); this.connection.getLog().logWarn(mesgBuf.toString()); if (this.connection.getExplainSlowQueries()) { >>> String queryAsString = asSql(true); mysql.explainSlowQuery(queryAsString.getBytes(), queryAsString); } } How to repeat: Set the logSlowQueries and slowQueryThresholdMillis properties and run a query that takes longer than the threshold to execute. Suggested fix: Log the SQL with the bound values in place, as well as the execution time.