为什么 NoSql 数据库比关系数据库扩展性更好?我应该如何选择它们?

2022-01-13 00:00:00 mongodb sql database nosql mysql

我所说的 nosql 数据库是指 mongodb 或 dynamodb我一直在试图找出为什么 NoSql 数据库通常在水平扩展方面比关系数据库更好,以及如何在它们之间进行选择

By nosql databases I mean something like mongodb or dynamodb I've been trying to find why NoSql dbs usually are usually better at horizontal scaling than relational dbs, and how to choose between them

我查看了许多告诉我们SQL 与 NoSQL"的视频和帖子.他们中的大多数人最终都在谈论规范化与非规范化".

I have looked into many videos and posts that tell us the "SQL vs NoSQL". Most of them end up talking about "Normalization vs Denormalization".

以下是一些我仍然感到困惑的问题.

Here are some questions I am still confused about.

1.许多人说关系数据库必须遵循 ACID,因此它们不擅长水平扩展.但是 ACID 是关于事务的,我们总是可以选择不使用任何事务,对吧?我知道没有多少人这样做,但是如果我们对表进行足够的非规范化,会不会像 NoSQL dbs 那样我们几乎不使用任何事务?许多 NoSql 数据库现在也有事务.

1. Many people said that relational dbs have to follow ACID so they are bad at horizontal scaling. But ACID is about transaction, we can always choose not to use any transaction, right? I know not many people do this, but if we denormalized tables enough, would it be like NoSQL dbs where we almost don't use any transaction?. And many NoSql dbs now have transactions too.

2.我知道非规范化可能有利于水平缩放,因为如果数据是分布在许多节点(机器)上,很难进行表连接(或事务).但是像事务一样,我们可以选择不使用任何表连接.

2. I know denormalization is probably good for horizontal scaling, because if data are spreaded across many nodes(machines), it'll be hard to do table joining(or transaction). But like transaction, we can choose not to use any table join.

我唯一能想到的是 NoSQL 是无模式的,添加新字段(列)比 RDB 更容易.

The only thing I can think of is NoSQL are schema-free, it is easier to add new fields(columns) than RDB.

我想问的是
为什么是非规范化 NoSQL db"?比非规范化的关系数据库"更好.?
为什么是规范化 NoSQL db"?比规范化的关系数据库"更糟糕.?
阻止关系数据库非规范化的真正原因是什么?

What I am trying to ask are
why is a "Denormalized NoSQL db" better than a "Denormalized relational db" ?
why is a "Normalized NoSQL db" worse than a "Normalized relational db" ?
what's the real thing that prevents relational database from denormalization?

我看过这篇文章
https://softwareengineering.stackexchange.com/questions/194340/为什么-are-nosql-databases-more-scalable-than-sql
它说
"SQL API 缺少一种机制来描述放宽ACID 要求的查询.这就是为什么 BASE 数据库都是 NoSQL.""
谁能给我一个这样的例子吗?

I've read this post
https://softwareengineering.stackexchange.com/questions/194340/why-are-nosql-databases-more-scalable-than-sql
It says
""The SQL API lacks a mechanism to describe queries where ACID's requirements are relaxed. This is why the BASE databases are all NoSQL.""
Could anyone give me an example of this?

抱歉没有具体说明

我所说的 NoSQL 数据库是指 mongodb 之类的东西

By NoSQL databases I mean something like mongodb

推荐答案

类似 https://neo4j.com/blog/acid-vs-base-consistency-models-explained/ 这样解释 BASE:

A blog like https://neo4j.com/blog/acid-vs-base-consistency-models-explained/ explains BASE this way:

基本可用性

  • 数据库似乎大部分时间都在工作.

软状态

  • 存储不必是写一致的,不同的副本也不必一直相互一致.

最终一致性

  • 存储在稍后的某个时间点表现出一致性(例如,在读取时延迟).

这种程度的模棱两可听起来不太可靠,是吗?他们牺牲可用性和一致性来获得性能和可扩展性.

This level of equivocation doesn't sound very reliable, does it? They trade off availability and consistency to gain performance and scalability.

如果您运行的服务可以容忍不匹配的数据或过时的数据,或者偶尔丢失少量数据也可以.如果这些问题很少发生,但您几乎一直都能获得卓越的性能,那么它非常有吸引力.更重要的是,它的演示效果很好.

This is fine if you're running a service that is tolerant of mismatched data or stale data, or which is okay with some minor amount of data loss once in a while. If those issues are an uncommon occurrence, but you get superior performance nearly all the time, it's very attractive. And more importantly, it demos well.

但如果您必须运行对数据完整性有严格要求的服务,那就不好了.如果即使丢失一条数据记录也会让审计员遇到麻烦,或者如果您无法可靠地读取您刚刚提交的数据,因为该提交需要时间传播到集群的所有节点,这可能会破坏交易.

But if you have to run a service with strict requirements for data integrity, it's no good. If losing even one record of data gets you in trouble with auditors, or if you can't reliably read data you just committed a moment before because that commit takes time to propagate to all nodes of your cluster, it could be a deal-breaker.

因此,选择哪种数据存储取决于您的应用程序的要求.只有您可以判断 BASE 数据存储的宽松可用性和一致性是否足以满足您应用的需求.

So which data store to choose depends on the requirements of your app. Only you can judge if the relaxed availability and consistency of a BASE data store is sufficient for the needs of your app.

相关文章