简体   繁体   English

SQL(例如 mysql、postgresql)与 java8 流性能和更快?

[英]SQL(e.g. mysql, postgresql) where vs java8 stream performance and faster?

eg `例如`

 where like '%str%' vs stream().filter(i -> i.contains(str))
    group by column a vs stream().groupingby(column_a)
    group by column_a, column_b vs stream().groupingby(column_a, groupingby(column_b))
    count vs stream().count
    sum vs stream().sum
    order by vs stream().sort

... ` ...`

I'd like to know which is faster and performance is better when it is performed in same spec server or different, thinks.我想知道在相同规格的服务器或不同的服务器中执行时哪个更快,性能更好,我想。

Those are different usecases.这些是不同的用例。 Database were designed to work with persisted data, streams traverse given data structures.数据库旨在处理持久化数据,流遍历给定的数据结构。 So to use streams, you would need to read the data somehow first, that is where you use the database with indexes that helps especially with %like% .因此,要使用流,您需要先以某种方式读取数据,这就是您将数据库与索引一起使用的地方,这对%like%尤其有用。

So should the question be whether it is faster to do sum, group by, count, order by in database as part of the query or fetch the data from database and do those operations with java, then you hardly find a case where you doing it by streams would be preferable.因此,问题应该是在数据库中作为查询的一部分进行 sum、group by、count、order by 还是从数据库中获取数据并使用 java 执行这些操作更快,那么您几乎找不到这样做的情况通过流将是可取的。

The database is made to be fast, streams are made to be sexy to work with.数据库设计得很快,流设计得非常好用。 You can find stream performance related questions ( here , here , and you can find others) that shows that the streams are really slow.您可以找到与流性能相关的问题( 此处此处,您可以找到其他问题),这些问题表明流确实很慢。 The streams can work in parallel to become faster, but the the database do that as well.流可以并行工作以变得更快,但数据库也可以这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 对Java8 Stream性能感到困惑 - Puzzled with Java8 Stream performance Java8整数流与IntStream - Java8 Integer Stream Vs IntStream 如何从 Java 的右侧减少有限的 stream(例如 ArrayList)? - How to reduce a limited stream (e.g. an ArrayList) from right in Java? Java8 Lambda性能与公共功能 - Java8 Lambda performance vs public functions 以非完全编译语言(例如Java)存储在堆还是堆栈中的变量? - Variables stored on heap vs. stack in a non-fully compiled language (e.g. Java)? 如何在 Java 中阅读完整的堆栈跟踪,例如“……还有 23 个” - How to read the full stacktrace in Java where it says e.g. “… 23 more” 不同的数据库系统实现(例如MySQL和Microsoft SQL Server)是否会对“ DataSource”和“ DriverManager”产生不同的影响? - Does different database system implementations (e.g. MySQL, and Microsoft SQL Server) affect `DataSource` and `DriverManager` differently? Java8中的流切割 - Stream cutting in java8 Java ASM操作码:“H_”前缀助记符(例如Opcodes.H_GETFIELD与Opcodes.GETFIELD) - Java ASM Opcodes: “H_” prefixed mnemonics (e.g. Opcodes.H_GETFIELD vs. Opcodes.GETFIELD) Java8 Optional vs Stream中的嵌套空检查 - Nested null checks in Java8 Optional vs Stream
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM