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
-

 

Combining ORDER BY and DISTINCT

Without a transformation, a statement that contains both DISTINCT and ORDER BY would require two separate sorting steps-one to satisfy DISTINCT and one to satisfy ORDER BY. (Currently, Derby uses sorting to evaluate DISTINCT. There are, in theory, other ways to accomplish this.) In some situations, Derby can transform the statement internally into one that contains only one of these keywords. The requirements are:
  • The columns in the ORDER BY list must be a subset of the columns in the SELECT list.
  • All the columns in the ORDER BY list are sorted in ascending order.

A unique index is not required.

For example:
SELECT DISTINCT miles, meal
FROM Flights
ORDER BY meal
is transformed into
SELECT DISTINCT miles, meal
FROM Flights
Note that these are not equivalent functions; this is simply an internal Derby transformation.
 

javadb@jdbcurl.com