473,902 Members | 3,601 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL 2000 - Row Level Locking

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

The applications reference the relevant category applicable to them
and update
the Value accordingly. This is table is very small, occupying 1 page.
However, it has no index as it was not seen to be appropriate for a
table this size.

However, can someone please advise whether

1. An index is required for row level locking
2. If an index on a table as small as above is likely to reduce the
deadlock rate.

Also, please consider the following but which I am not sure is
relevant for above query.

We noted that when we migrated the database concerned from SQL 6.5 to
SQL 2000, using DTS, that the database was NOT strictly in SQL 2000
format for non clustered indexes (NC) ie the clustered key was not
part of the NC index until the clustered index was rebuilt.

Given this should I just rebuild this table with a fake index and drop
it thereafter.

We are aware of the different techniques used to avoid deadlocks (eg
tables accessed in same order etc) and have , as much as possible,
implemented those practices.

I thank you in advance for any help you may be able to offer.

Thanks

Puvendran
Jul 20 '05
12 9587
Philip Yale (ph********@bto penworld.com) writes:
Not strictly true. The clustered index only directs the optimizer to
the *PAGE* on which the row is located, since the index node rows in a
clustered index only contain the first key value of the target page at
the leaf level. (This is not the same as a non-clustered index, which
would direct the search to the individual record).
Wait here. This may be true in Sybase, but the row locator in MS SQL
Server for a non-clustered index in a table with a clustered index is
the key value of the clustered index.

So I would assume that the index structure in MS SQL Server extends down
the page as well. The gory details of this are described in Kalen Delaney's
"Inside SQL Server 2000", although I have to admit that I have not
read that chapter myself.
Thus, with a clustered index seek you will still have to read all rows
on the target page to find those which match / don't match. Because of
this, I still maintain that the clustered index lookup is more expensive
than a single-page tablescan, even with row-level locking, since you
have to read both the index node page and the entire leaf page (at least
2 logical reads), as opposed to just a single logical read by scanning
the 1-page table.


Maybe it is more expensive for the individual query, but not for overall
performance.
Exactly how the optimizer avoids this pitfall, I don't know, but it
may be as simple that the optimizer stops looking for plans once
it has found one which is good enough.


This isn't (shouldn't be) the way optimizers work. They consider ALL
possible plans, then slect the "cheapest".


No, that's not the way an optimizer should work! Because for a complex
query with 12 tables, the optimizer could spend minutes to determine
which of a several sub-second plans to use.
--
Erland Sommarskog, SQL Server MVP, so****@algonet. se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #11
Erland Sommarskog <so****@algonet .se> wrote in message news:<Xn******* **************@ 127.0.0.1>...
Philip Yale (ph********@bto penworld.com) writes:
Not strictly true. The clustered index only directs the optimizer to
the *PAGE* on which the row is located, since the index node rows in a
clustered index only contain the first key value of the target page at
the leaf level. (This is not the same as a non-clustered index, which
would direct the search to the individual record).
Wait here. This may be true in Sybase, but the row locator in MS SQL
Server for a non-clustered index in a table with a clustered index is
the key value of the clustered index.

So I would assume that the index structure in MS SQL Server extends down
the page as well. The gory details of this are described in Kalen Delaney's
"Inside SQL Server 2000", although I have to admit that I have not
read that chapter myself.
Thus, with a clustered index seek you will still have to read all rows
on the target page to find those which match / don't match. Because of
this, I still maintain that the clustered index lookup is more expensive
than a single-page tablescan, even with row-level locking, since you
have to read both the index node page and the entire leaf page (at least
2 logical reads), as opposed to just a single logical read by scanning
the 1-page table.


Maybe it is more expensive for the individual query, but not for overall
performance.
Exactly how the optimizer avoids this pitfall, I don't know, but it
may be as simple that the optimizer stops looking for plans once
it has found one which is good enough.


This isn't (shouldn't be) the way optimizers work. They consider ALL
possible plans, then slect the "cheapest".


No, that's not the way an optimizer should work! Because for a complex
query with 12 tables, the optimizer could spend minutes to determine
which of a several sub-second plans to use.

Wait here. This may be true in Sybase, but the row locator in MS SQL
Server for a non-clustered index in a table with a clustered index is
the key value of the clustered index.

So I would assume that the index structure in MS SQL Server extends down
the page as well. The gory details of this are described in Kalen Delaney's
"Inside SQL Server 2000", although I have to admit that I have not
read that chapter myself.
In our discussion, though, we aren't considering NC indexes, just
clustered. My description of clustered index access is almost a
verbatim quote of the "gory details" in Kalen's book, where she states
explicitly that a clustered index seek only gets as far as the first
record in a data page, not the individual records within that page
(page 420, section headed Nonclustered Index Leaf Rows).
No, that's not the way an optimizer should work! Because for a complex
query with 12 tables, the optimizer could spend minutes to determine
which of a several sub-second plans to use.


For a complex query with 12 joins I would agree with you entirely, and
I believe that that is what it does do (for queries exceeding 4 tables
in the join). However, that's not what we are considering here, so
when I said that it should consider ALL joins, I meant it! :-)

I think we're probably reaching the point of diminishing returns in
this discussion now, and that we broadly agree on the explanation -
the single-page example is a special case where the optimizer doesn't
necessarily take the theoretically most efficient path, but since the
overhead is negligible who cares? The approach taken gets
progressively more efficient as table size increases.

My initial surprise at this stems from the fact that Sybase would NOT
choose to use an index (of any sort) over a table scan of a singlepage
table. Since I've moved from Sybase into the SQLServer arena, I'm
still on a learning curve about the intricacies of the SQLServer
optimizer; the temptation is very great to apply many years of Sybase
P&T experience to similar scenarios in SQLServer, but I've quickly
discovered that this simply won't work! Despite their shared history,
they're now two very different animals.

Thanks for the discussion, though - it's good to be forced to think
these things through more fully.
Jul 20 '05 #12
Philip Yale (ph********@bto penworld.com) writes:
In our discussion, though, we aren't considering NC indexes, just
clustered. My description of clustered index access is almost a
verbatim quote of the "gory details" in Kalen's book, where she states
explicitly that a clustered index seek only gets as far as the first
record in a data page, not the individual records within that page
(page 420, section headed Nonclustered Index Leaf Rows).
OK, if Kalen says so, it is so. I still suppose it has some smart way to
avoid the keys that are looked.
For a complex query with 12 joins I would agree with you entirely, and
I believe that that is what it does do (for queries exceeding 4 tables
in the join). However, that's not what we are considering here, so
when I said that it should consider ALL joins, I meant it! :-)


That four-table thing is also an oldie. In SQL 6.5, as well as in older
Sybase versions, SQL Server would only consider groups of four, so if
you had

SELECT * FROM a, b, c, d, e WHERE ...

the optimizer would examine all iterations of abcd and bcde.

But this is not true anymore.
--
Erland Sommarskog, SQL Server MVP, so****@algonet. se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #13

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

Similar topics

1
5459
by: Arska | last post by:
Hi Is it possible to force row level locking in one or more tables in some database. We have some problems when SQL Server decides to choose page- or table-level locking. We are using SQL Server 2000. Best regards Aarno
1
4051
by: Fardude | last post by:
ACCESS 97, Pessimistic Record Locking!??? Does Access 97 allow record level Pessimistic locking? In other words, when user A is editing a record (has it locked) and User B tries to edit it (attempts to lock it), user B will get an error saying this record cannot be locked now. It seems like Access 97 is doing optimistic record level locking. In above scenario user B, is allowed to edit the record but when tries to
0
1280
by: Deano | last post by:
I use the Access 2000 MSI Wizard from Sagekey and they don't know if the bug documented on page 32 of the Access 2000 Developer`s Handbook Volume 2: Enterprise Edition still affects the runtime. Apparently page locking is invoked when using the Access run-time record than record-level locking. This also affects Access 2000 but if you patch Access the bug is fixed. I really don't know about the runtime though. Does anyone know if...
2
2224
by: Deano | last post by:
I use the Access 2000 MSI Wizard from Sagekey and they don't know if the bug documented on page 32 of the Access 2000 Developer`s Handbook Volume 2: Enterprise Edition still affects the runtime. Apparently page locking is invoked when using the Access run-time record than record-level locking. This also affects Access 2000 but if you patch Access the bug is fixed. I really don't know about the runtime though. Does anyone know if...
2
3149
by: Peter | last post by:
(I've tried this Q in the ms forums without response. See how it goes here.) Using A2003 but I guess this is not version-specific... If I want to implement row/record level locking on a split database where do I need to set this option. Is it sufficient to set it in the frontend database for record-level locking to apply to the backend tables. Or must I also set it in the backend mdb database instead or as well (which is never...
1
1681
by: jv | last post by:
Hello, I'm using A2K and am trying to make sure that my program only locks one record at a time and I don't seem to have any luck getting that to happen. In the database options, I've selected "Open Database Using Record-Level Locking" and the default record lock setting is "Edited Record". My forms' record lock setting is also "Edited Record". With the above settings, I get page-level locking. Can pessimistic
13
2703
by: Owen Jenkins | last post by:
Following on from an earlier post... I can reliably corrupt a record by doing the following ... Open two separate but identical front ends on one PC each linking to the same back end. Edit a records in one front end and leave it unsaved. Edit the same record in the other front end and save the change. Save the change in the first front end - this pops up the Write Conflict message to which I click Save.
11
3509
ollyb303
by: ollyb303 | last post by:
Hi, I have a problem with a multi-user db in Access 2000. The db is for logging calls to my company and will be used by up to 30 people, though currently around 10 are using it. I have split the db into front/back end and each user is using a local copy of the front end, connected to the back end via our network. It was all working fine when we tested it (across 2 different sites) and had no problems, but now, some new users are...
1
2232
by: Paul H | last post by:
I have an Employees table with the following fields: EmployeeID SupervisorID Fred Bob Bob John Bob Mary Bill Bill I have created a self join in the relationships window, with
0
9997
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9845
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
10866
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
10978
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,...
1
8045
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7204
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
5892
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...
1
4724
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 we have to send another system
2
4305
muto222
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.