I would like to run a query on AWS Athena with both a LIMIT
and an OFFSET
clause. I take it the former is supported while the latter is not. Is the
Using OFFSET
for pagination is very inefficient, especially for an analytic database like Presto that often has to perform a full table or partition scan. Additionally, the results will not necessarily be consistent between queries, so you can have duplicate or missing results when navigating between pages.
In an OLTP
database like MySQL or PostgreSQL, it's better to use a range query over an index, where you keep track of the last value seen on the previous page.
In an OLAP
database like Presto, it's better to cache the result set and perform pagination using the cached data. You don't want to run an expensive query over billions or trillions of rows each time the user clicks to go to a different page.
See these articles for a longer explanation of the problem and the index approach: