performance difference between User Defined Function and Stored Procedures

后端 未结 6 956
终归单人心
终归单人心 2021-01-08 00:28

If a statement return rows doing a simple select over the data base, is there performance difference between implement it using Function and Procedures? I know it is prefera

6条回答
  •  时光说笑
    2021-01-08 00:52

    The first time I tried to use an Inline Table Valued Function (TVF), it actually took 66 to 76% (1.147 to 1.2 vs. 0.683 secs.) longer (vs. a Stored Procedure (SP))!?! That was the average of 100 iterations with 89 Rows per iteration. My SP was just doing the standard set nocount on followed by a complex (but still single) select Statement (with 5 inner join's and 2 outer join's (with one of the inner join's having an on Expression with an embedded select (which itself had a where Expression (with an embedded select + inner join))) and a group by and order by with 5 Columns and a count). The Caller is an insert into a Temp Table (with an identity Column but no Keys or Indexes) - Statement. The Inline TVF took 66% longer even without the order by the SP was doing. When I added it back in (to the select calling the Inline TVF since you can't have order by in an Inline TVF), it took even longer (76%)!?!

提交回复
热议问题