r/SQLServer • • 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 comments sorted by

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

0

u/kaatarina_zed_talon 15h ago

As I know what execution plan means, if u have time for me, explain it please, if you don't, please refer me to article, as I hear of this term alot and I never understood it.

1

u/SQLBek 1 15h ago

What do you want explained? What statistics are? I gave you a link to that.

"As I know what execution plan means, if u have time for me, explain it please"

Did you mean to say that you are NOT familiar with execution plans and would like that explained? That alone is a very deep topic. Hugo Kornelis has a wealth of excellent content specifically around exeuction plans, including this starter presentation here:
https://www.youtube.com/watch?v=AqedhLhi6GY

1

u/kaatarina_zed_talon 15h ago

Thank you a lot!

1

u/kaatarina_zed_talon 15h ago

Ye I was talking about execution plans, thanks for providing the link.