SQL Server, Today I tell you why your Query is slow. Recompilation problems

Hi Guys, I hope you had a happy Easter! Today, as we often do, we talk about slowdowns . To be honest, one of the questions I get asked most often is this: "I have a Query that works fine for me and is very fast but when I try it from on customer’s server it is very slow! ...Why?" To answer this question, let's think first of all of everything that changes from your environment to that of the customer: everything ! The data Are you querying the same data ? SQL Server Optimizer creates the execution plan based on the "data it finds to read" (and store the execution plan inside the cache plan for performance reason.) So suppose you have taken a copy of the customer data via a backup and therefore have the same data. Are you already okay? No, absolutely! What you need is to have the same statistics and the same index fragmentation . You will therefore understand the first reason why the tests made on your PC are not very significant. Tests must be done...