We used Custom Table Types to pass a list of integers into our stored procedures.
Then we use them to join other tables in our stored proc queries.
For instance:
CREATE PROCEDURE [dbo].[sp_Name] ( @Ids [dbo].[OurTableType] READONLY ) AS SET Nocount ON SELECT * FROM SOMETABLE INNER JOIN @Ids [OurTableType] ON [OurTableType].Id = SOMETABLE.Id
We have seen very poor performance when using large data sets.
One approach we used to speed things up is dumping the contents into a temporary table and merging instead.
For instance:
CREATE PROCEDURE [dbo].[sp_Name] ( @Ids [dbo].[OurTableType] READONLY ) AS SET Nocount ON CREATE TABLE
This greatly improves performance, but I wanted to get some opinions on this approach and any other consequences that we did not consider. It may also be useful to explain why this improves performance.
NB Sometimes we may need to pass in more than just an integer, so we don’t use a comma-separated list or something like that.
source share