Advertisement
vim_fans

Untitled

Sep 14th, 2021
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. /*
  2. 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.
  3. */
  4.  
  5. select *
  6. from
  7. (select *
  8. from t
  9. order by unindexed_column)
  10. where ROWNUM < :N;
  11.  
  12. /*
  13. My question about this SQL statement are as follows:
  14. 1. Does order by executed on the last order(even though it's a subquery's order?)
  15. 2. Why this way just sort N rows? how could get the right answer if it does not sort the entire records?
  16. */
  17.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement