Re: Informix vs. Sybase vs. Oracle vs. (gasp) MS SQL Server
Date: 1997/11/25
Message-ID: <347B239E.CF0485C6_at_strengur.is>#1/1
Pablo Sanchez wrote:
[Stuff deleted]
> 1) The ER diagram and
> 2) The business problem that we're solving
>
> There are *many* ways to solve an application so I'd love to
> see The Application (you claim) that:
>
> There are applications where anything other than row
> level locking simply won't do.
Ok. Here is an easy one. Only involves 2 tables (master and detail). This is of course very simlified and I have not checked the syntax :-)
CREATE TABLE master (id INT PRIMARY KEY, name VARCHAR(31), address VARCHAR(21), amount DECIMAL(16,4) );
CREATE INDEX x1 ON master (name);
CREATE INDEX x2 ON master (address);
CREATE TABLE detail (id INT REFERENCES master, line_no INT, item_no INT, descr VARCHAR(100), cost DECIMAL(10,4));
ALTER TABLE detail PRIMARY KEY(id, line_no);
- We need to lock the master table so nobody else will update it while we are.
SELECT * FROM master WHERE id = ? FOR UPDATE;
- No need to lock the detail recs 'cause the master rec is locked.
SELECT * FROM detail WHERE id = ? ORDER BY line_no;
UPDATE master SET amount = (SELECT sum(cost) FROM detail WHERE id = ?)
COMMIT; If you have row level locking, the first select stmt will lock one row. As the primary key is 4 bytes you can potentially put 4-500 keys on any page (if you have 2K pages). In a page lock system (like Sybase and MSSQL) the probability of a user trying to access one of the ~499 key values another user has locked is pretty high.
Page lock workarounds could be:
- Make the primary key >1Kb, so you would only have one key per page. (Disks are cheap, right?)
- Use optimistic locking. (So users who have been typing in for hours get the message: Somebody else has modified this rec while you were working. Please try again).
- Swich to Informix :-)
Take care,
-Snorri
-- Snorri Bergmann | Mail: snorri_at_strengur.is Strengur Consulting Engineers | WWW: http://www.strengur.is/ Armuli 7 | Phone: +354 550 9000 (9007 direct) 108 Reykjavik Iceland | Telefax: +354 550 9010Received on Tue Nov 25 1997 - 00:00:00 CET
