为什么要使用非关系数据库?

编程入门 行业动态 更新时间:2024-10-28 10:34:30
本文介绍了为什么要使用非关系数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

数据库中最新的热潮似乎围绕着非关系数据库。为什么?这似乎是适得其反。例如,我以一种关系方式(表格的Django + SQL中的示例代码)表达我的数据更有意义:

class Post(models.Model): name = models.CharField() created = models.DateTimeField(auto_now_create = True) 类注释): text = models.TextField() post = models.ForeignKey('Post') created = models.DateTimeField(auto_now_create = True)

SQL:

id int primary key auto_increment, name varchar, created datetime); create table comment(id int primary key auto_increment, text text, post_id int, created datetime, foreign key post_id references post ));

SQL的优点是这些信息可以用方法。当然,整个对象 - 关系映射问题存在,但我把它看作一个特性,而不是一个问题。使用SQL,我可以获取早于昨天的所有不同的评论,整理所有这些,并生成统计信息。对于非关系数据库也可以这样做?

使用MongoDB这样的非关系数据库似乎真的会影响性能,因为你会立即抓取整个对象图,而不是你最少需要的。

有人可以向我解释使用非关系数据库的好处吗?

解决方案

查看 CAP定理

并且 PACELC解释

关系数据库倾向于做出一组权衡,和非关系倾向于做出一组不同的权衡。对于大规模分布式数据集,非关系有时更有意义。

还有一种感觉,其中非关系数据库可以消除很多ORM痛苦,总是有权衡。在某些使用情况下,非关系存储可以更快,因为特定层次结构的所有数据可以更紧密地存储在磁盘上。还要注意,非关系数据库仍然具有查询功能。

最后,它是为您的特定用例做出适当的权衡集。 / p>

The latest craze in databases seems to be centered around non-relational databases. Why? It seems kind of counterproductive. For example, it makes much more sense to me to express my data in a relational way (example code in Django + SQL for tables):

class Post(models.Model): name = models.CharField() created = models.DateTimeField(auto_now_create = True) class Comment(models.Model): text = models.TextField() post = models.ForeignKey('Post') created = models.DateTimeField(auto_now_create = True)

SQL:

create table post (id int primary key auto_increment, name varchar, created datetime); create table comment(id int primary key auto_increment, text text, post_id int, created datetime, foreign key post_id references post(id));

The power of SQL is that this information can be expressed in so many ways. Sure, the whole object-relational-mapping problem exists, but I look at it as a feature and not as a problem. With SQL, I can fetch all distinct comments of a given post which are older than yesterday, collate all of those together, and generate statistics. Can the same be done for non-relational databases?

It also would seem to really impact performance to use a non-relational database like MongoDB because you would immediately grab an entire object graph, rather than what you minimally need.

Can someone explain to me what the benefits are of using a non-relational database?

解决方案

Take a look at the CAP Theorem

And the PACELC interpretation

Relational databases tend to make one set of trade-offs, and non-relational tend to make a different set of trade-offs. For massive distributed datasets, non-relational sometimes makes more sense.

There is also a sense in which non-relational databases can eliminate a lot of the ORM pain, but again there are always tradeoffs. In some use cases, non-relational storage can be faster, because all the data for a particular hierarchy can be stored closer together on the disk. Also note that non-relational databases do still have query capabilities.

In the end, it's about making the appropriate set of trade-offs for your particular use-case.

更多推荐

为什么要使用非关系数据库?

本文发布于:2023-10-24 09:06:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1523527.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:要使   关系   数据库

发布评论

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

>www.elefans.com

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