I have an existing stored proc that selects a set of 25 columns from a table to perform Action A. I am writing another action B which needs just 3 columns from the table. Only one column out of the three I need is in an index. So I do not think there would be any significant difference in the execution time of the query between Action A and Action B (Correct me if I am wrong) if I have another query that just fetches the three开发者_JAVA技巧 columns. But I am concerned about the size of the data packet that gets transmitted over the network if I reuse the same sproc used by Action A. Should I write another stored proc just to retrieve the columns that I need for Action B?
Yes!
Obviously it is impossible to say how much the network issue itself would really matter without knowing the size of the columns involved, the frequency with which the procedure is called and the speed of your network but it is just good practice to not return unneeded columns (or rows) to the client. (Interesting blog post on this issue)
This will also allow your 3 column query to potentially use a narrower covering index in the future to reduce the IO requirements of the query.
Selecting only the columns you need will also allow tools such as the missing index DMVs and DTA to make appropriate recommendations based on your actual workload requirements and may reduce memory requirements for the query as you are passing less data around (particularly if you have any sorts in the plan)
精彩评论