postgresql psql explain选项使用示例介绍

news/2024/7/9 21:36:24 标签: postgresql, psql, explain

postgresql__psql_explain_1">postgresql psql explain选项使用示例介绍

explain_3">explain

postgres=# explain select count(*) from pgbench_accounts ;
                                                   QUERY PLAN                                                    
-----------------------------------------------------------------------------------------------------------------
 Aggregate  (cost=2854.29..2854.30 rows=1 width=8)
   ->  Index Only Scan using pgbench_accounts_pkey on pgbench_accounts  (cost=0.29..2604.29 rows=100000 width=0)
(2 rows)

postgres=#

explain_analyze_14">explain analyze

postgres=# explain analyze select count(*) from pgbench_accounts ;
                                                                           QUERY PLAN                                                                            
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
 Aggregate  (cost=2854.29..2854.30 rows=1 width=8) (actual time=26.809..26.809 rows=1 loops=1)
   ->  Index Only Scan using pgbench_accounts_pkey on pgbench_accounts  (cost=0.29..2604.29 rows=100000 width=0) (actual time=0.033..14.879 rows=100000 loops=1)
         Heap Fetches: 0
 Planning time: 0.099 ms
 Execution time: 26.877 ms
(5 rows)

explain_analyzebuffers_27">explain (analyze,buffers)

联合使用analyze和buffers选项

注意:buffers必须跟analyze一起使用,只用真实执行SQL才能获取缓冲区信息),可通过实际执行SQL查看实际的代价和缓冲区命中的情况,

postgres=# explain (analyze,buffers) select count(*) from pgbench_accounts ;
                                                                           QUERY PLAN                                                                            
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
 Aggregate  (cost=2854.29..2854.30 rows=1 width=8) (actual time=28.387..28.387 rows=1 loops=1)
   Buffers: shared hit=276
   ->  Index Only Scan using pgbench_accounts_pkey on pgbench_accounts  (cost=0.29..2604.29 rows=100000 width=0) (actual time=0.019..14.825 rows=100000 loops=1)
         Heap Fetches: 0
         Buffers: shared hit=276
 Planning time: 0.129 ms
 Execution time: 28.438 ms
(7 rows)

postgres=# 

explain_analyzeverbosebufferscoststiming_47">explain (analyze,verbose,buffers,costs,timing)

postgres=# explain (analyze,verbose,buffers,costs,timing) select count(*) from pgbench_accounts ;
                                                                               QUERY PLAN                                                                               
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Aggregate  (cost=2854.29..2854.30 rows=1 width=8) (actual time=28.262..28.262 rows=1 loops=1)
   Output: count(*)
   Buffers: shared hit=276
   ->  Index Only Scan using pgbench_accounts_pkey on public.pgbench_accounts  (cost=0.29..2604.29 rows=100000 width=0) (actual time=0.019..14.475 rows=100000 loops=1)
         Output: aid
         Heap Fetches: 0
         Buffers: shared hit=276
 Planning time: 0.171 ms
 Execution time: 28.297 ms
(9 rows)

参考

1. explain (analyze,verbose,buffers,costs,timing) select
2. Postgresql explain的analyze和buffers选项


http://www.niftyadmin.cn/n/1187409.html

相关文章

ccflow_005.请假流程-傻瓜表单-审核组件模式

ccflow_005.请假流程-傻瓜表单-审核组件模式 用审核组件演示各个流程应用 首先设置节点,填写请假单的 表单方案。选择内置傻瓜表单。我们之前创建的表单就回来了。 可以点击下面的设计傻瓜表单来查看效果 这是我们之前就创建好的 当然也可以点击设计节点表单去查看…

PG数据库内核分析学习笔记_MultiXact日志管理器

PG数据库内核分析学习笔记_MultiXact日志管理器 MultiXact日志是PG系统用来记录组合事务ID的一种日志. 由于PG采用了多版本并发控制, 因此同一个元组相关的事务ID可能有多个, 为了在加锁(行共享锁)的时候统一操作, PG将与该元组相关联的多个事务ID组合起来用一个MultiXactID代…

关于js中属性那些事

1 //为object对象扩展create函数,指定继承对象 2 if (typeof Object.create ! function) { 3 Object.create function (o) { 4 var F function () { }; 5 F.prototype o; 6 return…

global 常用技巧介绍

global 常用技巧介绍 global -c xx 查找以"xx"为前缀的所有函数, 如果没"xx"参数, 那么会列出所有的函数. global -c 不支持正则表达式, 如果需要模糊查找, 可以和grep搭配使用 global -c |grep xx 或 global -c xx |grep xx global -x “完整函数名称”…

Flink学习笔记:Operators之Process Function

本文为《Flink大数据项目实战》学习笔记,想通过视频系统学习Flink这个最火爆的大数据计算框架的同学,推荐学习课程: Flink大数据项目实战:http://t.cn/EJtKhaz 1. Process Function 1.1分层API Flink提供三层API. 每个API在简洁性…

vim 常用技巧介绍

vim 常用技巧介绍 vim 指定范围内查找 参考: https://stackoverflow.com/questions/3264120/vim-search-only-between-specific-line-numbers 方法1 指定要搜索的起止行号, search为要搜索的pattern 如上图, 我们只想查找struct XLogRecord中包含"record"的行, …

利用python打开摄像头并保存

今天在学习python的时候偶然看到了一个打开摄像头的代码。该代码主要是导入了python里的cv库。代码很简单,以下为代码: lmport cv2 import numpy as np#添加模块和矩阵模块 capcv2.VideoCapture(0) #打开摄像头,若打开本地视频&am…

iis隐藏index.php

1.先安装微软的URL Rewrite模块 网址是https://www.iis.net/downloads/microsoft/url-rewrite#additionalDownloads 安装完成后iis会出现url重写模块 2.点击进去点击点击导入规则 3.填入 重写规则 &#xff0c;然后点击右侧“应用”提交&#xff1a; <IfModule mod_rewrite.…