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
-

 

IN/ANY subquery transformation

An IN or ANY subquery that is guaranteed to return at most one row can be transformed into an equivalent expression subquery (a scalar subquery without the IN or ANY). The subquery must not be correlated. Subqueries guaranteed to return at most one row are:
  • Simple VALUES clauses
  • SELECTs returning a non-grouped aggregate
For example:
WHERE C1 IN (SELECT MIN(c1) FROM T)
can be transformed into
WHERE C1 = (SELECT MIN(c1) FROM T)

This transformation is considered before subquery materialization. If the transformation is performed, the subquery becomes materializable. In the example, if the IN subquery were not transformed, it would be evaluated anew for each row.

The subquery type transformation is shown in IN or ANY Subquery Transformations for Subqueries Returning a Single Row:
Table 1. IN or ANY Subquery Transformations for Subqueries Returning a Single Row
Before Transformation After Transformation
c1 IN (SELECT ...) c1 = (SELECT ...)
c1 = ANY (SELECT ...) c1 = (SELECT ...)
c1 <> ANY (SELECT ...) c1 <> (SELECT ...)
c1 > ANY (SELECT ...) c1 > (SELECT ...)
c1 >= ANY (SELECT ...) c1 >= (SELECT ...)
c1 < ANY (SELECT ...) c1 < (SELECT ...)
c1 <= ANY (SELECT ...) c1 <= (SELECT ...)
 

javadb@jdbcurl.com