我正在从 PHP 页面调用存储过程。它工作正常。但是我使用了一个测试工具并尝试模拟多个请求。然后有时我会收到这样的回复:
"尝试获取锁时发现死锁;尝试重新启动事务"
这是存储过程:
DELIMITER $$
USE `mydb`$$
DROP PROCEDURE IF EXISTS `UserRegistration`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `UserRegistration`(IN `sfname` VARCHAR(200), IN `slname` VARCHAR(200), IN `semail` VARCHAR(200), IN `saddress` TEXT, IN `scity` VARCHAR(200), IN `sstate` VARCHAR(200), IN `szipcode` VARCHAR(20), IN `scountry` VARCHAR(200), IN `spin` VARCHAR(255), IN `sactivation_code` TEXT, IN `slcard_no` VARCHAR(20), IN `sgcm_regid` TEXT, OUT `rflag` INT)
BEGIN
DECLARE user_id INT DEFAULT 0;
SET rflag=0;
DELETE FROM user_device_details WHERE udd_user_id_fk IN (SELECT upd_user_id_pk FROM user_personal_details WHERE upd_email_id=semail);
DELETE FROM user_credit_card_details WHERE uccd_user_id_fk IN (SELECT upd_user_id_pk FROM user_personal_details WHERE upd_email_id=semail);
DELETE FROM user_photo_details WHERE upd_user_id_fk IN (SELECT upd_user_id_pk FROM user_personal_details WHERE upd_email_id=semail);
DELETE FROM transaction_history_details WHERE thd_user_id_fk IN (SELECT upd_user_id_pk FROM user_personal_details WHERE upd_email_id=semail);
DELETE FROM user_loyalty_card_details WHERE ulcd_user_id_fk IN (SELECT upd_user_id_pk FROM user_personal_details WHERE upd_email_id=semail);
DELETE FROM user_device_gcm_details WHERE udgd_user_id_fk IN (SELECT upd_user_id_pk FROM user_personal_details WHERE upd_email_id=semail);
DELETE FROM user_secure_details WHERE usd_user_id_fk IN (SELECT upd_user_id_pk FROM user_personal_details WHERE upd_email_id=semail);
DELETE FROM user_personal_details WHERE upd_email_id=semail;
SELECT upd_user_id_pk INTO user_id FROM user_personal_details WHERE upd_email_id=semail;
INSERT INTO user_personal_details(upd_first_name,upd_last_name,upd_email_id,upd_address,upd_city,upd_state,upd_zipcode,upd_country)VALUES(sfname,slname,semail,saddress,scity,sstate,szipcode,scountry);
SELECT LAST_INSERT_ID() INTO user_id;
INSERT INTO user_secure_details(usd_user_id_fk,usd_activation_code,usd_pin)VALUES(user_id,sactivation_code,spin);
INSERT INTO user_device_gcm_details(udgd_user_id_fk, udgd_gcm_regid)VALUES(user_id,sgcm_regid);
INSERT INTO user_loyalty_card_details(ulcd_card_no, ulcd_user_id_fk,ulcd_points)VALUES(slcard_no,user_id,'0.00');
SET rflag=user_id;
END$$
DELIMITER ;
建议我解决这个问题。