使用EXPLAIN进行MYSQL存储过程调用

时间:2011-03-22 10:08:19

标签: mysql stored-procedures

如何分析和使用EXPLAIN进行存储过程调用? 我需要优化查询时间,但似乎没有我可以在哪里做一个EXPLAIN调用proc_name()?

3 个答案:

答案 0 :(得分:20)

你可以尝试

set profiling=1;
call proc_name();
show profiles;

答案 1 :(得分:9)

目前你无法解释mysql中的存储过程 - 但是你可以这样做:

drop procedure if exists get_user;
delimiter #
create procedure get_user
(
in p_user_id int unsigned,
in p_explain tinyint unsigned
)
begin
  if (p_explain) then
    explain select * from users where user_id = p_user_id;
  end if;
  select * from users where user_id = p_user_id;
end#

delimiter ;

call get_user(1,1);

答案 2 :(得分:3)

EXPLAIN仅适用于SELECT语句,除非使用EXPLAIN tablename,它是DESCRIBE tablename的别名

相关问题