从数据上来看已经回滚完成了,数据都是未执行前的状态,SHOW INNODB STATUS的信息是这样的,能解释下吗: ------------ TRANSACTIONS ------------ Trx id counter 0 1593853 Purge done for trx's n:o < 0 1593846 undo n:o < 0 0 History list length 7 LIST OF TRANSACTIONS FOR EACH SESSION: ---TRANSACTION 0 0, not started, OS thread id 3968 MySQL thread id 191, query id 3892 localhost 127.0.0.1 root show innodb status ---TRANSACTION 0 1593852, not started, OS thread id 3332 MySQL thread id 4, query id 3889 localhost 127.0.0.1 root ---TRANSACTION 0 0, not started, OS thread id 3268 MySQL thread id 2, query id 3655 localhost 127.0.0.1 root ---TRANSACTION 0 1593847, ACTIVE 18 sec, OS thread id 3384 15 lock struct(s), heap size 2496, 482 row lock(s), undo log entries 236 MySQL thread id 181, query id 3662 localhost 127.0.0.1 root Trx read view will not see trx with id >= 0 1593848, sees < 0 1593848
我刚才又测试了一下,SP里面只有一个INSERT语句,用START transaction;COMMIT嵌套住以后,故意加一个错误的语句在里面,数据回滚了,但是进程还在,表依然是被锁了,怎么会这样的;付我的测试语句:START TRANSACTION;INSERT INTO `nodes_hierarchy`( `name`, `parent_id`, `node_type_id`, `node_order` )SELECT `Name`, NULL, 2, `ID` FROM temptable20110421t1736561303378616068 WHERE Type = 'S' ORDER BY `ID`;a;COMMIT
参照下面这样的事务写法 create PROCEDURE aa(SqlCMD1 varchar(8000),SqlCMD2 varchar(8000),SqlCMD3 varchar(8000)) begin declare exit handler for sqlexception rollback; start TRANSACTION;
PREPARE stmt_name FROM SqlCMD1; EXECUTE stmt_name; DEALLOCATE stmt_name; PREPARE stmt_name FROM SqlCMD2; EXECUTE stmt_name; DEALLOCATE stmt_name; PREPARE stmt_name FROM SqlCMD3; EXECUTE stmt_name; DEALLOCATE stmt_name; COMMIT; end
------------
TRANSACTIONS
------------
Trx id counter 0 1593853
Purge done for trx's n:o < 0 1593846 undo n:o < 0 0
History list length 7
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 0 0, not started, OS thread id 3968
MySQL thread id 191, query id 3892 localhost 127.0.0.1 root
show innodb status
---TRANSACTION 0 1593852, not started, OS thread id 3332
MySQL thread id 4, query id 3889 localhost 127.0.0.1 root
---TRANSACTION 0 0, not started, OS thread id 3268
MySQL thread id 2, query id 3655 localhost 127.0.0.1 root
---TRANSACTION 0 1593847, ACTIVE 18 sec, OS thread id 3384
15 lock struct(s), heap size 2496, 482 row lock(s), undo log entries 236
MySQL thread id 181, query id 3662 localhost 127.0.0.1 root
Trx read view will not see trx with id >= 0 1593848, sees < 0 1593848
`name`,
`parent_id`,
`node_type_id`,
`node_order`
)SELECT
`Name`,
NULL,
2,
`ID`
FROM
temptable20110421t1736561303378616068
WHERE
Type = 'S'
ORDER BY
`ID`;a;COMMIT
create PROCEDURE aa(SqlCMD1 varchar(8000),SqlCMD2 varchar(8000),SqlCMD3 varchar(8000))
begin
declare exit handler for sqlexception rollback;
start TRANSACTION;
PREPARE stmt_name FROM SqlCMD1;
EXECUTE stmt_name;
DEALLOCATE stmt_name;
PREPARE stmt_name FROM SqlCMD2;
EXECUTE stmt_name;
DEALLOCATE stmt_name;
PREPARE stmt_name FROM SqlCMD3;
EXECUTE stmt_name;
DEALLOCATE stmt_name;
COMMIT;
end