Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- The first N rows will populate this array of rows in sorted order. When the N +1 row is fetched, it will be compared to the last row in the array. If it would go into slot N +1 in the array, it gets thrown out. Otherwise, it is added to this array and sorted and one of the existing rows is discarded. Your sort area holds N rows maximum, so instead of sorting one million rows, you sort N rows.
- */
- select *
- from
- (select *
- from t
- order by unindexed_column)
- where ROWNUM < :N;
- /*
- My question about this SQL statement are as follows:
- 1. Does order by executed on the last order(even though it's a subquery's order?)
- 2. Why this way just sort N rows? how could get the right answer if it does not sort the entire records?
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement