OFFSET on AWS Athena

前端 未结 1 639
暗喜
暗喜 2021-01-05 16:08

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

相关标签:
1条回答
  • 2021-01-05 17:12

    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:

    • http://use-the-index-luke.com/no-offset
    • http://use-the-index-luke.com/sql/partial-results/fetch-next-page
    0 讨论(0)
提交回复
热议问题