Some SQL statements require that data be ordered, including those with ORDER BY, GROUP BY, and DISTINCT. MIN() and MAX() aggregates also require ordering of data.
Derby can sometimes avoid sorting steps for:
Derby can also perform the following optimizations, but they are not based on cost: