Cause can be
- Parameter sniffing: Is that a parameterized query or stored procedure?
- Outdate statistics => update them with
UPDATE STATISTICS dbo.yourTable WITH FULLSCAN
- Bad cached query plan; use WITH RECOMPILE
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi,
I have a table with a clustered index.
The query plans says the estimated number of rows from this table is 3574489 and the actual is 3460.
There are no missing statistics. I cannot understand why the estimated and actual are so different.
Does anyone have any ideas.
Thanks :)
Cause can be
UPDATE STATISTICS dbo.yourTable WITH FULLSCAN
The impact is on algorithms and resource allocation for the query. SQL Server has multiple algorithms that it can use for things like JOINs and GROUP BYs. The (estimated) size of the data is one of the primary items of information that it uses to choose the appropriate algorithm.
Hi @Benjamin Shaw ,
I cannot understand why the estimated and actual are so different.
The execution plan is always estimated with the latest statistics.
The measures that can be taken are as follows:
1.Rebuild the cluster index
2.Update statistics
- Update all statistics of the specified table: update statistics [tableName]
- Update the statistics of a single index of the specified table: update statistics [tableName] [indexName]
- Perform a full scan of the table and update statistics: update statistics [tableName (columnName)] with fullscan
3.If the above method does not work, you can try Option recompile.
Please refer to this: https://dba.stackexchange.com/questions/160076/wrong-estimated-number-of-rows
Best regards,
Seeya
If the response is helpful, please click "Accept Answer" and upvote it, as this could help other community members looking for similar queries.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.