I'm having a poor performance in joins with user defined tables (when more than one rows exists) Reading other posts like Performance of User-Defined Table Types in SQL Server i've tried to fix it but i've not obtained good results. I'll explain my case: I have this table type defined:
CREATE TYPE myType AS TABLE
(
[Id] [int] NOT NULL,
[Value] [varchar](500)
)
and i use it in the following sp:
DECLARE @TableParams myType
INSERT INTO @TableParams (Id, Value)
--Code to fill the table type variable
SELECT ........ from......
--table type variable filled
SELECT @NumberParams =count(1) from @TableParams
SELECT T0.col1 from T0 where (@NumberParams =(
select count(1) from T1
INNER JOIN @TableParams T2
on T1.Id = T2.Id
and T1.Value=T2.Value
where T1.col1= T0.col1
))OPTION(RECOMPILE)
as i've said I've tried all the options (except the option recompile in subselect) mentioned on attached post, but no good news. The option recompile option in the subselect i have not tested it because when i tried to compile the sp, it always returned an error