Home > Archive > Microsoft SQL Server forum > October 2005 > Count(*) Locking up things ...









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Count(*) Locking up things ...
csomberg@dwr.com

2005-10-28, 11:23 am

SQL 2000

I have inherited an application where many of the automated processes
call a proc that simply returns the number of records with a NEW
status.

In watching the process in SQL, I see this ends up blocking a lot of
processes - many like this are called every 5-30 seconds ...

I wish to replace COUNT(*) with EXISTS if that will make things operate
faster with no locks ...

Thoughts ...

Thanks everyone !!

Craig

Hugo Kornelis

2005-10-28, 8:23 pm

On 28 Oct 2005 09:13:07 -0700, csomberg@dwr.com wrote:

>SQL 2000
>
>I have inherited an application where many of the automated processes
>call a proc that simply returns the number of records with a NEW
>status.
>
>In watching the process in SQL, I see this ends up blocking a lot of
>processes - many like this are called every 5-30 seconds ...
>
>I wish to replace COUNT(*) with EXISTS if that will make things operate
>faster with no locks ...
>
>Thoughts ...
>
>Thanks everyone !!
>
>Craig


Hi Craig,

EXISTS will be faster than COUNT(*). It will still create locks, but
they'll last shorter.

That being said - if you need to know the number of rows with a NEW
status, then EXISTS won't do you any good. OTOH, if the current count is
only used to compare against 0 (i.e. to check whethere there are any NEW
rows or none), then changint to EXISTS is a no-brainer.

However, a far better performance gain would be the use of an index. If
your current query looks something like:

SELECT COUNT(*)
FROM SomeTable
WHERE Status = 'NEW'

Then adding the index below will speed it up tremendously, and probably
reduce your current blocking issues as well:

CREATE NONCLUSTERED INDEX YourIndex ON SomeTable(Status)

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com