Re: Deadlock problem when using SQL server
From: giespte (giespte_at_discussions.microsoft.com)
Date: 10/18/04
- Next message: tshad: "Re: Unable to add domain user"
- Previous message: Francois Allard: "SQL Server Assertion problem"
- In reply to: David Browne: "Re: Deadlock problem when using SQL server"
- Next in thread: David Gugick: "Re: Deadlock problem when using SQL server"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 18 Oct 2004 09:01:08 -0700
"David Browne" wrote:
>
> "giespte" <giespte@discussions.microsoft.com> wrote in message
> news:8F3D976F-A89A-46F3-8D1A-873948405241@microsoft.com...
> >I have a deadlock problem when using SQL server.
> >
> > It seems that the deadlock occurs when several threads udpate and then
> > query
> > different rows of the same table. I was able to reduce it to a simple
> > example:
> >
> > A table containing named counters:
> > The table has 2 columns:
> > name varchar( 100 )
> > value int( 4 )
> >
> > The table has a clustered primary key on the column 'name'.
> >
> > To get a unique counter value the following SQL statement (in a
> > transaction)
> > are executed:
> >
> > UPDATE counters SET value = value + 1 WHERE name = ?;
> > SELECT value FROM counters WHERE name = ?;
> >
>
> Are you wrapping these statements in an explicit transaction?
Yes.
>
> What is the index structure for the table?
The table has a clustered primary key on 'name', created with no additional
parameter. I suppose SQL Server uses a BTree as Default.
I remember that years ago, i had a performance problem with OpenIngres. A
hash Index improved the situation then. Is it possible to use hash indexes
with SQL Server ? Would they help in this situation ?
The Profiler logs a udpate key lock acquired and released for every row when
executing the update and a shared key lock acquired and released for every
row for the select. This looks like an index page scan to me.
Other locks ( Intended Update and Intended Share ) were set at table and
page level. The profiler skipped some log messages, so i have not been able
to analyze it in full detail, but it was lots of data to go through.
>
> Oracle and Sql Server are just different. In Oracle the statement
>
> SELECT value FROM counters WHERE name = ?;
>
> Generates no locks whatsoever, so I'm not sure you're going to get this to
> work without some customization for the different databases.
>
I know. That´s why i tried the nolock hint.
The thing that really surprised me was, that the deadlock occurred even
though the threads work on a separate data rows. There has to be some locking
at page or table level.
Thanks for the prompt reply.
Peter
> David
>
>
>
- Next message: tshad: "Re: Unable to add domain user"
- Previous message: Francois Allard: "SQL Server Assertion problem"
- In reply to: David Browne: "Re: Deadlock problem when using SQL server"
- Next in thread: David Gugick: "Re: Deadlock problem when using SQL server"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|