Subject RE: [firebird-support] Deadlock Simplified
Author Nigel Weeks
Yep - shorter transactions.

This is especially prevalent in high-traffic PHP web-apps.
If you use a single transaction for all queries on a page, it's one
transaction open until the entire page is finished being created.
If you then do updates during this big transaction, they're locked until the
end of the page.

Alternatively, start a transaction exclusively for and updates/inserts when
they occur, then commit them straight after they're done.
That way, you can still keep the big transaction open for the whole page,
with little baby transactions for the updates.

For example:

<?php
$conn = ibase_connect("server:/path/to/database.fdb","sysdba","masterkey");
// A big query for the page
$sql = "select * from some table";
$rec = ibase_query($sql);
while($obj = ibase_fetch_object($rec)){

// Do some operations, echo out some objects
// This loop contains a few situations where an update needs to happen,
but this pages takes 2 seconds to produce
// Start another transaction just for the update
$tr = ibase_trans();
$updsql = "update some_table set some_field = 1 where som_condition =
'some_value' ";
$updrec = ibase_query($tr,$updsql);
// Now, commit this little transaction to prevent deadlocks
ibase_commit($tr);


}

?>

Nige.

Nigel Weeks
Tech Support & Systems Developer
Rural Press Tasmania
The Examiner Newspaper
71-75 Paterson St
Launceston Tas 7250
Ph. 03 6336 7234
Mob. 0408 133 738

IMPORTANT NOTICE - The contents of this e-mail may be confidential and is
intended only for the individual(s) or entity(s) named herein. Any
unauthorised use of the contents is expressly prohibited. If you have
received the e-mail in error, please contact the sender by telephone
immediately and then delete the e-mail. We cannot guarantee that this
e-mail, attachments or Internet links are free of computer viruses that may
damage or interfere with data, hardware or software or contains material
that may contravene local, national or International laws. Opening of this
e-mail is acceptance on the part of the recipient(s) that he or she accepts
full responsibility for protecting their computer and associated software
and systems from any such viruses and materials and absolves Rural Press
Ltd.

-----Original Message-----
From: firebird-support@yahoogroups.com
[mailto:firebird-support@yahoogroups.com]On Behalf Of Stephen Davey
Sent: Friday, 17 November 2006 10:41 AM
To: firebird-support@yahoogroups.com
Subject: [firebird-support] Deadlock Simplified



Is there a quick and simple solution to deadlocks ?

I realise that the deadlock error message covers a range of sins.

Is the classic server less likely than superserver to encounter issues ?

[Non-text portions of this message have been removed]






[Non-text portions of this message have been removed]