各位大侠,遇到一个面试题,求助~假设有一个perl程序会去update一个表的两列。
A进程执行了这个程序,过程如下:update x -> update y -> commit
B进程执行了这个程序,过程如下:update y -> update x -> commit
于是便有可能发生死锁问题是要给出三种以上防止的方法。我只知道,在得到行x和y的时候使用select for update,请问还有什么其他的方法?谢啦!
mysqlperl死锁

解决方案 »

  1.   

    LOCK TABLES trans READ, customer WRITE;
    ....
    UNLOCK TABLES;START TRANSACTION;
    SELECT @A:=SUM(salary) FROM table1 WHERE type=1;
    UPDATE table2 SET summary=@A WHERE type=1;
    COMMIT;declare exit handler for sqlexception rollback; 
          declare exit handler for sqlwarning rollback; 
     
          START TRANSACTION; 
          insert into table1(a,b,c,d) values(var1,var2,var3,var4); 
          insert into table2(e,f,g) values(var5,var6,string1); 
          COMMIT;