SQL Server doesn't have the statistics for the table variable?

后端 未结 2 966
伪装坚强ぢ
伪装坚强ぢ 2021-01-16 00:48

I found the MSDN says that \"table variables don\'t have statistics\"

https://msdn.microsoft.com/en-us/library/dd535534(v=sql.100).aspx

Also the following ar

2条回答
  •  醉梦人生
    2021-01-16 01:17

    I found the following phrase in this article by Itzik Ben-Gan Improvements in Table Variables and Temporary Tables in SQL Server 2014:

    Cardinality Estimates with TF 2453

    The last improvement that I’ll discuss in this article concerns table variables and is available in SQL Server 2014 RTM CU3 and in SQL Server 2012 SP2. You can find the support entry describing it here.

    It’s a well-known fact that SQL Server doesn’t maintain statistics like histograms and density vectors for table variables. However, SQL Server does maintain a count of rows in the table, which in some cases can go a long way in helping the optimizer make optimal choices.

    You are using Enterprise Edition. I think this explains it. The article by Kendra Little does say that Enterprise Edition is smarter.

    I'd try to check with DBCC SHOW_STATISTICS the details of the statistics objects that you see and confirm whether they have all the data the normal statistics objects have. Statistics objects created for table variables should have less data, for example, no histogram. I don't have Enterprise Edition at hand to test.

提交回复
热议问题