OFFSET and LIMIT performance issue
Guess what?
LIMIT 5 OFFSET 200
has to walk over 200 rows before getting the 5 you want. Performance gets slower and slower.
A much better way is to use a UNIQUE key (possibly the PRIMARY KEY), and...
First time:
SELECT ... ORDER BY key LIMIT 5
Remember the last `key` fetched as $left_off
Next time, do
SELECT ... WHERE key > $left_off ORDER BY key LIMIT 5
Again, remember the last `key` fetched.
If you don't have a UNIQUE key, maybe you should add one for this purpose. Performance stays Order(1).
Subject
Written By
Posted
OFFSET and LIMIT performance issue
July 29, 2011 11:44PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.