执行计划常用参数简析

1、ANALYZE
真正执行实际的SQL,看到执行计划每一步时间
2、VERBOSE
用于显式计划的附加信息,附加信息:计划树中每个节点输出的各个列。触发器被出发还会显示出发器的名称。默认为FALSE。
3、COSTS
每个计划节点的启动成本和总成本、行数、每行宽度。Costs 默认为TRUE
4、BUFFERS
缓冲区使用的信息,只能与anaylyze参数一起使用,共享块、本地块、临时块(读和写)。共享块、本地块和临时块分别包含表和索引、临时表和临时索引。默认false
5、FORMAT
指定输出格式 (text\xml\json\yaml) 默认为text

highgo=# explain (analyze,buffers,format xml)select profession from test where id = 25;
                         QUERY PLAN                          
-------------------------------------------------------------
 <explain xmlns="http://www.postgresql.org/2009/explain">   +
   <Query>                                                  +
     <Plan>                                                 +
       <Node-Type>Seq ScanNode-Type>                      +
       <Relation-Name>testRelation-Name>                  +
       <Alias>testAlias>                                  +
       <Startup-Cost>0.00Startup-Cost>                    +
       <Total-Cost>19.56Total-Cost>                       +
       <Plan-Rows>1Plan-Rows>                             +
       <Plan-Width>12Plan-Width>                          +
       <Actual-Startup-Time>0.007Actual-Startup-Time>     +
       <Actual-Total-Time>0.096Actual-Total-Time>         +
       <Actual-Rows>1Actual-Rows>                         +
       <Actual-Loops>1Actual-Loops>                       +
       <Filter>(id = 25)Filter>                           +
       <Rows-Removed-by-Filter>1004Rows-Removed-by-Filter>+
       <Shared-Hit-Blocks>7Shared-Hit-Blocks>             +
       <Shared-Read-Blocks>0Shared-Read-Blocks>           +
       <Shared-Dirtied-Blocks>0Shared-Dirtied-Blocks>     +
       <Shared-Written-Blocks>0Shared-Written-Blocks>     +
       <Local-Hit-Blocks>0Local-Hit-Blocks>               +
       <Local-Read-Blocks>0Local-Read-Blocks>             +
       <Local-Dirtied-Blocks>0Local-Dirtied-Blocks>       +
       <Local-Written-Blocks>0Local-Written-Blocks>       +
       <Temp-Read-Blocks>0Temp-Read-Blocks>               +
       <Temp-Written-Blocks>0Temp-Written-Blocks>         +
     Plan>                                                +
     <Planning-Time>0.036Planning-Time>                   +
     <Triggers>                                             +
     Triggers>                                            +
     <Execution-Time>0.109Execution-Time>                 +
   Query>                                                 +
 explain>
(1 row)

如果不想修改数据,可以将explain analyze放到一个事务中,执行完后回滚。

highgo=# begin;
BEGIN
highgo=# explain analyze insert into test values (2,'张三','qwer');
                                          QUERY PLAN                                          
----------------------------------------------------------------------------------------------
 Insert on test  (cost=0.00..0.01 rows=1 width=0) (actual time=12.475..12.475 rows=0 loops=1)
   ->  Result  (cost=0.00..0.01 rows=1 width=0) (actual time=0.001..0.002 rows=1 loops=1)
 Planning time: 0.132 ms
 Execution time: 116.692 ms
(4 rows)

highgo=# rollback;
ROLLBACK

BY 海无涯

你可能感兴趣的:(Highgo,DB)