查看PostgreSQL数据库中SQL语句的执行计划

[postgres@rhel73 ~]$ psql
psql (9.6.0)
Type "help" for help.


postgres=# create table t(k serial primary key, v integer);
CREATE TABLE
postgres=#  insert into t(v) select trunc(random()*10) from generate_series(1,100000);
INSERT 0 100000
postgres=# explain analyze select count(*) from t;
                                                  QUERY PLAN                                                   
---------------------------------------------------------------------------------------------------------------
 Aggregate  (cost=1694.48..1694.49 rows=1 width=8) (actual time=17.810..17.811 rows=1 loops=1)
   ->  Seq Scan on t  (cost=0.00..1444.18 rows=100118 width=0) (actual time=0.025..10.825 rows=100000 loops=1)
 Planning time: 1.269 ms
 Execution time: 17.914 ms
(4 rows)


postgres=# explain analyze select * from t where k=1000;
                                                QUERY PLAN                                                
----------------------------------------------------------------------------------------------------------
 Index Scan using t_pkey on t  (cost=0.29..8.31 rows=1 width=8) (actual time=0.011..0.011 rows=1 loops=1)
   Index Cond: (k = 1000)----->>>此处是走索引的标志,类似于Oracle 执行计划中的"access"部分.
 Planning time: 0.368 ms
 Execution time: 0.042 ms
(4 rows)


postgres=# 


注意:
 (cost=0.29..8.31 rows=1 width=8)          ------->>>这是PG优化器预估的数据
 (actual time=0.011..0.011 rows=1 loops=1) ------->>>这是PG实际执行之后的数据.


  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值