[翻译]  using EXPLAIN for MYSQL stored procedure calls

[CHINESE]  使用EXPLAIN进行MYSQL存储过程调用


How do analyse and use EXPLAIN for my stored procedure calls ? I need to optimize the query time, however seems like there is no where i can do a EXPLAIN call proc_name() ?

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

3 个解决方案

#1


16  

You can try

你可以试试

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

#2


9  

at present you can't explain stored procedures in mysql - but you could do something like this:

目前你无法解释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);

#3


4  

EXPLAIN works only on SELECT statements, except when you use EXPLAIN tablename which is an alias of DESCRIBE tablename

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


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
© 2014-2018 ITdaan.com 粤ICP备14056181号