Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Database design Dynamodb工作台设计_Database Design_Amazon Dynamodb - Fatal编程技术网

Database design Dynamodb工作台设计

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

我需要一个表,它应该有以下属性: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 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(字符串)-排序键

定义以下GSI:

  • CommentId(字符串)-GSI分区键
以及下列政府物料供应处:

  • CommentTopicAndCommentCountry(字符串,GSI分区键)-组合字段,将两个值组合在一起,类似于“123_Germany”

  • CommentId(字符串,GSI排序键)与以前完全相同的字段

现在,请回答您的问题:

获取属于某个用户ID的所有注释

这非常简单,只需使用分区键/排序键并只指定一个分区键

获取带有commentID=“commentID”的注释

使用第一个GSI并提供注释id

获取topic=“commentTopic”和country=“commentCountry”所在的所有用户的评论

使用第二个GSI并为“注释id和国家/地区”提供一个值作为单个分区键值

现在的限制是,对于单个分区键,最多只能有10GB的数据,因此,如果最终用户编写的消息可能超过10GB,或者单个主题中的消息可能超过10GB,那么您可能需要使用多个表,而不是单个表

您可以拥有2017年的评论、2016年的评论等,以存储不同年份的评论。如果你想的话,你可以做得更精细一些

这样做的另一个好处是,您可以为不同的表设置不同的RCU/WCU值。我可以想象,新的注释会被更频繁地阅读,因此您可以为最新的表设置较高的RCU/WCI,但是旧的注释根本不会被编写,并且可能会被更少地阅读。在这种情况下,可以在那里设置较少的RCU

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