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

SpringTransactionManager does not cache insert PreparedStatements #38

Open
badgerwithagun opened this issue Jun 4, 2020 · 2 comments
Open
Labels
bug Something isn't working performance Issue with performance

Comments

@badgerwithagun
Copy link
Member

In SpringTransactionManager, any time Transaction.prepareBatchStatement is called, a new PreparedStatement is opened. In other implementations, the statements are cached in the transaction and re-used for the same SQL statement.

Harmless functionally, but affects performance.

@badgerwithagun badgerwithagun added bug Something isn't working performance Issue with performance labels Jun 4, 2020
@badgerwithagun badgerwithagun changed the title SpringTransactionManager does not re-use insert PreparedStatements SpringTransactionManager does not cache insert PreparedStatements Jun 4, 2020
@tsg21
Copy link
Contributor

tsg21 commented Jun 20, 2020

In most cases, the JDBC driver (or the database itself) will implement prepared statement caching, no? I am not sure you really need to do anything here.

Note Hikari CP's comments on the topic

@badgerwithagun
Copy link
Member Author

This isn't really about statement caching as such. The trick that Transaction.prepareBatchStatement pulls is that any statement opened this way gets executeBatch called on it automatically at the end of the transaction, so if you write a 100 outbox records in one transaction they all get pushed out in one go in the same batch.

Because SpringTransactionManager isn't correctly caching, each insert is made in a separate request to the DB, which is indeed costly if you're doing a lot of "fan out" type behaviour (I am also planning on "fan in" capability...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working performance Issue with performance
Projects
None yet
Development

No branches or pull requests

2 participants