SNOW-1003959: Slow query in spring boot not showing the SQL executed.
Closed this issue · 6 comments
Please answer these questions before submitting your issue.
In order to accurately debug the issue this information is required. Thanks!
-
What version of JDBC driver are you using?
3.14.3 -
What operating system and processor architecture are you using?
Mac -
What version of Java are you using?
java17 -
What did you do?
I am following this page: https://vladmihalcea.com/hibernate-slow-query-log/
I added following config for a spring boot application:
logging.level.org.hibernate.SQL_SLOW.level=INFO
spring.jpa.properties.hibernate.session.events.log.LOG_QUERIES_SLOWER_THAN_MS=500
-
What did you expect to see?
I am expecting to see the SQL execute:
2024-01-10 10:21:52.239 INFO 82501 --- [ scheduling-1] org.hibernate.SQL_SLOW : SlowQuery: 1459 milliseconds. SQL: 'SELECT * FROM TABLE WHERE ...' []
However, What I am seeing looks as following:
2024-01-10 10:21:52.239 INFO 82501 --- [ scheduling-1] org.hibernate.SQL_SLOW : SlowQuery: 1459 milliseconds. SQL: '**HikariProxyPreparedStatement@1803888113 wrapping net.snowflake.client.jdbc.SnowflakePreparedStatementV1@644732**' []
-
Can you set logging to DEBUG and collect the logs?
https://community.snowflake.com/s/article/How-to-generate-log-file-on-Snowflake-connectors
-
What is your Snowflake account identifier, if any? (Optional)
I checked PgPreparedStatement.java for postgres
and found there is a toString method:
public String toString() {
if (preparedQuery == null) {
return super.toString();
}
return preparedQuery.query.toString(preparedParameters);
}
There is no toString
method in SnowflakePreparedStatementV1.java
. adding that method might fix the issue already.
That's my assumption. Hoping it will helps.
@shawnlu-ikigai thanks for reporting this. Would you agree that this is more of an enhancement request rather than a bug?
I think that output you're seeing is exactly because as you pointed out, we didn't override the toString() method, so it should theoretically be a straightforward thing to implement to address your problem. I'll take a look.
Hi @sfc-gh-wfateem Thank you for timely response. Yes, enhancement makes more sense.
@shawnlu-ikigai I made the change and test it locally so PR #1604 will address your problem. However, I just had an after thought and I think I can improve on this by adding a query ID in addition to the SQL text.
Do you think that will be helpful as well?
@sfc-gh-wfateem that's really quick man. Yeah query ID for sure will help.
When do you think this will be merged and pushed to mvnrepository?
@shawnlu-ikigai the change was just merged but it's past the code freeze for January's release, so this will make its way in the JDBC driver's February release.