ORDER BY performance
Date: 2000/08/11
Message-ID: <Fz502t.Mou_at_world.std.com>#1/1
Hi...
SELECT * from a,b WHERE b.select=x AND b.fk=a.pk ORDER BY a.date;
SELECT STATEMENT Cost =
SORT ORDER BY INDX_ADATE Cost = 1
NESTED LOOPS Cost = 1
INDEX RANGE SCAN PK_B Cost = 1 TABLE ACCESS BY INDEX ROWID A Cost = 2 INDEX RANGE SCAN PK_A Cost = 1
6 rows selected.
which is pretty succinct... What we're down to, though, is some experimental data suggesting that the sort gets considerable more expensive the more columns you have in the result record. I would have thought that sorting a temp result set wouldn't be implemented to shuffle all the bytes of the result records when ordering, but it looks like that's what's happening...
Are there any hints to get it to do more efficient sorts? I.e. just sort a list of temp ROWNUMs and return them in that order rather than shuffling the whole pile?
We tried implementing it as
SELECT * from a WHERE EXISTS (select * from b WHERE b.select=x AND
b.fk=a.pk) ORDER BY a.date;
and got a nice, short plan doing 2 index walks, but the problem was that it was walking all of a.date first, and then looking for EXISTS in b where the b test is much more restrictive. I added a hint to the second query to PUSH_SUBQ and we ended up back with the first explain plan again.
So, just to reiterate, is the Oracle SORT operation really inefficent in that it's shuffling all the bytes to do a sort? Is there any way to get it to do more efficient sorting?