[英]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.