从MySQL迁移做DynamoDB(Migrating from MySQL do DynamoDB)

系统教程 行业动态 更新时间:2024-06-14 16:57:18
从MySQL迁移做DynamoDB(Migrating from MySQL do DynamoDB)

我打算将我们网站的一些功能转移到DynamoDB中。 每个用户都有一个留言板,其他用户可以向他们发送消息。

我们的mysql表如下所示:ID | AUTHORID | 消息| USERID | TIMESTAMP


在这种情况下,最好的分区键和排序键是什么? 我还没理解这个概念。

在mysql上,主键是ID,并且USERID上有索引,因此我们可以获取给定用户的所有消息,并按ID排序。

谢谢。 最好的祝福

I'm planning on moving a few features of our website into DynamoDB. Each user have a messages board, where other users can send messages to them.

Our mysql table looks like this: ID | AUTHORID | MESSAGE | USERID | TIMESTAMP


What would be the best Partition key and sort key in this case? I didn't understand this concept yet.

On mysql the primary key is ID, and there is an index on USERID, so we can fetch all messages of a given user, and order by ID.

Thanks. Best Regards

最满意答案

根据每个用户拥有的消息数量(即,每个用户的消息是否相对较少),您可以选择UserID作为散列(或分区)密钥,并将ID(或甚至时间戳)选为范围键。 主要要求是用户ID和ID或用户ID和时间戳的组合是唯一的,另一个要求是每个散列键内的元素分布是统一的(即所有用户应该具有大约相同数量的消息)

只要您不需要在不知道相关用户的情况下对特定消息进行查询,这将很有效。 这可以通过始终跟踪用户上下文在应用程序的逻辑中进行缓解,或者您可以将ID修改为由用户ID和数值组成的复合值:因此消息ID将如下所示:“123 ,34“其中”123“是用户ID,”34“是消息ID。

另一种可能的选择是使用消息ID作为散列密钥,并使用用户ID上的分区键创建全局二级索引(GSI) 。

我建议您阅读本文档 , 该文档提供了使用表的指南,特别是有关使用分区的指南 。

Depending on how many messages you'll have per user (ie. if there will be relatively few messages per user), you may select the UserID to be the hash (or partition) key and the ID (or even Timestamp) to be the range key. The primary requirement is that the combination of User ID and ID or User ID and Timestamp be unique, and the other requirement is that the distribution of elements within each hash key be uniform (ie. all user should have about the same number of messages)

This will work well as long as you don't need to make queries against a specific message, without knowing it's associated user. This can be mitigated in your application's logic by always keeping track of the user context, or you can modify the ID to be a composite value that consists of the user id and the numeric value: so a message id would look like this: "123,34" where "123" is the user id and "34" is the message id.

Another possible option is to use the message ID as the hash key and create a Global Secondary Index (GSI) with a partition key on User ID.

I recommend that you read this document that gives guidelines for working with tables and specifically about working with partitions.

更多推荐

本文发布于:2023-04-12 20:59:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/aeec037bdfad134b438860a5bb30a11a.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:MySQL   DynamoDB   Migrating

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!