Answer the question
In order to leave comments, you need to log in
How to optimize a stored procedure?
When updating the online store, a temporary table is created, after entering the data into which, the stored procedure is executed:
DELIMITER $$
CREATE DEFINER=`root`@`%` PROCEDURE `sync_fl`()
BEGIN
DROP TABLE IF EXISTS `sh_prod_im__`;
ALTER TABLE `sh_prod_im` RENAME TO `sh_prod_im__`;
ALTER TABLE `sh_prod_im_` RENAME TO `sh_prod_im`;
END$$
DELIMITER ;
Answer the question
In order to leave comments, you need to log in
Transactions won't help here, because DROP TABLE/ALTER TABLE causes an immediate COMMIT.
It remains only to change the table update procedure itself. For example like this:
BEGIN TRANSACTION;
UPDATE `sh_prod_im` SET `updated` = 0;
INSERT
INTO `sh_prod_im` (`article`, ..., `updated`)
VALUES (:article, ..., 1)
ON DUPLICATE KEY UPDATE ..., `updated` = 1;
DELETE FROM `sh_prod_im` WHERE `updated` = 0;
COMMIT;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question