July 19, 2005 03:19 PM

Conditional Recompile

Strike a balance between performance and security
Rating: (0)
SQL Server Magazine
InstantDoc ID #46643
Since SQL Server's first release, the ability to reuse the saved execution plans for stored procedures has been touted as one of the best things about the product. As I demonstrated last month in "Reusing Query Plans" (InstantDoc ID 46233), reusing a saved plan doesn't always produce the best performance. It works when the saved plan is a useful plan, but not when the plan is inappropriate for the current parameter values. SQL Server's query optimizer develops the execution plan for a stored procedure based on the parameters available at the time. So, the plan might be ideal for the initial parameters but not for parameters passed in subsequent procedure calls.

Las...

...This article is for paid Professional Members only.

Already a Professional Member? Please log in now:

NOT A PROFESSIONAL MEMBER? YOU CHOOSE:

Professional Membership

Monthly

Annual

VIP Membership

Monthly

Annual

Add a Comment

Filled a big void in my expectations. After reading Reusing Query Plans in July, I felt ripped off, like I'd been left hanging (ever experienced this sub-optimal plan caching problem?...yeah, sucks doesn't it?). I was left asking myself "what about dynamic SQL? would that do the trick? if not, then what's the answer? there must be some solution, otherwise why write an article about it?" When I read part 2 (actually I guess this would be part 3) today I was breathing a sigh of relief by the end of the first page - "ahhh...she's addressing dynamic SQL...my life isn't meaningless after all...some closure at last". Great article.

I was left wondering about SQL 2005 however. Have the Microsoft guys done anything, other than statement-level recompiles, to address this problem? Also, do triggers (SQL 2000 & 2005) suffer from this same compiled plan problem? They do cache plans don't they (there are Cache Manager perfmon counters for trigger plans)? Can trigger plan recompiles be forced? When are they automatically recompiled? etc., etc. There's probably another article in the making there somewhere...

belwar 8/24/2005 10:31:34 PM


You must log on before posting a comment.

Are you a new visitor? Register Here
GOOGLE LINKS
SPONSORED LINKS
FEATURED LINKS