title: SQL Server query parse and compile time
body: <p>I am trying to optimize run time of a stored procedure and whenever SQL Server is not picking up the plan from cache, I am seeing lot of time spent on compiling and parsing of the stored procedure. I took these stats using </p>
  
  <pre><code>SET Statistics TIME ON
  
  EXEC [My_Stored_Proc_name] 
  
  SET Statistics TIME OFF
  </code></pre>
  
  <p>SQL Server parse and compile time: </p>
  
  <pre><code>CPU time = 1170 ms, elapsed time = 1173 ms.
  </code></pre>
  
  <p>Out of total run time of 1860 ms, SP is spending 1170 ms in compiling the stored procedure. Is there a way to optimize the compile plans?</p>
  
  <p>Note: the stored procedure is using around 30 + table joins.</p>