Using MySQL EXPLAIN to analyze the performance of a function
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 ?


Streamline Code Execution

Use SQL for all rows
Forcing SQL behavior over the Query Optimizer

Reduce Client/Server Traffic

Minimize Responses
Triggers

Divide/Conquer Complex Operations

Optimize Correlated Queries
Avoid Self Joins
Remove Unnecessary Statements from Loops
Use Controlled Break Statements (LEAVE or CONTINUE)
Good IF/CASE statements
Recursion
Cursors



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.