When I attempt to do something like
SELECT Max(ObjectId) FROM Objects;
I see that in the explain-plan that this is performed by doing a sort. Now, sorting (which I guess would require something in the complexity of O(nlogn)
) must be much costlier than just scanning each row and remembering the max value (which could be done in O(n)
).
Am I missing something here? Is oracle really performing a sort or does the explain-plan just use the description "sort" for describing a simple scan of all values in the ObjectId column? If oracle really does perform a "real sort", is there a good reason for doing this that I am missing?
Thanks in advance!