Question

I am in a situation where I need to do some comparison for some products that are in a shopping cart. The cart can have as many items as the user desires but the average over time is roughly 5-15 items per cart.

My question is one about optimization/overhead. I need to check what department each product is in and determine the shipping charge. The department for each product isn't directly related to the product (i.e. there isn't a department id column in the product definition table) but I can query and get the department id based on the product id.

This is where my question is. Would it be better (less overhead/faster) to pass in a list of id's to a stored procedure and use the list in the stored procedure with something like table valued parameter to query the existing table? Or would it be faster to just query the products 1 at a time (assuming the aver cart size is on the high end of 5-15), get the department id, and then go onto the next item?

I have never used TVP and I am trying to learn from some other questions posted on stack overflow and the msdn site. So before I spend to much time trying to get the results I want I am posing this question.

Was it helpful?

Solution

Generally the TVP should be faster (and easer to make it faster if you need it). The larger the list, the more favorable TVP's should be versus one query per ID.

It's a bit more development work to set things up to use a TVP, so if you'll never have more than a small list (say 3 or less), then it may not be worth it, but otherwise it's definitely a better approach.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top