Table Valued Function Killing My Query Performance

后端 未结 5 1272
盖世英雄少女心
盖世英雄少女心 2020-12-04 19:54

I was having a horrible time today trying to get a query to perform the way I would expect. I had to make a slight change to a table valued function that lives in the query

5条回答
  •  感动是毒
    2020-12-04 20:17

    This is because a multi-Statement Table valued UDF cannot be processed inline with the rest of the SQL statememnt it is used in, and therefore cannot be part of the statement cache plan.. That means that it must be compiled separately from the rest of the SQL it is used in, over and over, for every row in the final resultset generated by the query.

    An Inline Table valued UDF, otoh, is processed and compiled along with the sql it is used in, and it therefore becomes part of the cache plan and only gets processed and compiled once, no matter how many rows you generate.

提交回复
热议问题