Answer the question
In order to leave comments, you need to log in
How to optimize a MySQL procedure?
There is MariaDB 10.3 and something like this MySQL procedure:
BEGIN
DECLARE done INT DEFAULT 0;
DECLARE v_id, v_user_id, v_created INT;
DECLARE cur1 CURSOR FOR SELECT `id`, `user_id`, `created` FROM `table` WHERE `update` = 0 ORDER BY `id` DESC;
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
UPDATE `table` SET `update` = 0 WHERE 1;
OPEN cur1;
WHILE done = 0 DO
FETCH cur1 INTO v_id, user_id, v_created;
IF done = 0 THEN
// Несколько различных SQL заросов (INSERT IGNORE, INSER UPDATE, UPDATE, SELECT)
UPDATE `table` SET `update` = 1 WHERE `id` = v_id LIMIT 1;
END IF;
END WHILE;
CLOSE cur1;
END
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question