PostgreSQL DBA(70) - PG 12 Add SETTINGS option to EXPLAIN

PostgreSQL 12为explain命令提供了settings选项,可查看影响执行计划的设置修改.

测试数据:


testdb=# drop table if exists t_settings;
NOTICE:  table "t_settings" does not exist, skipping
DROP TABLE
testdb=# create table t_settings(id int,c1 varchar(20));
CREATE TABLE
testdb=# 
testdb=# insert into t_settings select x,'c1'||x from generate_series(1,100000) as x;
INSERT 0 100000
testdb=# create index idx_t_settings_id on t_settings(id);
CREATE INDEX

PG 11


testdb=# explain (settings on) select * from t_settings where id = 1;
ERROR:  unrecognized EXPLAIN option "settings"
LINE 1: explain (settings on) select * from t_settings where id = 1;
                 ^

PG 11不支持该特性.

PG 12
PG 12新增了该特性


[local]:5432 pg12@testdb=# explain (settings on) select * from t_settings where id = 1;
                                    QUERY PLAN                                     
-----------------------------------------------------------------------------------
 Bitmap Heap Scan on t_settings  (cost=12.17..570.66 rows=500 width=62)
   Recheck Cond: (id = 1)
   ->  Bitmap Index Scan on idx_t_settings_id  (cost=0.00..12.04 rows=500 width=0)
         Index Cond: (id = 1)
(4 rows)
Time: 5.403 ms

修改参数,查看执行计划


[local]:5432 pg12@testdb=# set enable_indexscan=off;
SET
Time: 0.555 ms
[local]:5432 pg12@testdb=# explain (settings on) select * from t_settings where id = 1;
                                   QUERY PLAN                                   
--------------------------------------------------------------------------------
 Bitmap Heap Scan on t_settings  (cost=4.30..8.31 rows=1 width=11)
   Recheck Cond: (id = 1)
   ->  Bitmap Index Scan on idx_t_settings_id  (cost=0.00..4.30 rows=1 width=0)
         Index Cond: (id = 1)
 Settings: enable_indexscan = 'off'
(5 rows)
Time: 0.759 ms

注意执行计划中的” Settings: enable_indexscan = ‘off’ “,把影响执行计划的参数修改打印出来,这是一个pretty cool特性,增强了易用性.

参考资料
Waiting for PostgreSQL 12 – Add SETTINGS option to EXPLAIN, to print modified settings

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/6906/viewspace-2652910/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/6906/viewspace-2652910/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值