Database design Dynamodb工作台设计
我需要一个表,它应该有以下属性:userId,commentId,commentTopic,commentCountry。我希望避免使用辅助全局索引。什么样的设计才是最好的,可以让我进行以下操作:Database design Dynamodb工作台设计,database-design,amazon-dynamodb,Database Design,Amazon Dynamodb,我需要一个表,它应该有以下属性:userId,commentId,commentTopic,commentCountry。我希望避免使用辅助全局索引。什么样的设计才是最好的,可以让我进行以下操作: 1) Get all comments belonging to a userId. 2) Get a comment with commentID = "commentID" 3) Get comments of all users where topic = "commentTopic" and
1) Get all comments belonging to a userId.
2) Get a comment with commentID = "commentID"
3) Get comments of all users where topic = "commentTopic" and country = "commentCountry"
我想:
1) userId#commentId as partitionKey which will uniformly distribute the load and allow me to perform operation 1 and 2 from above list.
2) commentCountry#commentTopic as RangeKey which will allow me to perform operation 3 efficiently.
这种方法有什么缺点吗。这张桌子的设计效率高吗?将多个键连接在一起的缺点是什么 这里有一个你可以使用的想法。您可以使用以下属性定义一个表注释:
- 用户ID(字符串)-分区键
- CommentId(字符串)-排序键
- CommentId(字符串)-GSI分区键
- CommentTopicAndCommentCountry(字符串,GSI分区键)-组合字段,将两个值组合在一起,类似于“123_Germany”
- CommentId(字符串,GSI排序键)与以前完全相同的字段
PK = USER#userid
SK = COMMENT#commentId(GSIPK)
GSISK = commentTopic#country
从用户处获取所有评论
PK = USER#userid AND SK START_WITH COMMENT#
通过注释id获取注释可以针对GSI
GSIPK = COMMENT#commentId
获取topic=“commentTopic”和country=“commentCountry”所在的所有用户的评论
当您编写“userId#commentId”时,是否意味着它是一个字符串类型的单个属性,包含两个共分类值?
GSIPK START_WITH COMMENT# AND GSISK = commentTopic#country