Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using EXPLAIN for MYSQL stored procedure calls

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() ?

like image 369
flyclassic Avatar asked Mar 22 '11 10:03

flyclassic


2 Answers

You can try

set profiling=1;
call proc_name();
show profiles;
like image 122
MiSTiX Avatar answered Sep 20 '22 04:09

MiSTiX


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

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);
like image 23
Jon Black Avatar answered Sep 19 '22 04:09

Jon Black