查看PostgreSQL数据库中SQL语句的执行计划
2017-03-09 19:05
507 查看
[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实际执行之后的数据.
相关文章推荐
- 怎么 查看数据库最近曾经执行过的SQL语句
- 查看当前数据库连接数是多少?查看当前正在执行的SQL语句?
- 详细查看数据库SQL执行计划
- 查看sql语句的执行计划
- ORACLE 查看有多个执行计划的SQL语句
- 查看sql语句的执行时间及缓存执行计划
- [转]使用mysql profiles 来查看sql 语句执行计划
- oracle中查看sql语句的执行计划
- pl/sql查看后台数据库执行语句
- 在oracle 数据库中查看一个sql语句的执行时间和SP2-0027错误
- PostgreSQL SQL的性能调试方法3--查看执行计划
- 如何在sqlplus中查看oracle数据库sql语句执行计划,执行时间和统计信息
- PostgreSQL环境中查看SQL执行计划示例
- 在oracle 数据库中查看一个sql语句的执行时间和SP2-0027错误
- Mysql利用profiles来查看sql 语句执行计划
- Oracle 如何根据动态性能视图来查看某条SQL语句的执行计划
- 优化SQL查询:如何写出高性能SQL语句1、首先要搞明白什么叫执行计划?执行计划是数据库根据SQL
- 使用mysql profiles 来查看sql 语句执行计划