Hi,
I would like to suggest reconsidering the default behavior of prepared statement caching.
In my opinion, configuration and caching strategies for prepared statements are more appropriate to be handled at the database level rather than at the application or driver level.
In fact, the HikariCP documentation explicitly advises against implementing statement caching outside the driver or database:
Many connection pools, including Apache DBCP, Vibur, c3p0 and others offer PreparedStatement caching. HikariCP does not. Why?
At the connection pool layer PreparedStatements can only be cached per connection. If your application has 250 commonly executed queries and a pool of 20 connections you are asking your database to hold on to 5000 query execution plans — and similarly the pool must cache this many PreparedStatements and their related graph of objects.
Most major database JDBC drivers already have a Statement cache that can be configured, including PostgreSQL, Oracle, Derby, MySQL, DB2, and many others. JDBC drivers are in a unique position to exploit database specific features, and nearly all of the caching implementations are capable of sharing execution plans across connections. This means that instead of 5000 statements in memory and associated execution plans, your 250 commonly executed queries result in exactly 250 execution plans in the database.
Using a statement cache at the pooling layer is an anti-pattern, and will negatively impact your application performance compared to driver-provided caches.
— Source: https://github.com/brettwooldridge/HikariCP#statement-cache
Additionally, our team has actually encountered increased PostgreSQL memory usage in production environments that appeared to be related to prepared statement caching behavior.
Because of these concerns, it may be safer to disable prepared statement caching by default and allow users to explicitly enable it when appropriate for their workload.
If this change is considered reasonable, I would be willing to contribute a small patch to adjust the default configuration.
Thank you.
Hi,
I would like to suggest reconsidering the default behavior of prepared statement caching.
In my opinion, configuration and caching strategies for prepared statements are more appropriate to be handled at the database level rather than at the application or driver level.
In fact, the HikariCP documentation explicitly advises against implementing statement caching outside the driver or database:
Additionally, our team has actually encountered increased PostgreSQL memory usage in production environments that appeared to be related to prepared statement caching behavior.
Because of these concerns, it may be safer to disable prepared statement caching by default and allow users to explicitly enable it when appropriate for their workload.
If this change is considered reasonable, I would be willing to contribute a small patch to adjust the default configuration.
Thank you.