I am trying to understand how client-side emulation prepared statement in MySQL JDBC driver works.
Part 1 I read online that for prepared statements, there are four steps involved when a relational database handles a JDBC/SQL query and they are as follows:
- Parse the incoming SQL query
- Compile the SQL query
- Plan/optimize the data acquisition path
- Execute the optimized query / acquire and return data
The pre-execution of steps compiles the SQL statement and hence provides pre-optimization. For server-side prepared statement, an additional round-trip will be made to the database to precompile the SQL statement.
Question How do the client-side emulation prepared statement do step 3 if it does not make a round-trip to the database? Or does a client-side emulation prepared statement works differently?
Part 2 I have also done two experiments.
- Experiment 1 - using one client-side prepared statement for each query
- Experiment 2 - 'reusing' client-side prepared statements for the same query multiple times
Both experiments show improvement in performance such as response time. Experiment 1 has an improvement of about 18% and Experiment 2 has an improvement of about 30%.
Question
- Am I right to assume that preoptimization still exists for client-side prepared statement?
- If yes, does it preoptimizes in a way that is similar to server-side (the four steps mentioned in part 1) prepared statements or in a much different way?
- If no, why is there still improvement?
Thanks for your help!
Statement
? The performance benefits you observe most likely stem from caching. – Mark Rotteveel