Reputation: 1561
I am trying to understanding if Statement caching is useful in case of parametrized prepared statements.
As per my understanding
I am using JDBC/Snaq DB Pool/ MySQL database.
Statement Caching here is referred to two different cases:
My confusion is simple:
Hope I clarify my question.
Upvotes: 2
Views: 3819
Reputation:
JDBC
query caching is done on the database side of things and it caches the execution plan
, what the values of the parameters are is of no consequence, only that they are in the same order every time. If the values actually mattered there would be no point in caching anything.
Long time ago you had to use PreparedStatements
to get execution plans to be cached, but since about 2005 - 2008 all the modern databases worth mentioning cache execution plans regardless of the type of statement that is executed.
There is some minimal client side caching of the actual Java Object that represents the PreparedStatement
or CallableStatement
but any actual savings in time or space will be minimal in a modern JDBC
driver.
The overhead of calculating the execution plan
on the server side is orders of magnitude larger than doing to simple String
manipulation on the client side. This means there is no meaningful performance benefit on the client side of using a PreparedStatement
, there are other more important benefits like SQL Injection
protection to justify using one.
Upvotes: 5