Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Sometimes cte takes lone time

 
   Database Forums (Home) -> Programming RSS
Next:  Intellisense to SQL Server 2005 ?  
Author Message
tfs

External


Since: Nov 05, 2004
Posts: 75



(Msg. 1) Posted: Thu Aug 26, 2010 7:14 pm
Post subject: Sometimes cte takes lone time
Archived from groups: microsoft>public>sqlserver>programming (more info?)

I have a recursive routing that normally takes less than a second but
sometimes takes around 7 seconds and there is only 3 records in the table.

Why would that be? I can't seem to make it happen by clearing the cache and
bufferes but it does happen occasionally.

****************************************************
DBCC FREEPROCCACHE
DBCC DROPCLEANBUFFERS

declare @baseDocumentID int
Set @baseDocumentID = 5

;WITH PrrCTE(nDocumentID,nPrerequisiteFor, Level, baseDocumentID,
basePreReq )
AS
(
-- Anchor Member
SELECT nDocumentID, nPrerequisiteFor, 0, nPrerequisiteFor as
baseDocumentID, nDocumentID as basePreReq
FROM tblPrerequisite
WHERE nPrerequisiteFor = @baseDocumentID -- Start original document

UNION ALL

-- Recursive Member
SELECT
e.nDocumentID, e.nPrerequisiteFor, m.Level+1, m.baseDocumentID,
m.basePreReq
FROM
tblPrerequisite AS e
INNER JOIN PrrCTE m ON e.nPrerequisiteFor = m.nDocumentID
)
-- Using the CTE
SELECT nDocumentID, nPrerequisiteFor,Level, baseDocumentID, basePreReq
FROM PrrCTE
Order by basePreReq,Level
********************************************************

Am I missing something? The query works fine but am confused by the lag
time it occasionally takes.

Thanks,

Tom

 >> Stay informed about: Sometimes cte takes lone time 
Back to top
Login to vote
Erland Sommarskog2

External


Since: May 30, 2004
Posts: 1649



(Msg. 2) Posted: Fri Aug 27, 2010 6:25 pm
Post subject: Re: Sometimes cte takes lone time [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

tshad (tfs@dslextreme.com) writes:
> I have a recursive routing that normally takes less than a second but
> sometimes takes around 7 seconds and there is only 3 records in the table.

With that amount of data, the reasonable explanation I can think of
is blocking. Or your machine is about to cave in. Smile

--
Erland Sommarskog, SQL Server MVP, esquel.TakeThisOut@sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

 >> Stay informed about: Sometimes cte takes lone time 
Back to top
Login to vote
tfs

External


Since: Nov 05, 2004
Posts: 75



(Msg. 3) Posted: Fri Aug 27, 2010 6:25 pm
Post subject: Re: Sometimes cte takes lone time [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Erland Sommarskog wrote:
> tshad (tfs@dslextreme.com) writes:
>> I have a recursive routing that normally takes less than a second but
>> sometimes takes around 7 seconds and there is only 3 records in the
>> table.
>
> With that amount of data, the reasonable explanation I can think of
> is blocking. Or your machine is about to cave in. Smile

There is no blocking - but the caving would be a possible explanation Smile

Thanks,

Tom
 >> Stay informed about: Sometimes cte takes lone time 
Back to top
Login to vote
Erland Sommarskog2

External


Since: May 30, 2004
Posts: 1649



(Msg. 4) Posted: Sat Aug 28, 2010 6:25 am
Post subject: Re: Sometimes cte takes lone time [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

tshad (tfs@dslextreme.com) writes:
> Erland Sommarskog wrote:
>> tshad (tfs@dslextreme.com) writes:
>>> I have a recursive routing that normally takes less than a second but
>>> sometimes takes around 7 seconds and there is only 3 records in the
>>> table.
>>
>> With that amount of data, the reasonable explanation I can think of
>> is blocking. Or your machine is about to cave in. Smile
>
> There is no blocking - but the caving would be a possible explanation Smile

Yet a possibility if the table has a lot larger is that it still is
very big and lot of space, and therefore takes a long time to scan. What
does sp_spaceused report for the table?


--
Erland Sommarskog, SQL Server MVP, esquel DeleteThis @sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
 >> Stay informed about: Sometimes cte takes lone time 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
"Time key is not updateable" HELP! - I have a sql database connected with access, but when I try to run macros which basically just transfer information from tables for approval an error comes up with "time key is not updateable". I have found a quick fix in which I can delete the...

Localizing the Time - Hi All, I am using a SQL Server that is hosted in the US, and I am UK based. The hosts can't change the localization of the DB (understandably), and currently, when I need to insert a date into a column, I use something similar to: BEGIN UPDATE user...

diff between CPU time and elapsed time? - Hi, What is the difference between the CPU time and the Elapsed time as seen in the TKPROF results? Thanks, Santosh

TSQL TIme Series - have a problem with time series. This is my problem : Scenario 1 – I have the output below which is made up intervals with hourly repeating values StartDate EndDate DMas...

Calculate time intervals - I have data as following: create table #test (jobcategory int, startsusptime datetime, endsusptime datetime) nsert into #test values (1, '2007-05-03 14:12:39.033', '2007-05-04 06 insert into #test values (2, '2007-05-03 14:19:26.547', '2007-05-03 ..
   Database Forums (Home) -> Programming All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]