如何查询DynamoDB? [英] How do you query DynamoDB?

查看:453
本文介绍了如何查询DynamoDB?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在看亚马逊的DynamoDB,因为它看起来像是消除了维护和扩展数据库服务器的麻烦。我目前使用MySQL,并且维护和扩展数据库是一个完整的头痛。

I'm looking at Amazon's DynamoDB as it looks like it takes away all of the hassle of maintaining and scaling your database server. I'm currently using MySQL, and maintaining and scaling the database is a complete headache.

我经历了文档,我很难尝试

I've gone through the documentation and I'm having a hard time trying to wrap my head around how you would structure your data so it could be easily retrieved.

我完全不熟悉NoSQL和非关系数据库,所以任何帮助真的是真的赞赏(和需要)。

I'm totally new to NoSQL and non-relational databases, so any help is really appreciated (and needed).

从Dynamo文档看起来你只能查询主哈希键上的表,主范围键有限数比较运算符。

From the Dynamo documentation it sounds like you can only query a table on the primary hash key, and the primary range key with a limited number of comparison operators.

或者,您可以执行全表扫描并对其应用过滤器。捕获的是它将只扫描1Mb一次,所以你可能要重复扫描,以找到X个结果。

Or you can run a full table scan and apply a filter to it. The catch is that it will only scan 1Mb at a time, so you'd likely have to repeat your scan to find X number of results.

我意识到这些限制allow他们提供可预测的性能,但它似乎使它真的很难得到你的数据。并且执行全表扫描似乎似乎是真的效率低下,并且随着时间的推移只会随着表格的增长而变得更低效。

I realize these limitations allow them to provide predictable performance, but it seems like it makes it really difficult to get your data out. And performing full table scans seems like it would be really inefficient, and would only become less efficient over time as your table grows.

对于实例,说我有一个Flickr克隆。我的图片表格可能类似:

For Instance, say I have a Flickr clone. My Images table might look something like:


  • 图片ID(数字,主要哈希键)


  • 用户ID(字符串)

  • 标签(字符串集)


  • Image ID (Number, Primary Hash Key)
  • Date Added (Number, Primary Range Key)
  • User ID (String)
  • Tags (String Set)
  • etc

因此使用查询我将能够列出过去7天的所有图片,并将其限制为X个结果很容易。

So using query I would be able to list all images from the last 7 days and limit it to X number of results pretty easily.

但是如果我想列出来自特定用户的所有图像,我需要做一个全表扫描和用户名过滤。同样会去标签。

But if I wanted to list all images from a particular user I would need to do a full table scan and filter by username. Same would go for tags.

因为你一次只能扫描1Mb,你可能需要做多次扫描以找到X个图像。我也没有看到一个方法容易停止在X数量的图像。如果您尝试抓取30张图片,您的第一次扫描可能会找到5张,第二张可能会找到40.

And because you can only scan 1Mb at a time you may need to do multiple scans to find X number of images. I also don't see a way to easily stop at X number of images. If you're trying to grab 30 images, your first scan might find 5, and your second may find 40.

我有这个权利吗?它基本上是一个权衡?您获得真正快速可预测的数据库性能,几乎不需要维护。但是,权衡是你需要建立更多的逻辑来处理结果?

Do I have this right? Is it basically a trade-off? You get really fast predictable database performance that is virtually maintenance free. But the trade-off is that you need to build way more logic to deal with the results?

还是我完全不在这里?我对这一切都很陌生,所以如果我错了,请纠正我。我在这里学习。

Or am I totally off base here? I'm totally new to all of this, so please correct me if I'm wrong. I'm here to learn.

推荐答案

是的,你对性能和查询灵活性之间的权衡是正确的。

Yes, you are correct about the trade-off between performance and query flexibility.

但是有一些技巧来减少疼痛 - 次级索引/反规范化可能是最重要的。

But there are a few tricks to reduce the pain - secondary indexes/denormalising probably being the most important.

例如,您将有另一个表键入用户ID,列出他们的所有图像。添加图片时,您需要更新此表格,并向图片ID键入的表格添加一行。

You would have another table keyed on user ID, listing all their images, for example. When you add an image, you update this table as well as adding a row to the table keyed on image ID.

您必须决定需要什么查询,然后设计它们周围的数据模型。

You have to decide what queries you need, then design the data model around them.

这篇关于如何查询DynamoDB?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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