473,472 Members | 2,257 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

Oct 28 '05 #1
1 1580
On 28 Oct 2005 09:13:07 -0700, cs******@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)
Oct 28 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Puvendran | last post by:
Hi, We have encountered deadlock on a table which is used to generate sequential numbers for different categories eg typical entries Category Value TRADE_NO ...
9
by: john smile | last post by:
Hi All, I want to lock 2 tables on 2 servers using TABLOCKX hint. These tables function as semaphores in my application. It means when the tables are locked then other users will not be able to...
2
by: spammy | last post by:
hi all, im trying to establish whether i have a race condition or critical section in the following. i have a dataaccess class that continually retireves a table from a sqlserver (which may be...
3
by: Chris Tanger | last post by:
I am creating a class that has a method "Write" that I wish to make threadsafe. The method must block calling threads until the task performed in write is complete. Only 1 thread at a time can...
5
by: Arsen V. | last post by:
Hello, What is the best way to accomplish the following. 1) An ASP.NET program (consiting of one file somepage.aspx) receives about 25,000,000 requests pay day. 2) The requests come from a...
10
by: McFly Racing | last post by:
Thread Locking In Static Methods I have the need for a Log Manger class that has static methods. Normally I would use the lock statement or a Monitor statement both of which take a...
2
by: Brian Hirt | last post by:
I have a question about locks. I have a stats table that get updated when some other table changes. Sometimes that other table is updated a 2nd time before the first stats update is finished...
0
by: shakahshakah | last post by:
Just started investigating InnoDB after having used MyISAM tables in the 4.0.12 version, almost immediately ran into a locking issue with INSERTs, DELETEs, and transactions. Given the following...
2
by: heyzulu59 | last post by:
I thought that an online backup could always be run while other processes with the database went about their business. However today I noticed that certain processes in my production database were...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.