简体   繁体   English

使用查询(python boto3)从 Dynamo DB 表中获取所有记录

[英]Fetch all the records from Dynamo DB table using Query (python boto3)

I have a table in Dynamo Db with 2 million records.我在 Dynamo Db 中有一张表,其中包含 200 万条记录。 The table has date ( yyyy-mm-dd ) as partition key and account I'd as sort key.该表将日期 ( yyyy-mm-dd ) 作为分区键,将帐户 I 作为排序键。 Currently, we are using boto3.client.dynamodb.query to fetch the data based on KeyConditionExpression where X is date.目前,我们正在使用boto3.client.dynamodb.query来获取基于KeyConditionExpression的数据,其中X是日期。 I want to query the records based on just year?我想根据年份查询记录? What should KeyConditionExpression and Expression Attribute Values be? KeyConditionExpressionExpression Attribute Values应该是什么?

Sample row in Dynamo Db: Dynamo Db 中的示例行:

{"date": {"s" : "2022-04-29"},"account_id": {"s" :"6208378688923445"}}

Here date is partition key and account_id is sort key.这里date是分区键, account_id是排序键。 I want to query all the records with year 2022.我想查询2022年的所有记录。

A query can only operate on a single partition key.查询只能对单个分区键进行操作。 If you want to run this query, you need to add a GSI with the year as the partition key.如果要运行此查询,则需要添加一个以年份作为分区键的 GSI。 This has additional write and storage costs.这有额外的写入和存储成本。 If you don't need to run this query very often, it may be cheaper to just scan the table and filter in the application layer.如果你不需要经常运行这个查询,那么在应用层只扫描表和过滤可能会更便宜。 If you have 2 million records and each record is 500 bytes, the cost of a scan is less than $0.02如果您有 200 万条记录并且每条记录为 500 字节,则扫描成本低于 0.02 美元

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM