全球二级指数vs正常化 [英] Global secondary index vs dernomalization

查看:95
本文介绍了全球二级指数vs正常化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的消息表:

I have a message table like this:

From  |  To   |         timestamp       |      Message
------|-------|-------------------------|------------------
john  | Mark  | 2014-04-28T07:53:29.000Z|"Some message1"
john  | Mark  | 2014-04-28T08:53:29.000Z|"Some message2"
john  | Mary  | 2014-04-28T09:53:29.000Z|"Some message3"
mary  | Kevin | 2014-04-28T07:53:29.000Z|"Some message4"
jane  | John  | 2014-04-28T07:53:29.000Z|"Some message5"

我需要选择所有按日期排序的邮件 FROM [用户](最新的优先),这将导致分页(一次10条消息)。

I need to be able to select all the messages FROM [user] ordered by date (newest first) which will result in pagination (10 messages at a time).

我还需要能够选择再次按日期(最新到先)排序的 TO [用户]发送的所有消息,这将导致分页(一次10条消息)。

I also need to be able to select all the messages sent TO [user] again ordered by date (newest first) which will result in pagination (10 messages at a time).

我首先想到的是创建两个表:

My first thought would be to create two tables:

FROM表(FROM = PK,Timestamp =范围)和 TO表(TO = PK,时间戳=范围)。

FROM table (FROM = PK, Timestamp = Range) and a TO table (TO= PK, Timestamp = Range).

创建消息时,需要将其发送到FROM和TO表(数据重复)。然后,如果我需要从用户那里获取消息,则可以查询FROM表,而当我需要将消息发送给用户时可以查询TO表。

When a message is created it needs to be sent to both the FROM and TO table (duplication of data). I can then query the FROM table if I need to get messages from a user and can query the TO table when I need to get messages sent to a user.

我的第二个想法是使用全局二级索引。据我了解,全局二级索引没有限制。这样,我将使该表具有PK = FROM和RANGE = Timestamp。然后,我将创建一个全局二级索引PK = TO和RANGE = Timestamp。我唯一可以做到的是,我将没有重复的数据。如果我要使用全局二级索引,而不是就性能,限制或其他方面对表进行规范化,是否有任何缺点或注意?

My second idea would be to use global secondary indexes. As I know there is no limits on global secondary indexes. With this I would then have the table have a PK = FROM and RANGE = Timestamp. I then would create a global secondary index PK = TO and RANGE = Timestamp. The only upside I can to this is that I will not have duplicate data. Is there any downside or "watch outs" if I were to use global secondary indexes opposed to normalizing the tables in terms of performance, limits, or anything else?

推荐答案

对于您的用例来说,全局二级索引是很自然的选择。在节省重复数据的时间时,成本将保持不变。

For your use case global secondary index are quite natural choice. Costs will remain the same while you save your time on duplicating data.

简短地说-不,没有特定的性能或限制问题。全局二级索引的行为几乎就像它们是单独的表一样,例如,它们具有自己的读/写吞吐量。

Shortly - no, there are no specific performance or limits issues. Global secondary indexes behave pretty much as if they were separate tables, for example they have their own read/write throughput.

请查看此文档以获取详细信息:
http://docs.aws.amazon.com/ amazondynamodb / latest / developerguide / GSI.html#GSI.Writes

Check out this doc for detailed info: http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GSI.html#GSI.Writes

这篇关于全球二级指数vs正常化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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