dynamodb中的scan和query有什么区别?什么时候使用扫描/查询? [英] What is the difference between scan and query in dynamodb? When use scan / query?

查看:719
本文介绍了dynamodb中的scan和query有什么区别?什么时候使用扫描/查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DynamoDb文档中指定的查询操作:

A query operation as specified in DynamoDb documentation:


查询操作仅搜索主键属性值并支持比较运算符的子集

A query operation searches only primary key attribute values and supports a subset of comparison operators on key attribute values to refine the search process.

以及扫描操作:


扫描操作将扫描整个表。您可以指定过滤器,将其应用到结果中,以在完成完整扫描后细化返回给您的值。

A scan operation scans the entire table. You can specify filters to apply to the results to refine the values returned to you, after the complete scan.

哪个最好基于性能和成本方面的考虑。

Which is best based on Performance and Cost Considerations.

推荐答案

在创建Dynamodb表时,请选择主键和本地二级索引(LSI),以便执行查询操作返回查询所需的项目。

When creating a Dynamodb table select Primary Keys and Local Secondary Indexes (LSIs) so that a Query operation returns the items you want.

查询操作仅支持对主键进行相等的运算符评估,但有条件的(=,< ;,< =,>,> = ,之间,开始之间)。

Query operations only support an equal operator evaluation of the Primary Key, but conditional (=, <, <=, >, >=, Between, Begin) on the Sort Key.

扫描操作通常较慢且较昂贵,因为该操作必须遍历表中的每个项目以获取您要的项目。

Scan operations are generally slower and more expensive as the operation has to iterate through each item in your table to get the items you are requesting.

示例:

Table: CustomerId, AccountType, Country, LastPurchase

Primary Key: CustomerId + AccountType

在此示例中,您可以使用Query操作获取:

In this example, you can use a Query operation to get:


  1. 在AccountType上使用条件过滤器的CustomerId

需要使用扫描操作来返回:

A Scan operation would need to be used to return:


  1. 所有具有特定帐户类型的客户

  2. 基于国家/地区的条件过滤器的商品,即来自美国的所有客户

  3. 基于LastPurchase的条件过滤器的商品,即上个月进行过购买的所有客户

为避免对经常使用的操作进行扫描操作而创建本地二级索引(LSI)或全局S

To avoid scan operations on frequently used operations creating a Local Secondary Index (LSI) or Global Secondary Index (GSI).

示例:

Table: CustomerId, AccountType, Country, LastPurchase

Primary Key: CustomerId + AccountType
GSI: AccountType + CustomerId
LSI: CustomerId + LastPurchase

在此示例中,查询操作可以使您获得:

In this example a Query operation can allow you to get:


  1. 在AccountType上具有条件过滤器的CustomerId

  2. [GSI]在特定AccountType上在CustomerIds中的条件过滤器

  3. [LSI] LastPurchase上的条件过滤器

这篇关于dynamodb中的scan和query有什么区别?什么时候使用扫描/查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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