October 30, 2015 at 9:46 am
Select A.* from A inner join B on ( A.ID= B.ID )
I know there is some key word that you use to force SQL server to generate a new query plan ?
What can that be ?
Thanks
October 30, 2015 at 9:48 am
RECOMPILE
select a.* from a inner join b on a.id = b.id option (recompile)
October 30, 2015 at 10:06 am
mw112009 (10/30/2015)
Select A.* from A inner join B on ( A.ID= B.ID )
I know there is some key word that you use to force SQL server to generate a new query plan ?
What can that be ?
Thanks
There's a cost associated with it - recompiles are quite expensive. Why do you want to do this?
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
October 30, 2015 at 10:57 am
In an OLTP database, you want to minimize recompiles, so you don't want to leave RECOMPILE hint in production. However, in a DW database where tables are bulk loaded, statistics shift frequently, and queries are occasional or ad-hoc, then a case could be made to always recompile. In a DW the overhead of plan compilation is trivial compared to duration of the query, and you want the best possible plan based on most recent statistics and parameters.
"Do not seek to follow in the footsteps of the wise. Instead, seek what they sought." - Matsuo Basho
October 31, 2015 at 6:46 pm
Eric M Russell (10/30/2015)
In an OLTP database, you want to minimize recompiles, so you don't want to leave RECOMPILE hint in production.
I think that's an over generalized statement... "Catch All" procs (with multiple, optional parameters) for example, tend to benefit greatly from the use of the OPTION(RECOMPILE) hint.
In reality, it just depends on the query... Does the cost of recompilation out way the cost of using a sub-optimal execution plan?
November 1, 2015 at 12:33 am
Jason A. Long (10/31/2015)
Eric M Russell (10/30/2015)
In an OLTP database, you want to minimize recompiles, so you don't want to leave RECOMPILE hint in production.I think that's an over generalized statement... "Catch All" procs (with multiple, optional parameters) for example, tend to benefit greatly from the use of the OPTION(RECOMPILE) hint.
In reality, it just depends on the query... Does the cost of recompilation out way the cost of using a sub-optimal execution plan?
+1000 As with all else, "It Depends". A bad query plan that causes a multi-minute run is much more expensive that the combination of a RECOMPILE and good plan, which frequently ends up being sub-second. Of course, you can get the best of both worlds using Gail's "Catch All Query" method using dynamic SQL.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 1, 2015 at 7:08 am
Jason A. Long (10/31/2015)
Eric M Russell (10/30/2015)
In an OLTP database, you want to minimize recompiles, so you don't want to leave RECOMPILE hint in production.I think that's an over generalized statement... "Catch All" procs (with multiple, optional parameters) for example, tend to benefit greatly from the use of the OPTION(RECOMPILE) hint.
In reality, it just depends on the query... Does the cost of recompilation out way the cost of using a sub-optimal execution plan?
Not an over generalzation, I presented a DW scenario having a narrow case usage, and simply said the case for recompile all can be made, but maybe not applied. It depends on how much time, relative to data processing, the CPU would spend compiling. Ive seen some DW databases that would run only a handfull of query executions daily, and each query would run for more than an hour.
"Do not seek to follow in the footsteps of the wise. Instead, seek what they sought." - Matsuo Basho
November 1, 2015 at 3:26 pm
Yes, Well you can use RECOMPILE or OPTIMIZE FOR / PLAN GUIDES query hints ... i never used these but below links helps to understand.
https://msdn.microsoft.com/en-us/library/ms190417.aspx
https://msdn.microsoft.com/en-us/library/hh213001.aspx
basically syntax used is
exec <stored proc> WITH RECOMPILE ;
or exec sp_recompile '<object_name>'
more to understand .... http://www.brentozar.com/archive/2013/12/recompile-hints-and-execution-plan-caching/
best of luck
@JayMunnangi
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply