我目前正在 MySQL 上开发一个存储过程,我期望速度会略有提高。但是当我将它与通过 PHP 脚本执行 SQL 请求进行比较时,PHP 更快。使用 1000 行的表大约快 10 倍,使用 6000 行的表大约快 2 倍。
表大小是否改善了程序性能?我在我的代码中犯了错误,我可以优化它吗?
我的配置是 MySQL 5.0.10 上的 MyIsam 引擎。我的存储过程是
CREATE PROCEDURE get_task (IN var INT)
BEGIN
DECLARE id_task INT (11);
DECLARE job INT (11);
DECLARE state_name VARCHAR(20);
DECLARE task_name VARCHAR(20);
DECLARE worker_affected INT(11);
DECLARE user VARCHAR(10);
DECLARE progress INT(11);
DECLARE name VARCHAR(128);
DECLARE phone VARCHAR(128);
DECLARE mobile VARCHAR(128);
DECLARE site VARCHAR(32);
DECLARE worker_name VARCHAR(20);
DECLARE date_time_process_started DATETIME;
DECLARE frame INT(11);
DECLARE curseur1 CURSOR FOR
SELECT tq.`id_task`, tq.`job`, lts.`state_name`, ltt.`task_name`, tq.`worker_affected`, j.`user`, tq.`progress`, u.`name`, u.`phone`, u.`mobile`, u.`site`, w .`worker_name`, tq.`date_time_process_started`, tq.`frame`
FROM `task_queue` tq
LEFT JOIN `workers` w ON tq.`worker_affected` = w.`id_worker`
INNER JOIN `job` j ON tq.`job` = j.`job_id`
INNER JOIN `user` u ON j.`user` = u.`ipn`
INNER JOIN `list_task_type` ltt ON tq.`task_type` = ltt.`id_type_task`
INNER JOIN `list_task_state` lts ON tq.`task_state` = lts.`id_state`
WHERE tq.`id_task` = var
ORDER BY tq.`id_task`;
OPEN curseur1;
FETCH curseur1 INTO id_task, job, state_name, task_name, worker_affected, user, progress, name, phone, mobile, site, worker_name, date_time_process_started, frame;
SELECT id_task, job, state_name, task_name, worker_affected, user, progress, name, phone, mobile, site, worker_name, date_time_process_started, frame;
CLOSE curseur1;
END |