all groups > sql server programming > april 2006 >
You're in the

sql server programming

group:

Re: many small queries vs one large query



Re: many small queries vs one large query Ryan Hunt
4/10/2006 10:39:58 PM
sql server programming:
[quoted text, click to view]

Re: many small queries vs one large query Michael Hotek
4/14/2006 5:17:08 PM
That might be a very active SQL forum, but this one still blows that one
away in terms of volume, users, and answers.

Allan,
Your boss is flat out wrong and completely out to lunch. (But, you probably
shouldn't tell him that.) Every single time you connect, you have to send a
connection packet to SQL Server. SQL Server has to authenticate the login,
allocate memory space, and hand you a connection handle back. You then send
the query across. SQL Server executes the query, packages the results, and
sends them back to you. You then have to send a disconnect, SQL Server has
to tear down all of the memory structures to return the memory to the pool,
and send you an ack back. You then start it all over again. That is an
absolutely horrible waste of time, effort, and resources.

No one needs to explain this to you or point you anywhere. Just use some
basic common sense. Which is faster?

Option 1:
Connect
Issue query
Receieve results
Disconnect

Option 2:
Connect
Issue query
Receieve results
Disconnect
Connect
Issue query
Receieve results
Disconnect
Connect
Issue query
Receieve results
Disconnect
Connect
Issue query
Receieve results
Disconnect
Connect
Issue query
Receieve results
Disconnect
Connect
Issue query
Receieve results
Disconnect
Connect
Issue query
Receieve results
Disconnect
Connect
Issue query
Receieve results
Disconnect
Connect
Issue query
Receieve results
Disconnect
Connect
Issue query
Receieve results
Disconnect
......another 4990 times

If you boss doesn't believe it, simply prove it. Create a dummy application
block with a timer. Connect to SQL Server, yank 5000 rows, and disconnect.
Then change it to return each row of the result set one at a time with a
connect/disconnect sandwiched in between. You can probably hit the button
on the first one while your boss is standing there. When you hit the button
on the second one, would be a good time to have your boss take you out to
lunch for saving them from being killed by the end users. It might be
finished when you get back from lunch.

--
Mike
http://www.solidqualitylearning.com
Disclaimer: This communication is an original work and represents my sole
views on the subject. It does not represent the views of any other person
or entity either by inference or direct reference.


[quoted text, click to view]

AddThis Social Bookmark Button