473,799 Members | 3,026 Online
Bytes | Software Development & Data Engineering Community
+ 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 1592
On 28 Oct 2005 09:13:07 -0700, cs******@dwr.co m 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(Statu s)

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
9576
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 1456 JOB_NO 267 .....
9
5070
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 access them and automatically they can not continue their works. I have tried using the following code, but it does not work. I always got the error :
2
1352
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 slow). it provides a cached copy of this table to clients, for them to read from (note: there are no writes). the idea being if a particular table retrival takes time, the class would still provide a cached copy. now the code:
3
2498
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 perform the task within "Write". 1-10 different threads may call "Write" simultaneously and continuously, some in a greedy manner. That is to say that some of the threads calling "Write" will take all they can get, while other threads may only call...
5
1490
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 limited set of IP addresses. 3) How to count the total number of request from each IP address per day.
10
11916
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 reference to (this). In the case of these static methods I am not able to do that.
2
1297
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 which causes an error. I've tried using 'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE' but get 'could not serialize access due to concurrent update' If i try 'READ COMMITED' i get primary key failures. This seems like it's a pretty common thing,...
0
2307
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 table: CREATE TABLE test1 ( f1 varchar(32) default NULL ) and a steady stream of INSERTs from a command-line shell:
2
4909
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 in a lock-wait state because of the online backup. Why is this happening? I had to kill the online backup to free up about six other processes that were blocked. Application handle = 508 Application ID ...
0
9546
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10268
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10247
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10031
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5593
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.