You can precede a
SELECT statement in MySQL with
EXPLAIN, but how would you explain a function? I have a function that does a lot of work and I would like to analyze the performance of the function as a whole.
migrated from serverfault.com Feb 5 '13 at 17:01
This question came from our site for system and network administrators.
EXPLAIN was meant to do queries, not functions or procedures.
When it comes to procedural code, you must think like a developer all over again. For what purposes would you optimize code, especially for a database ?
It is no longer a case of EXPLAIN a query. If you can EXPLAIN the procedure, you can code. Obviously, if you can EXPLAIN a procedure faster, you can produce faster code.
It depends on what you want to do.
If you want an execution plan, you'll have to EXPLAIN each of the queries inside the function individually. MySQL doesn't have a feature that will do this for you.
If you just want to measure the execution time but the function runs too fast to meaningfully measure then you can use the BENCHMARK() function to repeatedly call the function. Then you can make changes to the function and run BENCHMARK() again and compare the results.