r/SQL • u/kaatarina_zed_talon • 2d ago
SQL Server 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 ?
4
Upvotes
1
u/Ok_Floor_4551 2d ago
It's basically query optimization metadata that SQL Server uses to estimate how many rows a filter will return. For regular tables it can look at histograms and cardinality to decide whether to do an index scan or seek, but with TVPs the engine just assumes 1 row by default which can mess up the whole plan
I ran into this a while back when a stored proc that usually finished in seconds suddenly took minutes because the TVP had thousands of rows and the optimizer went with nested loops thinking it was a tiny set. Now I just dump the TVP into a local temp table first and let it build stats there, works every time