分页与游标或使用偏移量之间的成本差异是什么? [英] What is the cost difference between paging with a cursor or using offset?

查看:111
本文介绍了分页与游标或使用偏移量之间的成本差异是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用[下一页]和[上一页]按钮创建结果页时,使用游标执行此操作或使用偏移量之间的成本差异是多少?每种技术的优缺点是什么?



作为一个具体的例子,阅读结果100-110的成本是多少。

我已经看到偏移量使用小数据存储操作的声明,并且有人声称它为每个跳过的实体使用了完整的读取操作。

使用游标,我已经读过它们不能向后翻页,但我注意到一个新的 Cursor.reverse()方法今天的第一次。



我假设使用游标的缺点是你不能通过数字跳转到页面,例如直接返回结果90-100。

解决方案

跳过结果让您每次跳过的结果都会导致数据存储小操作。它也比使用游标慢。



正如您所看到的,现在可以使用反向游标,只要查询的适当索引存在,就可以向后翻页。



如果您想跳至页面'n',您当然可以同时使用光标和偏移量。


When creating a results page with [Next Page] and [Prev Page] buttons, what is the cost difference between using a cursor to do this or using offset? And what are the pros and cons of each technique?

As a concrete example, what is the cost of reading results 100-110.

I have seen claims that offset uses "small datastore operations" and some that claim it uses a full "read operation" for each entity skipped.

Using cursors, I have read that they cannot page backwards, but I noticed a new Cursor.reverse() method for the first time today.

I assume that the disadvantages of using a cursor are that you cannot jump to a page by number e.g. straight to results 90-100.

解决方案

Skipping results costs you a datastore small operation per skipped result. It's also slower than using cursors.

As you observe, reverse cursors are now available, which will allow you to page backwards, as long as the appropriate indexes for your query exist.

You can, of course, combine both cursors and offsets, if you want to skip to page 'n'.

这篇关于分页与游标或使用偏移量之间的成本差异是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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