Drop Table

Support Forum for database administrators and web based access to important newsgroups related to databases
Register on Database Support Forum Edit your profileCalendarFind other Database Support forum membersFrequently Asked QuestionsSearch this forum -> 
For Database admins: Free Database-related Magazines Now Free shipping to Texas


Post New Thread










Thread
Author

Count(*) Locking up things ...
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


Report this thread to moderator Post Follow-up to this message
Old Post
csomberg@dwr.com
10-28-05 04:23 PM


Re: Count(*) Locking up things ...
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)

Report this thread to moderator Post Follow-up to this message
Old Post
Hugo Kornelis
10-29-05 01:23 AM


Sponsored Links





Last Thread Next Thread
Post New Thread

Microsoft SQL Server forum archive

Show a Printable Version Email This Page to Someone! Receive updates to this thread
Microsoft SQL Server
Access database support
PostgreSQL Replication
SQL Server ODBC
FoxPro Support
PostgreSQL pgAdmin
SQL Server Clustering
MySQL ODBC
Web Applications with dBASE
SQL Server CE
MySQL++
Sybase Database Support
MS SQL Full Text Search
PostgreSQL Administration
SQL Anywhere support
DB2 UDB Database
Paradox Database Support
Filemaker Database
Berkley DB
SQL 2000/2000i database
ASE Database
Forum Jump:
All times are GMT. The time now is 03:40 PM.

 
Mobile devices forum | Database support forum archive




Copyrights DropTable.com Database Support Forum 2004 - 2006