Shuvra
Shuvra

Reputation: 212

SQL VS C# aggregation operations performance

I am writing a Store procedure that has SUM, AVG operation over millions of data with grouping by 3 to 5 column. I am wondering if i Do this in C# that means If i only read the data from database to C# objects and do the calculation (sum, avg ect.) in the object(or datatable). Will this improve the performance?

I like to create faster application.

Thanks in Advance. Shuvra

Upvotes: 0

Views: 2343

Answers (2)

FIre Panda
FIre Panda

Reputation: 6637

It would be much better, performance wise, to do the sum, avg operation in your Store Procedure. Because if you want to perform these operation using C#, you have to fetch million of records and on million of records you will have sum, avg operation, that would definitely hurt performance to a much greater extent whereas if you do sum, avg operations in SP, you only have to fetch the summarize records and thus utilizes less bandwidth and boosts performance.

Upvotes: 5

Anders Abel
Anders Abel

Reputation: 69260

Databases are built to be efficient in sorting, selecting and grouping data. Let it do the work that it is built for. If you do it in C# code you first have to ask the database to deliver all the data and then you have to transfer it to the client. It will be a lot slower than just letting the DB do the calculation.

Upvotes: 11

Related Questions