# Non-cost-based optimizations

The optimizer makes some non-cost-based optimizations, which means that it does not consider them when determining the access path and join order.

If all the conditions are right, it makes the optimizations after the access path and join order are determined.

- Non-cost-based sort avoidance (tuple filtering)
  In most cases, Derby needs to perform two separate steps for statements that use DISTINCT or GROUP BY: first sorting the selected columns, then either discarding duplicate rows or aggregating grouped rows. Sometimes it is able to avoid sorting for these statements with tuple filtering.
- The MIN() and MAX() optimizations
  The optimizer knows that it can avoid iterating through all the source rows in a result to compute a MIN() or MAX() aggregate when data are already in the right order.

Parent topic: DML statements and performance
Related concepts
Performance and optimization
Locking and performance
Overriding the default optimizer behavior