Note that there are some explanatory texts on larger screens.

plurals
  1. POSP cache plan not generated
    primarykey
    data
    text
    <p>There is something weird in this statement COALESCE(@param_ids + ',', '')</p> <p>@param_ids are passed in as param and it is @param_ids VARCHAR(MAX)</p> <p>Any idea why the SQL-Server could not able to produce a cache plan for below scenario. This issue has been escalted to Microsoft they are still working on it.</p> <p>Not working scenario - No cache plan is generated Step 1 </p> <p>Alter a SP</p> <pre><code> IF (LTRIM(RTRIM(ISNULL(@param_ids,''))) = '') BEGIN SELECT @param_ids = COALESCE(@param_ids + ',', '') + CONVERT(VARCHAR(50),ID) FROM [dbo].Content_Type WITH (NOLOCK) END </code></pre> <p>Step 2 Exec Sp with params</p> <p>Step 3 (No cache plan)</p> <pre><code>SELECT * FROM sys.dm_exec_cached_plans CROSS APPLY sys.dm_exec_sql_text(plan_handle) WHERE [dbid] = DB_ID('databasename') AND [objectid] = OBJECT_ID('databasename.dbo.us_spname') GO </code></pre> <p>Working scenario - cache plan is generated Step 1 </p> <p>Alter a SP</p> <pre><code> IF (LTRIM(RTRIM(ISNULL(@param_ids,''))) = '') BEGIN --SELECT @param_ids = COALESCE(@param_ids + ',', '') + CONVERT(VARCHAR(50),ID) --FROM [dbo].Content_Type WITH (NOLOCK) SELECT @param_ids = COALESCE('aaaaaaa' + ',', '') + CONVERT(VARCHAR(50),ID) FROM [dbo].Content_Type WITH (NOLOCK) END </code></pre> <p>Step 2 Exec Sp with params</p> <p>Step 3 (cache plan exits)</p> <pre><code>SELECT * FROM sys.dm_exec_cached_plans CROSS APPLY sys.dm_exec_sql_text(plan_handle) WHERE [dbid] = DB_ID('databasename') AND [objectid] = OBJECT_ID('databasename.dbo.us_spname') GO </code></pre> <p>Thankx</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload