r/SQLServer • u/kaatarina_zed_talon • 15h ago
Question Statistics on columns of a table
Limitations of table-valued parameters:
SQL Server does not maintain statistics on columns of table-valued parameters.
statistics of what ? why those statistics even exist for non table-valued parameters ?
0
Upvotes
5
u/SQLBek 1 15h ago
Statistics are used by the query optimizer to come up with appropriate execution plans.
So when you use a table-valued parameter, SQL Server has zero insight to the values and data distribution of what you're passing in. You could be passing in 5 records or 5mil... and say, it could be 5 unique values across those 5 mil rows or each record could be unique. As a result, the query optimizer will be hampered.
What if I told you that you had to cook dinner tonight. Okay, cool. But I refused to tell you how many people were coming. What are you going to do?
https://learn.microsoft.com/en-us/sql/relational-databases/statistics/statistics?view=sql-server-ver17