一、基本使用
samples=# \h explain
Command: EXPLAIN
Description: show the execution plan of a statement
Syntax:
EXPLAIN [ ( option [, ...] ) ] statement
EXPLAIN [ ANALYZE ] [ VERBOSE ] statement
where option can be one of:
ANALYZE [ boolean ]
VERBOSE [ boolean ]
COSTS [ boolean ]
BUFFERS [ boolean ]
TIMING [ boolean ]
FORMAT { TEXT | XML | JSON | YAML }
analyze:默认false,执行命令并显示实际运行时间和其他相关信息;
verbose:默认false,显示关于计划的额外信息(每个节点的输出列表、模式等等);
costs:默认true,显示每个计划节点的启动代价和总代价,估计的行数和每行平均宽度;
buffers:默认false,显示缓冲区共享块,本地块,临时块的使用信息,前提是开启analyze;
timing:默认true,显示实际启动时间和执行时间,前提是要开启analyze;
format:默认text,指定执行计划的输出格式;
二、执行计划结果解读