all groups > sql server (alternate) > october 2005 >
You're in the

sql server (alternate)

group:

Count(*) Locking up things ...


Count(*) Locking up things ... csomberg NO[at]SPAM dwr.com
10/28/2005 9:13:07 AM
sql server (alternate):
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
Re: Count(*) Locking up things ... Hugo Kornelis
10/28/2005 9:49:37 PM
[quoted text, click to view]

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
--

AddThis Social Bookmark Button