Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 query that runs faster the second time

Author  Topic 

rtutus
Aged Yak Warrior

522 Posts

Posted - 2007-09-27 : 11:56:49
Hi,
We have a delete query , we run the query and it takes many seconds, the seond time we run the query it takes only 3 seconds (away faster)

How do we know what s going on with sql server at a specific moment? weither other requests are making it slow or what exactly causes the random slowdown while runing a query. Someytimes it runs fast and other times it takes for ever

Thanks.

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-09-27 : 11:58:32
Run profiler while running the query to see if any other process is blocking it.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

rtutus
Aged Yak Warrior

522 Posts

Posted - 2007-09-27 : 12:05:14
can u give more details pls? where I shoudl look in profiler to see if another process is blocking it?

Pls, Any suggestion is more than welcome, thanks a lot.
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-09-27 : 13:05:58
"We have a delete query , we run the query and it takes many seconds, the seond time we run the query it takes only 3 seconds (away faster)"

That's the opposite way round to your Subject: "query that runs slowly the second time"

Assuming that the first time is slower that may be because of the time to build the query plan 9whcih is then cached for the second time) and the time to retrieve the data, which may then be cached in memory for the second instance.

Kristen
Go to Top of Page

rtutus
Aged Yak Warrior

522 Posts

Posted - 2007-09-27 : 13:14:49
quote:
Originally posted by Kristen

"We have a delete query , we run the query and it takes many seconds, the seond time we run the query it takes only 3 seconds (away faster)"

That's the opposite way round to your Subject: "query that runs slowly the second time"

Kristen



thanks Kristen, I changed the title of the subject

Thanks guys
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2007-09-27 : 13:19:51
Wouldn't you expect it to run faster the second time, since you already deleted the rows the first time?



CODO ERGO SUM
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-09-27 : 13:56:28
I hope that isn't the answer, otherwise I'll feel really stupid!
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2007-09-27 : 14:17:49
Just sayin'

CODO ERGO SUM
Go to Top of Page

rtutus
Aged Yak Warrior

522 Posts

Posted - 2007-09-27 : 19:24:36
quote:
Originally posted by Kristen

I hope that isn't the answer, otherwise I'll feel really stupid!



True, supposed to run faster (according to your posts guys), but we re talking 15 minutes and 45 minutes for a delete query. So that s a lot.

Kristen, don t worry, cause if u feel stupid, how should I feel :) :)
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-09-27 : 20:08:08
</FeelingMuchBetterNow>
Go to Top of Page

rtutus
Aged Yak Warrior

522 Posts

Posted - 2007-09-28 : 09:33:21
Thanks for the advice:

Our environnement is SQL 2000. And here is the query:

delete from MyTable1 where ALIQUOTSID in

(select MyTable1.ALIQUOTSID from (select MyTable3.FOLDERNO, MyTable3.LOGDATE, Logaliquots.aliquotsid from (select FolderDEL.*, orders.ORDNO from (select FOLDERNO, LOGDATE from FOLDERS where LOGDATE < '2006-01-01') FolderDEL left join orders on FolderDEL.FOLDERNO = orders.FOLDERNO) MyTable3

left join Logaliquots on MyTable3.ORDNO = Logaliquots.ORDNO) MyTable2 left join MyTable1 on MyTable2.aliquotsid = MyTable1.aliquotsid

where MyTable1.ALIQUOTSID is not null)


2/ also, what do u think about the query, is it good? my colleague mage it.

Thanks for brainstorming

Go to Top of Page

rtutus
Aged Yak Warrior

522 Posts

Posted - 2007-09-28 : 10:07:15
quote:
Originally posted by harsh_athalye

Run profiler while running the query to see if any other process is blocking it.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"



Another question pls:
Please, how do I know if an other process is blocking it, where in the profiler trace can I see that?

Thank you
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-09-28 : 10:59:28
"what do u think about the query, is it good?"

I think that all those nested selects make it hard to read, and thus to maintain. And it make sit hard for me to understand what it is doing, and to help ... which may also be considered a bad thing, perhaps!!

Can't you just use JOINS instead?

Kristen
Go to Top of Page

rtutus
Aged Yak Warrior

522 Posts

Posted - 2007-10-01 : 10:43:54
Thanks amigo :)
Go to Top of Page
   

- Advertisement -