Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Stored Procedure looses execution plan. Expand / Collapse
Author
Message
Posted Wednesday, December 26, 2012 9:34 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Yesterday @ 2:53 PM
Points: 73, Visits: 339
I have a stored procedure and when I run it First time it creates an execution plan and it takes long time to complete which is understandable after the first time when I run it second time, it works perfectly...

now here is the issue... If I run the proc lets say today manually then there is no issue rest of the day and application accessing it don't complain about timeout issues...

when I run the proc tomorrow it again takes forever to complete...and the applications time out on the front end...

to resolve the time out I have to manually go to SSMS run the stored proc..and then applications have no issue for the rest of the day.

my question is why is the Query execution plan getting flushed/lost next day ?
the data doesnt change much and not at all some times...


SP uses Temp table and correlated subquery.
Post #1400285
Posted Wednesday, December 26, 2012 9:52 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Yesterday @ 2:34 PM
Points: 8,592, Visits: 8,233
WangcChiKaBastar (12/26/2012)
I have a stored procedure and when I run it First time it creates an execution plan and it takes long time to complete which is understandable after the first time when I run it second time, it works perfectly...

now here is the issue... If I run the proc lets say today manually then there is no issue rest of the day and application accessing it don't complain about timeout issues...

when I run the proc tomorrow it again takes forever to complete...and the applications time out on the front end...

to resolve the time out I have to manually go to SSMS run the stored proc..and then applications have no issue for the rest of the day.

my question is why is the Query execution plan getting flushed/lost next day ?
the data doesnt change much and not at all some times...


SP uses Temp table and correlated subquery.


That is the nature of execution plans. They can and will be removed from the cache when sql needs the room for something else. If this data is pretty constant maybe you could use a table to hold the results instead of running your proc repeatedly.


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Post #1400292
Posted Wednesday, December 26, 2012 12:56 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 2:54 AM
Points: 37,692, Visits: 29,951
It's probably got nothing whatsoever to do with the cached execution plan. The optimiser is not allowed (in most cases) to spend minutes optimising a query.

What's probably causing the slow-down is having to re-load the data required for the procedure into the data cache. I'd guess that something like index rebuilds, checkDB or large data loads are done at night, hence displacing the data cache.

The solution here is to tune the query, it's probably requiring more data than it should due to inefficient queries or poor indexing and you mainly see the effects of that when the data has to be pulled from disk.



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1400344
Posted Thursday, December 27, 2012 2:42 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, March 26, 2013 8:41 AM
Points: 2,562, Visits: 3,451
GilaMonster (12/26/2012)
The optimiser is not allowed (in most cases) to spend minutes optimising a query.
Not allowed means? what i think is optimizer will take time to generate plan regardless of time boundation.please explain


-------Bhuvnesh----------
While 1 = 1 (Learning SQL....)
Click to get fast response of your post
Post #1400516
Posted Thursday, December 27, 2012 3:02 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, May 13, 2013 5:41 AM
Points: 2, Visits: 42
ok
Post #1400527
Posted Thursday, December 27, 2012 3:04 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 2:54 AM
Points: 37,692, Visits: 29,951
Bhuvnesh (12/27/2012)
what i think is optimizer will take time to generate plan regardless of time boundation.


You would be thinking incorrectly then. Google: optimiser 'reason for early termination'



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1400529
Posted Thursday, December 27, 2012 3:33 AM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Today @ 12:57 AM
Points: 299, Visits: 484
WangcChiKaBastar (12/26/2012)
when I run the proc tomorrow it again takes forever to complete...and the applications time out on the front end...

to resolve the time out I have to manually go to SSMS run the stored proc..and then applications have no issue for the rest of the day.

my question is why is the Query execution plan getting flushed/lost next day ?
the data doesnt change much and not at all some times....


Check Sql Error log to find what cleared your plan cache.There you can see some error messages like below.

QL Server has encountered 1 occurrence(s) of cachestore flush for the 'Object Plans' cachestore (part of plan cache) due to "" Operation.

Post #1400538
Posted Thursday, December 27, 2012 3:40 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 2:54 AM
Points: 37,692, Visits: 29,951
dbasql79 (12/27/2012)
Check Sql Error log to find what cleared your plan cache.There you can see some error messages like below.

QL Server has encountered 1 occurrence(s) of cachestore flush for the 'Object Plans' cachestore (part of plan cache) due to "" Operation.


That only logs complete clearing of the cache, not if single plans are aged out or invalidated.



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1400539
Posted Thursday, December 27, 2012 5:04 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, March 26, 2013 8:41 AM
Points: 2,562, Visits: 3,451
GilaMonster (12/27/2012)
Bhuvnesh (12/27/2012)
what i think is optimizer will take time to generate plan regardless of time boundation.


You would be thinking incorrectly then. Google: optimiser 'reason for early termination'

will this option also return value when first time exec plan get created ?
is this option gives the value of 'reason for early termination' when query tried to use same plan for last time ? like if we get "timed out" , does that mean that query coudnt able to generate new plan and used plder one ?


-------Bhuvnesh----------
While 1 = 1 (Learning SQL....)
Click to get fast response of your post
Post #1400564
Posted Thursday, December 27, 2012 5:13 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 2:54 AM
Points: 37,692, Visits: 29,951
Bhuvnesh (12/27/2012)
will this option also return value when first time exec plan get created ?


Yes

is this option gives the value of 'reason for early termination' when query tried to use same plan for last time ? like if we get "timed out" , does that mean that query coudnt able to generate new plan and used plder one ?


No. Did you do the research?



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1400569
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse