Estimated rows and actual rows very different

Benjamin Shaw 141 Reputation points
2021-06-21T10:30:08.38+00:00

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 :)

Developer technologies | Transact-SQL
SQL Server | Other
{count} votes

3 answers

Sort by: Most helpful
  1. Olaf Helper 47,441 Reputation points
    2021-06-21T10:51:43.05+00:00

    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
    0 comments No comments

  2. AddWebSolution 171 Reputation points
    2021-06-21T11:17:44.277+00:00

    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.

    0 comments No comments

  3. Seeya Xi-MSFT 16,586 Reputation points
    2021-06-22T05:46:17.867+00:00

    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.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.