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

查看:148
本文介绍了如何在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:


一个值,它指定索引的升序(真)或降序(假)
。 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天全站免登陆