Mat is right (see comments): there is no general answer to that. It depends on the structure of your data, on the queries you want to run and on your database system.
Nevertheless I would say, in most traditional cases it is better to join, filter, group, cumulate and sort your data directly in the DB - just because your DB is built to perform exactly this kind of tasks. If your data structure and indexes are built up right, it will be hard to write code beating the database in terms of performance on this actions.
Indeed, there are complex queries where it is better to split it up and do some work in your code. But unless you have more than 10 tables involved or big sub queries, you should not think about this to much.
发布评论
评论(1)
马特是对的(见评论):对此没有通用的答案。这取决于数据的结构、要运行的查询以及数据库系统。
尽管如此,我想说,在大多数传统情况下,最好直接在数据库中连接、过滤、分组、累积和排序数据 - 因为您的数据库就是为了执行此类任务而构建的。如果您的数据结构和索引构建正确,则很难编写在此操作的性能方面击败数据库的代码。
事实上,对于复杂的查询,最好将其拆分并在代码中做一些工作。但除非您涉及超过 10 个表或大型子查询,否则您不应该对此考虑太多。
Mat is right (see comments): there is no general answer to that. It depends on the structure of your data, on the queries you want to run and on your database system.
Nevertheless I would say, in most traditional cases it is better to join, filter, group, cumulate and sort your data directly in the DB - just because your DB is built to perform exactly this kind of tasks. If your data structure and indexes are built up right, it will be hard to write code beating the database in terms of performance on this actions.
Indeed, there are complex queries where it is better to split it up and do some work in your code. But unless you have more than 10 tables involved or big sub queries, you should not think about this to much.