在什么情况下,你在DynamoDB使用简单哈希键? [英] In what situation do you use Simple Hash Keys on DynamoDB?

查看:279
本文介绍了在什么情况下,你在DynamoDB使用简单哈希键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简单哈希键似乎太简单写了一篇文章,而关于组合散/量程按键多写,因为组合散/量程按键是许多复杂的情况下很有用。但我相信,在常见的应用,许多表的设计应与简单的哈希键。在什么情况下你用简单的哈希键?

Simple Hash Keys seem to be too simple to write an article, while many write about Composite Hash/Range Keys, because Composite Hash/Range Keys are useful for many complex situations. But I believe that in common applications, many of tables should be designed with Simple Hash Keys. In what situation do you use Simple Hash Keys?

例如,当你设计层次模型像下面,你怎么设计为每个表的主键? (所有的表比其他租户都tenant_id作为一个字段。)

For example, when you design hierarchical models like following, how do you design primary keys for each table? (All tables other than Tenant have tenant_id as a field.)

  • 租户
  • 用户
  • 团队
  • 项目
  • 工作
  • 团队成员

只有团队成员是由组合散/ RANGE键设计。其他人则用简单的哈希键设计。

Only "Team Member" is designed by Composite Hash/Range Key. Others are designed by Simple Hash Key.

  • 租户是通过简单的哈希键设计。
  • 用户,团队和项目的主键是复合(tenant_id,sub_id)。
  • 任务的主键是复合({tenant_id} _ {project_range_key},sub_id)。
  • 在团队成员的主键是复合({tenant_id} _ {team_range_key},{tenant_id} _ {user_range_key})。

其中sub_id可以是一个序列号,created_at,否则

where sub_id can be a sequential number, created_at, or else.

在我张贴了这个问题,我更多地了解了DynamoDB和它的历史,我承认我的关注太多说不清楚了。

After I posted this question, I learned more about DynamoDB and its history, and I recognize my concern much clearly now.

在GSI由亚马逊发布了,我们必须以对tenant_id查询设计表格,如理念2。但是,现在我们可以使用GSI,所以我们可以设计表(例如团队,项目或任务)中的简单的哈希键和GSI的组合。是对的吗??

Before GSI was released by Amazon, we had to design tables like "Idea 2" in order to query against "tenant_id". But now we can use GSI, so we can design tables (e.g. Team, Project or Task) using the combination of "Simple Hash Key and GSI". Is that right??

推荐答案

您使用单一哈希键表来描述一个项目。对于好例子,一个用户有很多信息,如姓名,年龄等,您可以创建一个用户表USER_ID为hashkey并作为属性的所有其他信息。

You use single hash key table to describe an item. For examle, a user have many info like name, age, etc. You can create a user table with user_id as hashkey and all other info as attributes.

您使用哈希范围架构来形容的关系。例如,一个组可以有多个用户。所以,你可以创建一个团队的成员的关系表与团队-ID为hashkey和用户ID的范围键。

You use hash-range schema to describe a relationship. For example, one team can have multiple users. So you can create a Team-Member-Relationship table with team-id as hashkey and user-id as range key.

在换句话说,绘制顶点是(用户,团队,项目)和边缘是它们之间的关系(1对1,1对多,多到许多等)的关系图。然后使用Hashkey架构边缘的顶点和Hash-范围模式。

In other words, draw a relationship diagram with vertex being (user, team, project) and edge being their relationship (1-to-1, 1-to-many, many-to-many, etc). Then use Hashkey schema for vertex and Hash-Range schema for edge.

谢谢!

厄尔本

这篇关于在什么情况下,你在DynamoDB使用简单哈希键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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