单独的表格与地图列表-DynamoDB [英] Separate tables vs map lists - DynamoDB

查看:117
本文介绍了单独的表格与地图列表-DynamoDB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要你的帮助.我对数据库很陌生.

I need your help. I am quite new to databases.

我正在尝试在DynamoDB中建立一个表来存储有关电视节目的信息.看起来很简单明了,但是我不确定我在做什么是否正确.

I'm trying to get set up a table in DynamoDB to store info about TV shows. It seems pretty simple and straightforward but I am not sure if what I am doing is correct.

到目前为止,我已经有了这种结构.我试图将有关电视节目的所有内容都放在一张桌子上.季节和情节包含在地图列表中的地图列表中.

So far I have this structure. I am trying to fit everything about the TV shows into one table. Seasons and episodes are contained within a list of maps within a list of maps.

分层太多了吗?在将来某些物品很大的情况下,这会带来问题吗?我应该将其中一些地图列表分隔到另一个表中吗?

Is this too much layering? Would this present a problem in the future where some items are huge? Should I separate some of these lists of maps to another table?

显示表格

推荐答案

理想情况下,不应将可能无界的列表放在DynamoDB中的单行中,因为最终可能会遇到400kb的项目大小限制.同样,如果您要阅读或撰写一个节目的一集,则消耗的容量就好像您正在阅读或撰写节目中的所有集一样.

Ideally, you should not put a potentially unbounded list in a single row in DynamoDB because you could end up running into the item size limit of 400kb. Also, if you were to read or write one episode of one show, you consume capacity as if you are reading or writing all the episodes in a show.

看看邻接列表模式.这是一个不错的选择,因为它可以让您轻松地找到节目中的季节和季节中的情节.您还可以查看此幻灯片平台.在此过程的一部分中,它讨论的是分层数据,而这正是您要处理的数据.

Take a look at the adjacency list pattern. It’s a good choice because it will allow you to easily find the seasons in a show and the episodes in a season. You can also take a look at this slide deck. Part of the way through, it talks about hierarchical data, which is exactly what you’re dealing with.

如果您可以提供有关查询模式的更多信息,那么我可以为您提供有关如何在表中对数据建模的更多指导.

If you can provide more information about your query patterns, I can give you more guidance on how to model your data in the table.

更新(2018-11-26)

根据您的评论,听起来您应该使用复合键来建立分层的1-N关系.

Based on your comments, it sounds like you should use composite keys to establish hierarchical 1-N relationships.

通过使用 DataType:ItemId 的复合排序键(其中ItemId是根据数据类型的不同格式),您将具有很大的灵活性.这种方法将使您轻松获得节目中的季数,获得所有所有季的剧集,获取特定季中的所有剧集,甚至获得第1季,第5季和第2季之间的所有剧集第5集.

By using a composite sort key of DataType:ItemId where ItemId is a different format depending on the data type, you have a lot of flexibility. This approach will allow you to easily get the seasons in the show, get all episodes in all seasons, get all episodes in a particular season, or even get all episodes between season 1, episode 5 and season 2 episode 5.

hash_key  | sort_key        | data
----------|-----------------|----------------------------
SHOW_1234 | SHOW:SHOW_1234  | {name:"Some TV Show", ...
SHOW_1234 | SEASON:SE_01    | {descr:"In this season, the main character...
SHOW_1234 | EPISODE:S01_E01 | {...
SHOW_1234 | EPISODE:S01_E02 | {...

以下是我提到的查询的各种关键条件表达式:

Here are the various key condition expressions for the queries I mentioned:

  • hash_key ="SHOW_1234"和sort_key starts_with("SEASON:") –获取所有季节
  • hash_key ="SHOW_1234"和sort_key starts_with("EPISODE:") –获取所有季节的所有情节
  • hash_key ="SHOW_1234"和sort_key starts_with("EPISODE:S02 _") –获取第2季的所有剧集
  • hash_key ="SHOW_1234"以及介于"EPISODE:S01_E5"和"EPISODE:S02_E5"之间的sort_key –获取第1季第5集和第2季第5集之间的所有情节
  • hash_key = "SHOW_1234" and sort_key begins_with("SEASON:") – gets all seasons
  • hash_key = "SHOW_1234" and sort_key begins_with("EPISODE:") – gets all episodes in all season
  • hash_key = "SHOW_1234" and sort_key begins_with("EPISODE:S02_") – gets all episodes in season 2
  • hash_key = "SHOW_1234" and sort_key between "EPISODE:S01_E5" and "EPISODE:S02_E5" – gets all episodes between season 1, episode 5 and season 2 episode 5

这篇关于单独的表格与地图列表-DynamoDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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