偏移分页与光标分页 [英] Offset pagination vs Cursor pagination

查看:34
本文介绍了偏移分页与光标分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习分页,我有一些问题.

I am studying about pagination and I have some questions.

  1. 两种方法有什么区别?
  2. 基于游标的分页的最佳用例?
  3. 基于光标的分页可以转到特定页面吗?
  4. 基于光标的分页可以返回上一页吗?
  5. 两者之间是否存在性能差异?


我的想法

我认为基于游标的要复杂得多,这使得基于偏移的分页更加可取.只有以实时数据为中心的系统才需要基于游标的分页.


My thoughts

I think cursor based is much more complex which makes offset based pagination more desirable. Only real-time data centric system needs a cursor based pagination.

推荐答案

光标分页最常用于实时数据,因为新记录的添加频率很高,而且在读取数据时,您通常会首先看到最新的结果.在不同的情况下,偏移量和游标分页最有意义,因此它将取决于数据本身以及添加新记录的频率.查询静态数据时,仅靠性能成本可能不足以让您使用游标,因为它带来的额外复杂性可能超出您的需要.

Cursor pagination is most often used for real-time data due to the frequency new records are added and because when reading data you often see the latest results first. There different scenarios in which offset and cursor pagination make the most sense so it will depend on the data itself and how often new records are added. When querying static data, the performance cost alone may not be enough for you to use a cursor, as the added complexity that comes with it may be more than you need.

引自这篇很棒的博文,编码愉快!

另外,看看这个:

分页是这个问题的解决方案,它确保服务器只以小块的形式发送数据.基于光标的分页是我们在编号页面上推荐的方法,因为它消除了跳过项目和多次显示相同项目的可能性.在基于游标的分页中,常量指针(或游标)用于跟踪应从数据集中的何处获取下一个项目.

Pagination is a solution to this problem that ensures that the server only sends data in small chunks. Cursor-based pagination is our recommended approach over numbered pages, because it eliminates the possibility of skipping items and displaying the same item more than once. In cursor-based pagination, a constant pointer (or cursor) is used to keep track of where in the data set the next items should be fetched from.

此说明来自 Appolo GraphQL 文档.

这篇关于偏移分页与光标分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆