DynamoDB 中的 BatchGetItem 和 Query 有什么区别? [英] What's the difference between BatchGetItem and Query in DynamoDB?

查看:37
本文介绍了DynamoDB 中的 BatchGetItem 和 Query 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在浏览 AWS DynamoDB 文档,但在我的一生中,无法弄清楚 batchGetItem() 和 Query() 之间的核心区别是什么.两者都根据表和索引中的主键检索项目.唯一的区别在于检索到的项目的大小,但这似乎不是突破性的差异.两者都支持条件更新.

I've been going through AWS DynamoDB docs and, for the life of me, cannot figure out what's the core difference between batchGetItem() and Query(). Both retrieve items based on primary keys from tables and indexes. The only difference is in the size of the items retrieved but that doesn't seem like a ground breaking difference. Both also support conditional updates.

在什么情况下我应该使用 batchGetItem 而不是 Query,反之亦然?

In what cases should I use batchGetItem over Query and vice-versa?

推荐答案

简而言之:BatchGetItem 处理表并使用散列键来标识要检索的项目.您最多可以在回复中获得 16MB 或 100 个项目

In a nutshell: BatchGetItem works on tables and uses the hash key to identify the items you want to retrieve. You can get up to 16MB or 100 items in a response

查询适用于表、本地二级索引和全局二级索引.您最多可以在响应中获得 1MB 的数据.最大的区别是查询支持过滤表达式,这意味着您可以请求数据,DDB 会在服务器端为您过滤.

Query works on tables, local secondary indexes and global secondary indexes. You can get at most 1MB of data in a response. The biggest difference is that query support filter expressions, which means that you can request data and DDB will filter it server side for you.

如果你真的想使用这些中的任何一个,你可能可以实现同样的事情,但经验法则是当你需要从 DDB 批量转储东西时你做一个 BatchGet,当你需要缩小范围时你查询记下您要检索的内容(并且您希望 dynamo 为您执行繁重的数据过滤工作).

You can probably achieve the same thing if you want using any of these if you really want to, but rule of the thumb is you do a BatchGet when you need to bulk dump stuff from DDB and you query when you need to narrow down what you want to retrieve (and you want dynamo to do the heavy lifting filtering the data for you).

这篇关于DynamoDB 中的 BatchGetItem 和 Query 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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