rails/arel — pull request #160 by t0m (2013-01-31 02:50:11+00:00)
Title: Small change to oracle paging code to trigger stopkey optimization

I previously added a comment on [issue 99](https://github.com/rails/arel/issues/99#issuecomment-12000009) about a quick tweak to the paging code and I didn't want it to go to waste. Changing the `raw_rnum_` predicate from:

`WHERE raw_rnum_ BETWEEN :low and :high`

to: `WHERE raw_rnum_ >= :low and rownum <= :limit`

allows the optimizer to use the [count stopkey](http://decipherinfosys.wordpress.com/2007/08/09/paging-and-countstopkey-optimization/) optimization and return the same results noticeably quicker.

Here's the execution plan for my DB with the current code:
![no-stopkey](https://f.cloud.github.com/assets/144980/113364/45650ad4-6b4f-11e2-8304-32322f370626.png)

And with the changes:
![stopkey](https://f.cloud.github.com/assets/144980/113365/4b4cb582-6b4f-11e2-85cd-24ec91541cd1.png)

I've had this change running for almost a month in a few of my apps on 11G as well as some test projects on XE and everything seems cool, maybe someone else could give it a try and see if they get the same results?