如何在 DynamoDB 中反向扫描索引? [英] How can I Scan an index in reverse in DynamoDB?

查看:27
本文介绍了如何在 DynamoDB 中反向扫描索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用 DynamoDB,但在扫描时遇到问题.我可以使用 ExclusiveStartKey 以转发顺序获得分页结果.但是,无论我将 ScanIndexForward 设置为 true 还是 false,我都会从我的扫描操作中获得前向顺序的结果.如何从 DynamoDB 中的 Scan 获得相反顺序的结果?

I am currently using DynamoDB and having a problem scanning. I am able to get paged results in forward order by using the ExclusiveStartKey. However, regardless of whether I set ScanIndexForward true or false, I get results in forward order from my scan operation. How can i get results in reverse order from a Scan in DynamoDB?

推荐答案

ScanIndexForward 是通过您正在查询的表或索引的范围键以降序获取项目的正确方法.来自 AWS API 参考:

ScanIndexForward is the correct way to get items in descending order by the range key of the table or index you are querying. From the AWS API Reference:

指定升序 (true) 或降序 (false) 的值遍历索引.DynamoDB 返回的结果反映了请求的顺序由范围键确定.如果数据类型是Number,按数字顺序返回结果.对于字符串类型,结果按 ASCII 字符代码值的顺序返回.为了类型 Binary,DynamoDB 将二进制数据的每个字节视为无符号当它比较二进制值时.

A value that specifies ascending (true) or descending (false) traversal of the index. DynamoDB returns results reflecting the requested order determined by the range key. If the data type is Number, the results are returned in numeric order. For type String, the results are returned in order of ASCII character code values. For type Binary, DynamoDB treats each byte of the binary data as unsigned when it compares binary values.

根据 扫描文档,我得出结论没有办法反向扫描.但是,如果您需要这样做,我会说您没有正确使用 DynamoDB.在为 DyanmoDB 之类的数据库设计架构时,您应该根据预期的查询来规划架构,以确保几乎所有应用程序查询都具有良好的索引.扫描更多地用于系统管理员操作或用于输入 MapReduce 或分析.扫描操作总是扫描整个表,然后过滤掉值以提供所需的结果,本质上增加了从结果集中删除数据的额外步骤."(查询和扫描性能)这会导致 性能问题和其他问题.

Based on the docs for Scan, I conclude that there is no way to Scan in reverse. However, I would say that you are not using DynamoDB correctly if you need to do that. When designing a schema for a database like DyanmoDB you should plan the schema based on your expected queries to ensure that almost all application queries have a good index. Scans are meant more for sys admin operations or for feeding into MapReduce or analytics. "A Scan operation always scans the entire table, then filters out values to provide the desired result, essentially adding the extra step of removing data from the result set." (Query and Scan Performance) That can lead to performance problems and other issues.

使用 DynamoDB 与使用传统关系数据库有着根本的不同,您需要对使用它的方式进行重大改变.您需要确定 DynamoDB 在存储和性能、可靠性和可用性方面的可用性优势是否值得接受其局限性.

Using DynamoDB is fundamentally different from working with a traditional relational database and requires a big change in the way you think about using it. You need to decide whether DynamoDB's advantages of availability in storage and performance, reliability and availability are worth accepting its limitations.

这篇关于如何在 DynamoDB 中反向扫描索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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