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
 General SQL Server Forums
 New to SQL Server Programming
 Long query

Author  Topic 

handro1104
Starting Member

3 Posts

Posted - 2012-02-11 : 08:54:30
Recently I ran a query that took a long time to finish and it slowed down all the other users. Slowing down other user doesn't make sense; is this normal? Is there a way to make all users run independently?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-11 : 09:02:05
its normal if you're using a transaction or placing an exclusive lock on one ore more shared objects

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-02-11 : 09:21:01
Did you do a show plan?

Please post your query if you need some help figuring pout what's going on

when you run it, also run sp_who2 and sp_lock



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-02-11 : 09:22:00
And it depends on what type of query..is it just a select, or are you modifying data?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

handro1104
Starting Member

3 Posts

Posted - 2012-02-11 : 09:33:54
Thank you very much for the answers. I don't need help with the query; my concern is why it affected, slowed down, all other used. It was a select query not using a transaction or placing an exclusive lock on one ore more shared objects. It was a very inefficient query on very large tables and probably used a huge space.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-11 : 09:43:51
yep...even that can be a reason. if there were no proper indexes etc it can cause query to scan big table etc which can also cause hiccups. Analysing execution plan will give more info on that

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

handro1104
Starting Member

3 Posts

Posted - 2012-02-11 : 10:05:47
So, the thing is my queries will affect, slow down, other users. I was working under the impression that the execution was running in a CPU with multiprogramming and time slicing, giving a few milliseconds to each user in turn; that way if my query is inefficient, it will be very slow for me (it would take a lot of time slices), but nobody will be slowed down, they would get their time slices at the same time regardless of my query. This is how programs run in computers; is there a reason why a database would be different? If this is true, then in a production environment, a user running a complex query will slow down all other users.
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2012-02-11 : 12:48:24
quote:
Originally posted by handro1104

So, the thing is my queries will affect, slow down, other users. I was working under the impression that the execution was running in a CPU with multiprogramming and time slicing, giving a few milliseconds to each user in turn;


That's not how the SQL OS handles multi-tasking. It lets a query run until it completes or exceeds its quantum (which is not a few ms). If the query was large and inefficient, it would probably have been run in parallel too, so using multiple cores concurrently. If it was really inefficient and large, it could have used 100% of the processing power on the server.

In addition, it would have taken locks, even just as a read query. So any query that wanted to modify the locked objects (and an inefficient query could well lock far more than necessary for far longer than necessary) would have to wait.

To add to that, the query could well have needed a larger amount of workspace memory than normal queries, and there's only a limited amount of that so it could have caused other queries to wait for memory grants, etc, etc, etc.

quote:
If this is true, then in a production environment, a user running a complex query will slow down all other users.


Yup, which is why writing good, efficient code is so important.

--
Gail Shaw
SQL Server MVP
Go to Top of Page
   

- Advertisement -