Java DB

Apache Derby

Derby Performance Tuning

Derby Getting Started
Derby Reference Manual
Derby Developer's Guide
Derby Performance Tuning
Derby Server and Admin Guide
Derby Tools and Utilities
Derby Performance Tuning
-Performance tips and tricks
-Tuning databases and applications
-DML statements and performance
-Performance and optimization
-Locking and performance
-Non-cost-based optimizations
-Overriding the default optimizer behavior
-Selectivity and cardinality statistics
-Internal language transformations
-Predicate transformations
-Transitive closure
-View transformations
-Subquery processing and transformations
-Outer join transformations
-Sort avoidance
-Aggregate processing
-

 

Using the statement cache

The statement cache is enabled by default. You can use it to avoid extra compilation overhead:
  • Your application can use PreparedStatements instead of Statements.

    PreparedStatements are JDBC objects that you prepare (compile) once and execute multiple times. See the figure below. If your application executes statements that are almost but not exactly alike, use PreparedStatements, which can contain dynamic or IN parameters. Instead of using the literals for changing parameters, use question marks (?) as placeholders for such parameters. Provide the values when you execute the statement.

Derby supports the ParameterMetaData interface, new in JDBC 3.0. This interface describes the number, type, and properties of prepared statement parameters. See the Derby Developer's Guide for more information.
Figure 1. A connection need only compile a PreparedStatement once. Subsequent executions can use the same statement execution plan even if the parameter values are different. (PreparedStatements are not shared across connections.)
This figure shows one connection
with multiple executions of the same PreparedStatement, which uses the same
statement execution plan.
  • Even if your statement uses Statements instead of PreparedStatements, Derby can reuse the statement execution plan for the statements from the statement cache. Statements from any connection can share the same statement execution plan, avoiding compilation, by using the single-statement cache. The statement cache maintains statement plans across connections. It does not, however, maintain them across reboots. See the figure below.

    When, in the same database, an application submits an SQL Statement that exactly matches one already in the cache, Derby grabs the statement from the cache, even if the Statement has already been closed by the application.

    To match exactly with a statement already in the cache, the SQL Statement must meet the following requirements:

    • The text must match exactly
    • The current schema must match
    • The Unicode flag that the statement was compiled under must match the current connection's flag
Remember: If your application executes statements that are almost but not exactly alike, it is more efficient to use PreparedStatements with dynamic or IN parameters.
Figure 2. A database can reuse a statement execution plan when the SQL text matches a prior statement exactly. (PreparedStatements are much more efficient.)
This figure
shows how Derby can reuse a statement execution plan that is already in the
statement cache, even when the statement is executed from a different connection.

 

javadb@jdbcurl.com