Your procedure "proceso()" checks all rows for "map_index=0" on every update. Since map_index isn't (by default) an index or a primary key, this can take very long.Quote:
Really this it's a good system, only uploads map_index=0 where is insert any date, no update, for this reason the speed of DB musn't be delayed (excuse for my english)
I would suggest to pass the id of the updated player to the procedure. The procedure then can process just the right row without reading all rows.
Code:
DELIMITER $$ DROP TRIGGER IF EXISTS espera $$ CREATE TRIGGER espera AFTER UPDATE ON player_index FOR EACH ROW begin IF NEW.map_index = 0 THEN CALL proceso(NEW.id, NEW.account_id); END IF; end $$ DELIMITER ;
Code:
delimiter $$
DROP PROCEDURE IF EXISTS `proceso` $$
CREATE PROCEDURE `proceso`(p_id INT, a_id INT)
begin
declare p_empire integer;
SELECT empire INTO p_empire FROM player_index WHERE id = a_id LIMIT 1;
IF p_empire = 1 THEN
UPDATE player SET x=1111, y=1111, map_index=1 where id = p_id;
ELSEIF p_empire = 2 THEN
UPDATE player SET x=2222, y=2222, map_index=2 where id = p_id;
ELSEIF p_empire = 3 THEN
UPDATE player SET x=3333, y=3333, map_index=3 WHERE id = p_id;
END IF;
end $$
delimiter ;