openGauss插件使用指南:gms_stats Extension

gms_stats概述

gms_stats是一个基于openGauss的插件,用于良好地估计统计数据(尤其是针对较大的分区表),并能获得更好的统计结果,最终制定出速度更快的SQL执行计划。目前支持的接口有:GATHER_SCHEMA_STATS(用于收集某个schame下对象的统计信息)。

gms_stats限制

  • 仅支持Create extension命令方式加载插件。

gms_stats安装

openGauss打包编译时默认已经包含了gms_stats, 可以在安装完openGauss后,直接通过create extension gms_stats;加载插件。

gms_stats使用

创建Extension

创建gms_stats Extension可直接使用CREATE Extension命令进行创建:

openGauss=# CREATE Extension gms_stats;

使用Extension

创建用于测试的schema,table和materialized view.

openGauss=# create schema gms_stats_test;
CREATE SCHEMA
openGauss=# set search_path=gms_stats_test;
SET
openGauss=# create table normal_table(a int, b char(10));
CREATE TABLE
openGauss=# insert into normal_table select generate_series(1,500), 'abc';
INSERT 0 500
openGauss=# 
openGauss=# create table partition_table(a int) partition by range(a) (partition p1 values less than(100),partition p2 values less than(maxvalue));
CREATE TABLE
openGauss=# insert into partition_table select generate_series(1,600);
INSERT 0 600
openGauss=# 
openGauss=# create materialized view mv_tb as select * from normal_table;
CREATE MATERIALIZED VIEW
openGauss=# 
openGauss=# select schemaname, tablename, attname, avg_width, most_common_vals, most_common_freqs from pg_stats where schemaname='gms_stats_test' order by tablename, attname;
 schemaname | tablename | attname | avg_width | most_common_vals | most_common_freqs 
------------+-----------+---------+-----------+------------------+-------------------
(0 rows)

查询结果

openGauss=# begin
openGauss$# gms_stats.gather_schema_stats('gms_stats_test');
openGauss$# end;
openGauss$# /
NOTICE:  PL/SQL procedure successfully completed.
CONTEXT:  SQL statement "CALL gms_stats.gather_schema_stats('gms_stats_test')"
PL/pgSQL function inline_code_block line 2 at PERFORM
ANONYMOUS BLOCK EXECUTE
openGauss=# select schemaname, tablename, attname, avg_width, most_common_vals, most_common_freqs from pg_stats where schemaname='gms_stats_test' order by tablename, attname;
   schemaname   |    tablename    | attname | avg_width | most_common_vals | most_common_freqs 
----------------+-----------------+---------+-----------+------------------+-------------------
 gms_stats_test | mv_tb           | a       |         4 |                  | 
 gms_stats_test | mv_tb           | b       |        11 | {"abc       "}   | {1}
 gms_stats_test | normal_table    | a       |         4 |                  | 
 gms_stats_test | normal_table    | b       |        11 | {"abc       "}   | {1}
 gms_stats_test | partition_table | a       |         4 |                  | 
(5 rows)

删除Extension

在openGauss中删除gms_stats Extension的方法如下所示:

openGauss=# DROP Extension gms_stats [CASCADE];

 说明:

如果Extension被其它对象依赖,需要加入CASCADE(级联)关键字,删除所有依赖对象。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值