postgres explain查看sql执行计划参考

EXPLAIN [ ( option [, ...] ) ] statement
EXPLAIN [ ANALYZE ] [ VERBOSE ] statement
explain 后面可以跟的选型有:
ANALYZE [ boolean ] -- 执行statement, 得到真实的运行时间以及统计信息.
VERBOSE [ boolean ] -- 输出详细信息, 如列,schema,trigger等信息. 默认关闭.
COSTS [ boolean ] -- 输出根据成本因子计算得出的cost值, 默认打开.(分为该节点输出第一行前的成本以及输出所有行的成本.)
BUFFERS [ boolean ] -- 输出本次QUERY shared/local/TEMP blocks的信息. The number of shared blocks hit, read, dirtied, and written, the
number of local blocks hit, read, dirtied, and written, and the number of temp blocks read and written.
包括命中/未命中读数据块, 产生的脏数据块, 写出了多少QUERY开始前的脏数据块. (需打开analyze, TEXT模
式只输出非0项, "计数包含所有子节点的计数".)
TIMING [ boolean ] -- 输出每个节点的真实的时间开销, 总时间不包含网络开销,parser,rewriter,planer开销, (需打开analyze)
FORMAT { TEXT | XML | JSON | YAML } -- 输出格式, 默认TEXT.
注意:对于analyze的使用, 会真的执行被评估的SQL, 如果是执行DML, 可以放在事务中使用并回滚事务:
BEGIN;
EXPLAIN ANALYZE QUERY;
ROLLBACK;

FORMAT { TEXT | XML | JSON | YAML } -- 输出格式, 默认TEXT.
explain (analyze,verbose,buffers,costs,timing) select id1 from t_info10 where id1<10;
explain (analyze,verbose,buffers,costs,timing,format json) select id1 from t_info10 where id1<10;

猜你喜欢

转载自blog.51cto.com/1937519/2374009