I wouldn’t have used the expression “clustering factor” in this context (data can be well clustered without being well-ordered) but you are essentially correct.

For this type of “short sort”, the work done and the memory used do depend on the arrival order of the data.

(Footnote: My memory from the days when I did computer science is that every sort algorithm was subject to some boundary cases where the data order was “bad for” the algorithm – basically the order of input always affected the amount of work needed and the worst case was always very bad.)

]]>I’ve re-read the posting and don’t see any confusion between sorting and comparing. What I see is that we can infer from the change in the number of comparisons that something different has happened during sorting.

One of your commnet, however, highlights the ambiguity that surrounds the word “sorting” in this context.

When as ask for 10 rows, the mechanism does not “sort” 1,000,000 rows because it does NOT get 1,000,000 rows into order; it gets 10 rows into order, and 999,990 rows which are not well-ordered.

]]>No smoke, at least not intentionally. If you think about the two comments I made about the data, one of them tells you what it * looks like*, the other tells you what it is supposed to

But I think that here you are mixing up a bit of ideas.

The first is the number of rows that there is in the table. It’s 1.000.000 full stop. So Oracle sort 1.000.000 rows, i.e. Oracle reads 1.000.000 rows and “do-some-magic” so we get them ordered.

The second idea is how many comparisons Oracle does to sort that rows. “Comparisons” are a complete different kind of objects and they depends on the algorithm that is used to sort (i.e. qsort is better that bubble sort because it does less comparisons).

Reading your post, I get the idea that you mean “Oracle have 1.000.000 rows but it sorts 2.000.000 rows” (as it multiplies it), well this is wrong, at least “we can say that Oracle do 3.000.000 comparisons to sort 1.000.000″ but the number of rows doesn’t change.

Bye,

Antonio

ordered

—- Sort Statistics ——————————

Input records 1048576

Output records 10

Total number of comparisons performed 1048575

Comparisons performed by in-memory sort 1048575

Total amount of memory used 2048

Uses version 1 sort

reversed

—- Sort Statistics ——————————

Input records 1048576

Output records 1048576

Total number of comparisons performed 5242856

Comparisons performed by in-memory sort 5242856

Total amount of memory used 1337344

Uses version 1 sort

randomised

—- Sort Statistics ——————————

Input records 1048576

Output records 135

Total number of comparisons performed 1049022

Comparisons performed by in-memory sort 1049022

Total amount of memory used 2048

Uses version 1 sort

All of them are using Version 1 sort. How can I force Oracle to use Version 2 sort?

and how can I force it to use version 1 sort?