# About the optimizer's choice of sort avoidance

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:

- statements with ORDER BY

  See Cost-based ORDER BY sort avoidance

Derby can also perform the following optimizations, but they are not based on cost:

- sort avoidance for DISTINCT and GROUP BYs

  See Non-cost-based sort avoidance (tuple filtering)

- statements with a MIN() aggregate

  See The MIN() and MAX() optimizations

- Cost-based ORDER BY sort avoidance

Parent topic: Derby's cost-based optimization
Related concepts
About the optimizer's choice of access path
About the optimizer's choice of join order
About the optimizer's choice of join strategy
About the system's selection of lock granularity
About the optimizer's selection of bulk fetch