DynamoDB - 删除分区的最有效方法?
DynamoDB - Most efficient way of deleting a partition?
假设我有一个分区键 User:user@email.com
,它有几个排序键,例如 Data
、Sale:001
、Contact:001
.
现在,如果我想删除这个用户怎么办?
我想到了两种使用 API 的方法。
1 - 扫描
首先在 partition-key=User:user@email
处执行 SCAN
,获取结果并使用相应的排序键对每个返回的项目执行批量删除。
2 - 查询
为此,我首先需要将所有排序键更改为具有通用前缀,例如 User|Data
、User|Sale:001
、User|Contact:001
,然后执行查询,其中
partition-key=User:user@email.com and sort_key.begins_with(User)
得到结果后,我会像扫描选项一样进行批量删除。
我不清楚哪个选项是最好的,因为我不确定扫描是否有 "intelligence" 只扫描特定分区内的内容,或者它会扫描 [=] 中的每条记录48=]。因为在 DynamoDB 中,您为 "searched"
的每 kb 项目付费
因为如果它是智能的,那么我认为它的成本与查询选项相同,而无需为我的排序键添加前缀。
Scan() 不支持 partition-key=User:user@email
除了作为过滤表达式。
所以是的,整个 table 都会被阅读。实际上只会返回匹配的记录。
另一方面,Query() 需要 partition-key=user:user@email
作为关键条件表达式。您无需对排序键设计进行任何更改;因为包含排序键的关键条件是 optional。
The partition key equality test is required, and must be specified in
the following format:
partitionKeyName = :partitionkeyval
If you also want to provide a condition for the sort key, it must be
combined using AND with the condition for the sort key. Following is
an example, using the = comparison operator for the sort key:
partitionKeyName = :partitionkeyval AND sortKeyName = :sortkeyval
假设我有一个分区键 User:user@email.com
,它有几个排序键,例如 Data
、Sale:001
、Contact:001
.
现在,如果我想删除这个用户怎么办?
我想到了两种使用 API 的方法。
1 - 扫描
首先在 partition-key=User:user@email
处执行 SCAN
,获取结果并使用相应的排序键对每个返回的项目执行批量删除。
2 - 查询
为此,我首先需要将所有排序键更改为具有通用前缀,例如 User|Data
、User|Sale:001
、User|Contact:001
,然后执行查询,其中
partition-key=User:user@email.com and sort_key.begins_with(User)
得到结果后,我会像扫描选项一样进行批量删除。
我不清楚哪个选项是最好的,因为我不确定扫描是否有 "intelligence" 只扫描特定分区内的内容,或者它会扫描 [=] 中的每条记录48=]。因为在 DynamoDB 中,您为 "searched"
的每 kb 项目付费因为如果它是智能的,那么我认为它的成本与查询选项相同,而无需为我的排序键添加前缀。
Scan() 不支持 partition-key=User:user@email
除了作为过滤表达式。
所以是的,整个 table 都会被阅读。实际上只会返回匹配的记录。
另一方面,Query() 需要 partition-key=user:user@email
作为关键条件表达式。您无需对排序键设计进行任何更改;因为包含排序键的关键条件是 optional。
The partition key equality test is required, and must be specified in the following format:
partitionKeyName = :partitionkeyval
If you also want to provide a condition for the sort key, it must be combined using AND with the condition for the sort key. Following is an example, using the = comparison operator for the sort key:
partitionKeyName = :partitionkeyval AND sortKeyName = :sortkeyval