Dead lock problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Problem description as follow:

Table structure:


* CREATE TABLE `test` (*


*  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,*


*  `name` char(50) NOT NULL DEFAULT '',*


*  PRIMARY KEY (`id`),*


*  UNIQUE KEY `name` (`name`)*

*) ENGINE=InnoDB AUTO_INCREMENT=81 DEFAULT CHARSET=utf8*
*INSERT INTO tes (name) VALUES ('a'),('b');* //make sure  'a' and 'b'
already exists

Script t1.php:
*<?php*
*$db->begin_transaction();*

*$db->query("REPLACE INTO test (name) value ('a')");*
*sleep(5);//make sure script t2 while here*

*$db->query("REPLACE INTO test (name) value ('a')");*
*$db->commit();*

Script t2.php
*<?php*
*$db->begin_transaction();*
*$db->query("REPLACE INTO test (name) value ('b')");*
*$db->commit();*

If execute t2.php after t1.php,there will be a dead lock,
execute *SHOW ENGINE INNODB STATUS* show that dead lack happened on second
sql statment
I hnow mysql have range lock, i still wonder why the second sql statment in
script t1.php grant lock repeated?
Look forward a clear explanation.


-- 

Best Regards,
HaiwenZhu

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux