Java使用JDBC执行存储过程,但是速度慢,所以想检查数据库存储过程的执行计划,你怎么看?有几百行SQL存储过程,数据库是Mysql,我知道要检查select语句执行计划是要用explain的,但是存储过程怎么可以呢?
最佳答案
你可以使用mysql optimizer tracer如果您至少有 mysql v5.6.3。
基本用法:
SET optimizer_trace="enabled=on";
SELECT ...; # your query here
SELECT * FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE;
# possibly more queries...
# When done with tracing, disable it:
SET optimizer_trace="enabled=off";
它可以追踪following queries :
SELECT; INSERT or REPLACE (with VALUES or SELECT); UPDATE/DELETE and their multi-table variants; all the previous ones prefixed by EXPLAIN; SET (unless it manipulates the optimizer_trace system variable); DO; DECLARE/CASE/IF/RETURN (stored routines language elements); CALL. If one of those statements is prepared and executed in separate steps, preparation and execution are separately traced.
关于mysql - 如何查看mysql存储过程的执行计划?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37458477/