Unnecessary Sorting, Grouping and Distinct

Oracle may need to perform sorts under the following circumstances:

The sorting in Oracle falls into two major categories: disk sorts and memory sorts. The sorting if possible should be performed in memory. Please note that memory is allocated for each session, so even comparatively small values can translate into large amounts of system memory. Whenever a sort is performed on disk instead of memory it will generally cause bad performance, especially on large sorts.

When using 'Explain Plan', the statistics section indicates the nature of the sorting 'Oracle Optimizer' decides for the particular operation.

Examples of sorting in 'Explain Plan' and their explanation:

Sorting Description
SORT AGGREGATE The group function SUM() operation
SORT GROUP BY GROUP BY clause
SORT JOIN A by-product of the MERGE JOIN operation
SORT ORDER BY The ORDER BY clause
SORT UNIQUE A DISTINCT clause or a by product of a UNION operation

Rules

Avoid "accidental" sorts. Sorting always affects performance negatively.

Different things can cause Oracle to perform a sort that you don't really require: