10

Just wondering are statistics kept in the database but not in the memory? If I backup/restore the database from a prod server to a development server, would it keep the same statistics so that execution plans won't be much different if I do it on the development server?

Nick Chammas
14.8k17 gold badges77 silver badges124 bronze badges
asked May 8, 2013 at 18:37

3 Answers 3

16

The buffer pool is a cache of the database. There is never an 'or', things that are in the buffer pool are also in the database, always. And anything read from the database must be, even temporarily, present in the buffer pool.

As for the question: statistics are in the database so a backup/restore will preserve the statistics.

Note though that preserving statistics is not a guarantee to plan reproducibility. Other factors influence plan generation, like number of CPUs and amount of RAM.

answered May 8, 2013 at 18:50
0
10
Marcello Miorelli
17.3k53 gold badges182 silver badges324 bronze badges
answered May 8, 2013 at 19:42
4

As Remus said, table statistics are stored in the database similar to other objects like tables and indexes. They play a big role in selecting the execution plan, but there are other factors.

That being said, SQL Server knows another type of statistics, statistics that give us information about recent behavior.

For example the DMVs sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats return statistics about how the index is used.

Those statistics are stored in memory only. The get lost on server restart and do not travel with the backup.

However, the optimizer does not use these to generate a plan either.

Marcello Miorelli
17.3k53 gold badges182 silver badges324 bronze badges
answered May 9, 2013 at 9:42
1
  • Yeah, this is why I had the question/confusion in the first place. I was thinking statistics are similar to DMVs. They could be gone when server restarts or db restored to another server. Thanks for making the point. Commented May 10, 2013 at 13:32

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.