Oracle 10g Sorting

| Comments (0)

[Moozik: The Mission - Naked and Savage]

You can never really guarantee the order in which your results will return to you unless you use an order by clause. Nothing earth shattering there. Except that in versions prior to 10.2, Oracle was quite happy to let you get away with just a group by. 10.2 changed all that as a new sorting algorithm was introduced.

Oracle introduced a new sorting algorithm (sometimes known as the Version 2 sort, which is how it is labelled in the 10032 trace) in 10.2.

The previous algorithm was effectively building an in-memory index on the incoming data using a balanced binary tree and seeking to the right (i.e. optimised towards data that appeared in the correct order and keeping such data in the order of appearance - hence the apparent sorting of rowids in our example in 9i).

The CPU and memory overheads for this algorithm are a bit fierce for large sorts, so the new algorithm does something completely different (possibly based on a variant of the heapsort, though it isn’t actually a heapsort) which is more efficient on memory and CPU. It has the side-effect though, of re-ordering incoming rows even when the data is not arriving out of order.

Not that I'd been lazy and just had group by's you understand. Ahem.

Leave a comment

About this Entry

This page contains a single entry by kev published on November 19, 2007 4:37 PM.

Negative Numbers Are Hard was the previous entry in this blog.

Gridrunner+++ is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.