Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

One big call vs. multiple smaller TSQL calls

Tags:

tsql

I have a ADO.NET/TSQL performance question. We have two options in our application:

1) One big database call with multiple result sets, then in code step through each result set and populate my objects. This results in one round trip to the database.

2) Multiple small database calls.

There is much more code reuse with Option 2 which is an advantage of that option. But I would like to get some input on what the performance cost is. Are two small round trips twice as slow as one big round trip to the database, or is it just a small, say 10% performance loss? We are using C# 3.5 and Sql Server 2008 with stored procedures and ADO.NET.

like image 291
BrokeMyLegBiking Avatar asked Mar 23 '10 15:03

BrokeMyLegBiking


1 Answers

I would think it in part would depend on when you need the data. For instance if you return ten datasets in one large process, and see all ten on the screen at once, then go for it. But if you return ten datasets and the user may only click through the pages to see three of them then sending the others was a waste of server and network resources. If you return ten datasets but the user really needs to see sets seven and eight only after making changes to sets 5 and 6, then the user would see the wrong info if you returned it too soon.

If you use separate stored procs for each data set called in one master stored proc, there is no reason at all why you can't reuse the code elsewhere, so code reuse is not really an issue in my mind.

like image 162
HLGEM Avatar answered Sep 21 '22 10:09

HLGEM