patternsqlMinor
Estimated row size and estimated data size is incorrect
Viewed 0 times
incorrectsizeestimatedandrowdata
Problem
I have a 9 million record table that is about 452MB in size (disregarding NC indexes). Below is physical stats and the columns
As a simple example, if I dump the table into a temp table, the actual plan shows a whopping 42GB estimated and actual data size. See image below.
I suspect this is due to the two varchar(4000) columns which is causing the estimated row size to be larger than they are. However, I really don't think 42GB are being transfered - not sure how that would be possible.. I don't know if I'm seeing performance issues because of this but the query plan looks scary because of these wrong estimates. Why is the query plan so wrong on the estimated and actual table scans?
As a simple example, if I dump the table into a temp table, the actual plan shows a whopping 42GB estimated and actual data size. See image below.
I suspect this is due to the two varchar(4000) columns which is causing the estimated row size to be larger than they are. However, I really don't think 42GB are being transfered - not sure how that would be possible.. I don't know if I'm seeing performance issues because of this but the query plan looks scary because of these wrong estimates. Why is the query plan so wrong on the estimated and actual table scans?
Solution
SQL Server just uses a ballpark estimate for
So each
It seems that in reality you could reduce the maximum size of these columns.
This would reduce the estimated row size. Having an accurate estimated row size can help when there are memory consuming operators in the plan for getting an appropriately sized memory grant.
varchar that each value will on average be half the column capacity.So each
varchar(4000) will be estimated at 2,000 bytes. You have two of them so that explains the bulk of the 4,496 bytes estimate.It seems that in reality you could reduce the maximum size of these columns.
This would reduce the estimated row size. Having an accurate estimated row size can help when there are memory consuming operators in the plan for getting an appropriately sized memory grant.
Context
StackExchange Database Administrators Q#118777, answer score: 6
Revisions (0)
No revisions yet.