为什么要使用非关系数据库? [英] Why would I want to use a non-relational database?

查看:185
本文介绍了为什么要使用非关系数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

数据库中最新的热潮似乎围绕着非关系数据库。为什么?这似乎是适得其反。例如,我以一种关系方式(表格的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.

这篇关于为什么要使用非关系数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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