SQL 与 noSQL(速度)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13397979/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 12:08:02  来源:igfitidea点击:

SQL versus noSQL (speed)

sqlnosql

提问by janko-m

When people are comparing SQL and noSQL, and concluding the upsides and downsides of each one, what I never hear anyone talking about is the speed.

当人们比较 SQL 和 noSQL 并总结每个人的优缺点时,我从未听过任何人谈论速度。

Isn't performing SQL queries generally fasterthan performing noSQL queries?

执行 SQL 查询通常不会比执行 noSQL 查询更快吗?

I mean, for me this would be a really obvious conclusion, because you should always be able to find something faster if you knowthe structure of your database than if you don't.

我的意思是,对我来说,这将是一个非常明显的结论,因为如果您知道数据库的结构,您应该总是能够比不知道时更快地找到一些东西。

But people never seem to mention this, so I want to know if my conclusion is right or wrong.

但是人们似乎从来没有提到过这一点,所以我想知道我的结论是对还是错。

采纳答案by Carsten

The definition of noSQL systems is a very broad one -- a database that doesn't use SQL / is not a RDBMS. Therefore, the answer to your question is, in short: "it depends".

noSQL 系统的定义非常广泛——不使用 SQL 的数据库不是 RDBMS。因此,简而言之,您的问题的答案是:“视情况而定”。

Some noSQL systems are basically just persistent key/value storages (like Project Voldemort). If your queries are of the type "look up the value for a given key", such a system will (or at least should be) faster that an RDBMS, because it only needs to have a much smaller feature set.

一些 noSQL 系统基本上只是持久的键/值存储(如Project Voldemort)。如果您的查询属于“查找给定键的值”类型,那么这样的系统将(或至少应该)比 RDBMS 更快,因为它只需要具有更小的功能集。

Another popular type of noSQL system is the document database (like CouchDB). These databases have no predefined data structure. Their speed advantage relies heavily on denormalization and creating a data layout that is tailored to the queries that you will run on it. For example, for a blog, you could save a blog post in a document together with its comments. This reduces the need for joins and lookups, making your queries faster, but it also could reduce your flexibility regarding queries.

另一种流行的 noSQL 系统是文档数据库(如CouchDB)。这些数据库没有预定义的数据结构。它们的速度优势在很大程度上依赖于非规范化和创建适合您将在其上运行的查询的数据布局。例如,对于博客,您可以将博客文章及其评论保存在文档中。这减少了连接和查找的需要,使您的查询更快,但它也可能降低您在查询方面的灵活性。

回答by RichardTheKiwi

People who tend to use noSQL use it specifically because it fits their use cases. Being divorced from normal RDBMS table relationships and constraints, as well as ACID-ity of data, it's very easy to make it run a lot faster.

倾向于使用 noSQL 的人专门使用它,因为它适合他们的用例。脱离了正常的 RDBMS 表关系和约束,以及数据的 ACID-ity,很容易让它运行得更快。

Consider Twitter, which uses NoSQL because a user only does very limited things on site, or one exactly - tweet. And concurrency can be considered non-existent since (1) nobody else can modify your tweet and (2) you won't normally be simultaneously tweeting from multiple devices.

考虑使用 NoSQL 的 Twitter,因为用户在网站上只做非常有限的事情,或者确切地说是一条推文。并发性可以被认为是不存在的,因为 (1) 没有其他人可以修改您的推文,并且 (2) 您通常不会同时从多个设备发送推文。

回答by Cross

As Einstein would say, speed is relative.

正如爱因斯坦所说,速度是相对的。

If you need to store a master/detail simple application (like a shopping cart), you would need to do several Insert statements in your SQL application, also you will get a Data set of information when you do a query to get the purchase, if you're using NoSQL, and you're using it well, then you would have all the data for a single order in one simple "record" (document if you use the terms of NoSQL databases like djondb).

如果您需要存储主/明细简单应用程序(如购物车),则需要在 SQL 应用程序中执行多个 Insert 语句,并且在执行查询以获取购买时,您将获得一组信息数据,如果您正在使用 NoSQL,并且您使用得很好,那么您将在一个简单的“记录”中包含单个订单的所有数据(如果您使用 NoSQL 数据库的术语,如 djondb,则记录)。

So, I really think that the performance of an application can be measured by the number of things it need to do to achieve a single requirement, if you need to do several Inserts to store an order and you only need one simple Insert in a database like djondb then the performance will be 10x faster in the NoSQL world, just because you're using 10 times less calls to the database layer, that's it.

所以,我真的认为一个应用程序的性能可以通过它实现单个需求需要做的事情的数量来衡量,如果你需要做几个 Inserts 来存储一个订单,而你只需要一个简单的 Insert 到数据库中像 djondb 那么在 NoSQL 世界中的性能将提高 10 倍,仅仅因为您对数据库层的调用减少了 10 倍,仅此而已。

To illustrate my point let me link an example I wrote sometime ago about the differences between NoSQL and SQL data models approach: http://djondb.com/blog/?p=4, I know it's a self reference, but basically I wrote it to address this question which I found it's the most challenging question a RDBMS guy could have and it's always a good way to explain why NoSQL is so different from SQL world, and why it will achieve better performance anytime, not because we use "nasa" technology, it's because NoSQL will let the developer do less... and get more, and less code = greater performance.

为了说明我的观点,让我链接一个我之前写的关于 NoSQL 和 SQL 数据模型方法之间差异的示例:http: //djondb.com/blog/?p=4,我知道这是一个自我参考,但基本上我写了它解决了这个问题,我发现它是 RDBMS 人员可能遇到的最具挑战性的问题,它总是一个很好的方式来解释为什么 NoSQL 与 SQL 世界如此不同,以及为什么它可以随时获得更好的性能,而不是因为我们使用“nasa “技术,这是因为 NoSQL 将让开发人员做更少的事情……并获得更多,更少的代码 = 更高的性能。

回答by Diego

The answer is: it depends. Generally speaking, the objective of NoSQL DATABASES (no "queries") is scalability. RDBMS usually have some hard limits at some point (I'm talking about millons and millons of rows) where you could not scale any more by traditional means (Replication, clustering, partitioning), and you need something more because your needs keep growing. Or even if you manage to scale, the overall setup is quite complicated. Or you can scale reads, but not writes.

答案是:视情况而定。一般来说,NoSQL DATABASES(无“查询”)的目标是可扩展性。RDBMS 通常在某些时候(我说的是数百万行)有一些硬性限制,您无法通过传统方式(复制、集群、分区)进行扩展,并且您需要更多东西,因为您的需求不断增长。或者即使您设法扩展,整体设置也非常复杂。或者您可以扩展读取,但不能扩展写入。

And the queries depends on the particular implementation of your server, the type of query you are doing, the columns in the table, etc... remember that queries are just one part of the RDBMS.

查询取决于您的服务器的特定实现、您正在执行的查询类型、表中的列等...请记住,查询只是 RDBMS 的一部分。

回答by vivek thakar

query time of relational database like SQL for 1000 person data is 2000 ms and graph database like neo4j is 2ms .if you crate more node 1000000 speed stable 2 ms

1000 个人数据的 SQL 等关系数据库的查询时间为 2000 毫秒,neo4j 等图形数据库的查询时间为 2 毫秒。如果您创建更多节点 1000000 速度稳定 2 毫秒