|
|
|
|
|
by cogman10
512 days ago
|
|
The answer is "it depends". Sum is a good thing to do in the Db because it's low cost to the db and reduces io between the db and app. Sort can be (depending on indexes) a bad thing for a db because that's CPU time that needs to be burned. Conditional logic is also (often) terrible for the db because it can break the optimizer in weird ways and is just as easily performed outside the db. The right action to take is whatever optimizes db resources in the long run. That can sometimes mean shifting to the db, and sometimes it means shifting out of the db. |
|
And if your conditional logic is breaking the optimizer then the solution is usually to write the query more correctly. I can't think of a single instance where I've ever found moving conditional logic out of a query to be meaningfully more performant. But maybe there's a specific example you have in mind?