• Little Nick (1/11/2012)


    RESOURCE_SEMAPHORE_QUERY_COMPILE waits is high. My understanding, this nothing to do with my ASP.NET code technique

    Let's, my same Stored Procedure is execute 500 a day. Did we have special technique to make it run efficiently?

    Sure it does. You aren't using parameters so every call to sp_executesql is likely requiring a compilation. If you use parameters properly then you will more likely get plan re-use. Even ORM tools like Linq to SQL, EF, hibernate/nhibernate use parameters.

    Plus, performance isn't your biggest problem in this case it is the security hole you leave open by using non-cleansed input to build a sql string.

    From http://technet.microsoft.com/en-us/library/cc293620.aspx

    Keep in mind that caching is done on a per-batch level. If you try to force parameterization using sp_executesql or Prepare/Execute, all the statements in the batch must be parameterized for the plan to be reusable. If a batch has some parameterized statements and some using constants, each execution of the batch with different constants will be considered distinct, and there will be no value to the parameterization in only part of the batch.

    You might also want to read this post, http://blogs.msdn.com/b/sqlprogrammability/archive/2007/01/21/2-0-diagnosing-plan-cache-related-performance-problems-and-suggested-solutions.aspx