# Sort

Sorts are expensive operations especially on large tables where the rows do not fit in memory and spill to disk.

There are a number of different operations that promote sorts:

- Order by clauses
- Group by
- Sort merge join

Note that if the row source is already appropriately sorted then no sorting is required. In other words, if the fields you sort by happen to be defined by an Index in that particular order then sort operation is avoided. Therefore, whenever you see that an explicit sort operation has taken place, check if it can be avoided by using an index or sometimes just by making sure your are using an index's fields in the right order.

If no such index exists and the number of rows to be sorted is of high volume, please consult a DBA as this may justify adding a new index.

Parent topic: Common Issues to Be Aware of