Skip to content

在线,https://explain.depesz.com/

8,explain

1、Explain

explain select * from tablename;

2、explain输出josn格式

explain (format json) select * from tablename;

除了json格式,还支持xml、text、yaml等

3、explain analyze查看实际的启动时间

explain analyze select * from tablelname;

另一种方法:

explain(analyze true) select * from tablename;

4、explain 只看执行的路径情况,不看cost值

explain(costs false) select * from tablename;

5、通过实际执行查看实际的代价和缓冲区命中的情况

explain (analyze true,buffers true) select * from tablename;

SQL优化

postgres@postgres=>show wal_sync_method;

 wal_sync_method 
-----------------

 fdatasync
(1 row)
postgres@postgres=>show wal_sync_method;

 wal_sync_method 
-----------------

 fdatasync
(1 row)

1,explain

explain 和 explain analyze 的方式来,其中的区别是前者是评估,后者是实际执行计划

https://explain.depesz.com/

http://tatiyants.com/pev/#/plans/new

Fiter 指应用限定条件进行记录过滤;

Seq Scan 指表扫描,也即全表扫描;

Group Key 指分组查询的分组键值;

GroupAggregate 指分组聚合结果;

https://www.modb.pro/doc/688

https://zhuanlan.zhihu.com/p/197568601

https://blog.csdn.net/weixin_33943347/article/details/90617718?utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2~all~first_rank_v2~rank_v25-7-90617718.nonecase&utm_term=pgsql%E6%95%B0%E6%8D%AE%E5%BA%93%E8%A1%A8%E7%BB%93%E6%9E%84%E5%A4%87%E4%BB%BD