Re: Profiling / recording query timing data with QueryInterceptor
Posted by: Filipe Silva
Date: October 10, 2019 04:45PM

Hi Johnathan,

Your solution doesn't look so bad. Maybe you don't need to use a ThreadLocal since the relevant part of the query interceptor workflow occurs while the connection-level mutex is held, so it will run from one thread at a time, and you are using it locally only.

But there are alternatives for sure. Another approach could be by injecting data into a comment in the query itself in the pre-process phase and then take it back in the post-process phase. You could do this by holding a reference to the JdbcConnection instance that created this QueryInterceptor right away in the init() method and then call JdbcConnection.setStatementComment() in the preProcess() and later on use the SQL Supplier from the postProcess and retrieve the data from it. If you do this don't forget to null the connection reference in the destroy() method as a safety measure to avoid memory leaks. Check this out to get an idea.

There are a few QueryInterceptor implementations throughout Connector/J code that you can also consult.

IHTH

Options: ReplyQuote




Sorry, only registered users may post in this forum.

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.