Share via

update stats

NeophyteSQL 241 Reputation points
2020-09-24T21:41:40.65+00:00

one of our applications that selects data from tables using multiple joins only work when update stats is performed on all underlying tables.

we had to update stats like evry 5 mins.

what could be the reason stats needing update for the query to perfrom, why is the query unable to re use stats.

any possible reasons.

SQL Server | Other
SQL Server | Other

Additional SQL Server features and topics not covered by specific categories


4 answers

Sort by: Most helpful
  1. NeophyteSQL 241 Reputation points
    2020-09-24T23:37:14.493+00:00

    query involves a cte with multiple joins and then case statement with or in the where clause

    then the cte is used to select the data required based on multiple joins with reference tables

    Was this answer helpful?


  2. Ronen Ariely 15,221 Reputation points
    2020-09-24T23:13:12.817+00:00

    Hi,

    is there a reason for dynamic sql to not use statistics.

    Obviously no. Any execution of query (dynamic or static) is done after the server check the statistics and build Execution Plan.

    There are different parameters that impact the Execution Plan which the server build and/or choose

    You should really provide DDL and the query which you use at least, so we will have understanding of your table(s) structure. This discussion is not useful without it in my opinion

    what could be the reason stats needing update for the query to perform

    Usually there is no need to update the statistics for each execution, and it is not done by the server for each query that you execute. Updating the statistics can impact the performance since the server will create new execution plan based on the new statistics. But as Erland said you can simply told the server to create the Execution Plan again by using sp_recompile (test if you really need to update the statistics manually or simply recompile)

    Was this answer helpful?

    0 comments No comments

  3. NeophyteSQL 241 Reputation points
    2020-09-24T22:55:32.617+00:00

    thanks you very much.

    there are multiple stored procedures involved.

    sql server 2016

    one of the stored procedures uses dynamic sql, is there a reason for dynamic sql to not use statistics.

    only when the statistics are updated, the application can select the data, I shall post the query shortly.

    thank you

    Was this answer helpful?

    0 comments No comments

  4. Erland Sommarskog 134.7K Reputation points MVP Volunteer Moderator
    2020-09-24T22:07:02.327+00:00

    All sorts. With the amount of information you have provided, this is about as intelligent answer I can give.

    Next time, rather than running UPDATE STATISTICS, just do sp_recompile on of the tables.

    It certainly could help if you posted the query. Also it would help to know the output of SELECT @@version and the compatibility level of the database.

    Was this answer helpful?

    0 comments No comments

Your answer

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