T-SQL code is extremely slow when saved as an Inline Table-valued Function

馋奶兔 提交于 2019-12-01 05:22:53

When you use literals SQL Server can look at the column statistics to estimate how many rows will be returned and choose an appropriate plan based on that assumption. When you use variables the values are not known at compile time so it falls back on guesses.

If the plan is better when it guesses than when it refers to the actual statistics then this indicates the statistics likely need updating.

If you have auto update of statistics turned on then you may well be hitting the issue here Statistics, row estimations and the ascending date column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!