Sql-server – Is it much more expensive to use procedures that get lists and deriving a count in the application vs. a separate stored procedure for the count

performancesql-server-2008

I would like to know if returning a count is much more expensive than returning a dataset in regard to processing performance? I assume there is a bandwidth increase in delivery to the application logic.

I am basically trying to determine if it is more worth my time to create separate procedures to get counts or just utilize the procedures returning datasets and count how many rows are in the dataset in the application logic.

Best Answer

Not 100% sure I understand your question but - if you are already selecting the data, will also selecting a count be that much more expensive? No, I don't think you'd have an issue doing that. Selecting just a count should incur the same cost as far as the scans/seeks and joins/filtering/aggregating you had to do in your query but also show some time saved in processing/formatting and sending the actual rows as well. If you your select takes 10ms, I'd expect the count to also take 10 or less ms.

Alternatively you can get the rowcount returned by operations as well and return that without even incurring the additional 10 ms.

This SO question deals with the same basic question I think you are driving at and gives a few different answers on technique.