Sql-server – Can the plan-cache and/or statistics be copied from one instance to another

plan-cacherestoresql-server-2008-r2statistics

MS SQL Server 2008r2: I restore production databases on top of a staging instance that I use for testing. Is it possible to also copy the plan-cache and/or statistics to the staging instance, to better simulate the production environment for testing purposes?

Best Answer

You cannot copy individual plans form one server to another. You can copy statistics - generate script and run it on the test/staging env.

Mainly, you should focus on -

Constraints, Statistics, Table size (number of rows and pages) and Database options along with sessions SET options and hardware resources (maxdop and max memory settings) inorder for the query optimizer to select a plan.

Alternatively, you can use plan guide for single queries.

Again, since you are on sql server 2008 R2, you cannot use query store or dbcc clone database.