Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-1003959: Slow query in spring boot not showing the SQL executed. #1601

Closed
shawnlu-ikigai opened this issue Jan 10, 2024 · 6 comments · Fixed by #1604
Closed

SNOW-1003959: Slow query in spring boot not showing the SQL executed. #1601

shawnlu-ikigai opened this issue Jan 10, 2024 · 6 comments · Fixed by #1604
Assignees
Labels
enhancement The issue is a request for improvement or a new feature

Comments

@shawnlu-ikigai
Copy link

Please answer these questions before submitting your issue.
In order to accurately debug the issue this information is required. Thanks!

  1. What version of JDBC driver are you using?
    3.14.3

  2. What operating system and processor architecture are you using?
    Mac

  3. What version of Java are you using?
    java17

  4. 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
  1. 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**' []
  1. Can you set logging to DEBUG and collect the logs?

    https://community.snowflake.com/s/article/How-to-generate-log-file-on-Snowflake-connectors

  2. What is your Snowflake account identifier, if any? (Optional)

@github-actions github-actions bot changed the title Slow query in spring boot not showing the SQL executed. SNOW-1003959: Slow query in spring boot not showing the SQL executed. Jan 10, 2024
@shawnlu-ikigai
Copy link
Author

shawnlu-ikigai commented Jan 10, 2024

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.

@sfc-gh-wfateem sfc-gh-wfateem self-assigned this Jan 11, 2024
@sfc-gh-wfateem sfc-gh-wfateem added the enhancement The issue is a request for improvement or a new feature label Jan 11, 2024
@sfc-gh-wfateem
Copy link
Collaborator

@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.

@shawnlu-ikigai
Copy link
Author

Hi @sfc-gh-wfateem Thank you for timely response. Yes, enhancement makes more sense.

@sfc-gh-wfateem
Copy link
Collaborator

@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?

@shawnlu-ikigai
Copy link
Author

@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?

@sfc-gh-wfateem
Copy link
Collaborator

sfc-gh-wfateem commented Jan 15, 2024

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement The issue is a request for improvement or a new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants