查看PostgreSQL数据库中SQL语句的执行计划
发布时间:2020-12-13 16:57:24 所属栏目:百科 来源:网络整理
导读:[postgres@rhel73 ~]$ psqlpsql (9.6.0)Type "help" for help.postgres=# create table t(k serial primary key,v integer);CREATE TABLEpostgres=# insert into t(v) select trunc(random()*10) from generate_series(1,100000);INSERT 0 100000postgres=#
[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实际执行之后的数据. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
