PostgreSQL 11 preview - compress method 接口 - 暨开放接口系列

本文涉及的产品
云原生数据库 PolarDB MySQL 版,Serverless 5000PCU 100GB
云数据库 Redis 版,社区版 2GB
推荐场景:
搭建游戏排行榜
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

标签

PostgreSQL , 开放接口 , udf , type , index , scan , language , fdw , sample , aggregate , operator , window , storage , compress


背景

PostgreSQL是一款扩展能力极强的数据库,这也是PG可以深入各个垂直行业的原因。

PostgreSQL的开放式接口

已有非常多跟进自定义接口扩展出来的插件。

下面是自定义接口对应的文档。

1、自定义函数

https://www.postgresql.org/docs/10/static/xfunc.html

2、自定义数据类型

https://www.postgresql.org/docs/10/static/xtypes.html

3、自定义操作符

https://www.postgresql.org/docs/10/static/xoper.html

4、自定义聚合、窗口

https://www.postgresql.org/docs/10/static/xaggr.html

5、自定义数据扫描方法

https://www.postgresql.org/docs/10/static/custom-scan.html

6、自定义数据采样方法

https://www.postgresql.org/docs/10/static/tablesample-method.html

7、自定义外部数据访问接口

https://www.postgresql.org/docs/10/static/fdwhandler.html

8、自定义存储过程语言

https://www.postgresql.org/docs/10/static/plhandler.html

9、自定义索引接口

https://www.postgresql.org/docs/10/static/indexam.html

11、自定义WAL日志接口

https://www.postgresql.org/docs/10/static/generic-wal.html

12、自定义逻辑订阅接口

https://www.postgresql.org/docs/10/static/logicaldecoding.html

13、自定义工作进程接口

https://www.postgresql.org/docs/10/static/bgworker.html

14、自定义存储接口

https://commitfest.postgresql.org/15/1283/

15、自定义压缩接口

https://commitfest.postgresql.org/15/1294/

16、自定义加密接口

著名扩展插件

1、空间

https://commitfest.postgresql.org/15/1294/

2、路由

http://pgrouting.org/

3、化学

http://www.rdkit.org/docs/Cartridge.html

4、基因

https://wiki.postgresql.org/images/1/1b/Postbis_pgcon_eu_2012.pdf

5、图像识别

https://wiki.postgresql.org/images/1/1b/Postbis_pgcon_eu_2012.pdf

6、图式搜索

http://www.agensgraph.com/

7、流式计算

https://www.pipelinedb.com/

8、外部访问接口

https://wiki.postgresql.org/wiki/Fdw

9、推荐数据库

https://github.com/DataSystemsLab/recdb-postgresql

10、分布式数据库

https://wiki.postgresql.org/wiki/PostgreSQL_derived_databases

11、列存储

https://github.com/citusdata/cstore_fdw

哪里可以找到扩展插件

github

https://pgxn.org/

http://pgfoundry.org/

https://wiki.postgresql.org/wiki/Main_Page

... ...

如何扩展

《找对业务G点, 体验酸爽 - PostgreSQL内核扩展指南》

开放的压缩接口

PostgreSQL 11 会引入的开放压缩接口。

未来可以对任意类型、索引实施外部压缩算法。

PostgreSQL每一种数据类型都有对应的in,out函数,加解压可以在对应数据类型的in, out函数内实现,在in,out函数内增加加解压的handler,可以方便各个类型调用。

                                      List of functions  
   Schema   |         Name         | Result data type |     Argument data types     |  Type    
------------+----------------------+------------------+-----------------------------+--------  
 pg_catalog | abstimeout           | cstring          | abstime                     | normal  
 pg_catalog | aclitemout           | cstring          | aclitem                     | normal  
 pg_catalog | any_out              | cstring          | "any"                       | normal  
 pg_catalog | anyarray_out         | cstring          | anyarray                    | normal  
 pg_catalog | anyelement_out       | cstring          | anyelement                  | normal  
 pg_catalog | anyenum_out          | cstring          | anyenum                     | normal  
 pg_catalog | anynonarray_out      | cstring          | anynonarray                 | normal  
 pg_catalog | anyrange_out         | cstring          | anyrange                    | normal  
 pg_catalog | array_out            | cstring          | anyarray                    | normal  
 pg_catalog | bit_out              | cstring          | bit                         | normal  
 pg_catalog | bittypmodout         | cstring          | integer                     | normal  
 pg_catalog | boolout              | cstring          | boolean                     | normal  
 pg_catalog | box_out              | cstring          | box                         | normal  
 pg_catalog | bpcharout            | cstring          | character                   | normal  
 pg_catalog | bpchartypmodout      | cstring          | integer                     | normal  
 pg_catalog | byteaout             | cstring          | bytea                       | normal  
 pg_catalog | cash_out             | cstring          | money                       | normal  
 pg_catalog | charout              | cstring          | "char"                      | normal  
 pg_catalog | cidout               | cstring          | cid                         | normal  
 pg_catalog | cidr_out             | cstring          | cidr                        | normal  
 pg_catalog | circle_out           | cstring          | circle                      | normal  
 pg_catalog | cstring_out          | cstring          | cstring                     | normal  
 pg_catalog | date_out             | cstring          | date                        | normal  
 pg_catalog | enum_out             | cstring          | anyenum                     | normal  
 pg_catalog | event_trigger_out    | cstring          | event_trigger               | normal  
 pg_catalog | fdw_handler_out      | cstring          | fdw_handler                 | normal  
 pg_catalog | float4out            | cstring          | real                        | normal  
 pg_catalog | float8out            | cstring          | double precision            | normal  
 pg_catalog | gtsvectorout         | cstring          | gtsvector                   | normal  
 pg_catalog | index_am_handler_out | cstring          | index_am_handler            | normal  
 pg_catalog | inet_out             | cstring          | inet                        | normal  
 pg_catalog | int2out              | cstring          | smallint                    | normal  
 pg_catalog | int2vectorout        | cstring          | int2vector                  | normal  
 pg_catalog | int4out              | cstring          | integer                     | normal  
 pg_catalog | int8out              | cstring          | bigint                      | normal  
 pg_catalog | internal_out         | cstring          | internal                    | normal  
 pg_catalog | interval_out         | cstring          | interval                    | normal  
 pg_catalog | intervaltypmodout    | cstring          | integer                     | normal  
 pg_catalog | json_out             | cstring          | json                        | normal  
 pg_catalog | jsonb_out            | cstring          | jsonb                       | normal  
 pg_catalog | language_handler_out | cstring          | language_handler            | normal  
 pg_catalog | line_out             | cstring          | line                        | normal  
 pg_catalog | lseg_out             | cstring          | lseg                        | normal  
 pg_catalog | macaddr8_out         | cstring          | macaddr8                    | normal  
 pg_catalog | macaddr_out          | cstring          | macaddr                     | normal  
 pg_catalog | nameout              | cstring          | name                        | normal  
 pg_catalog | numeric_out          | cstring          | numeric                     | normal  
 pg_catalog | numerictypmodout     | cstring          | integer                     | normal  
 pg_catalog | oidout               | cstring          | oid                         | normal  
 pg_catalog | oidvectorout         | cstring          | oidvector                   | normal  
 pg_catalog | opaque_out           | cstring          | opaque                      | normal  
 pg_catalog | path_out             | cstring          | path                        | normal  
 pg_catalog | pg_ddl_command_out   | cstring          | pg_ddl_command              | normal  
 pg_catalog | pg_dependencies_out  | cstring          | pg_dependencies             | normal  
 pg_catalog | pg_lsn_out           | cstring          | pg_lsn                      | normal  
 pg_catalog | pg_ndistinct_out     | cstring          | pg_ndistinct                | normal  
 pg_catalog | pg_node_tree_out     | cstring          | pg_node_tree                | normal  
 pg_catalog | point_out            | cstring          | point                       | normal  
 pg_catalog | poly_out             | cstring          | polygon                     | normal  
 pg_catalog | range_out            | cstring          | anyrange                    | normal  
 pg_catalog | record_out           | cstring          | record                      | normal  
 pg_catalog | regclassout          | cstring          | regclass                    | normal  
 pg_catalog | regconfigout         | cstring          | regconfig                   | normal  
 pg_catalog | regdictionaryout     | cstring          | regdictionary               | normal  
 pg_catalog | regnamespaceout      | cstring          | regnamespace                | normal  
 pg_catalog | regoperatorout       | cstring          | regoperator                 | normal  
 pg_catalog | regoperout           | cstring          | regoper                     | normal  
 pg_catalog | regprocedureout      | cstring          | regprocedure                | normal  
 pg_catalog | regprocout           | cstring          | regproc                     | normal  
 pg_catalog | regroleout           | cstring          | regrole                     | normal  
 pg_catalog | regtypeout           | cstring          | regtype                     | normal  
 pg_catalog | reltimeout           | cstring          | reltime                     | normal  
 pg_catalog | shell_out            | cstring          | opaque                      | normal  
 pg_catalog | smgrout              | cstring          | smgr                        | normal  
 pg_catalog | textout              | cstring          | text                        | normal  
 pg_catalog | tidout               | cstring          | tid                         | normal  
 pg_catalog | time_out             | cstring          | time without time zone      | normal  
 pg_catalog | timestamp_out        | cstring          | timestamp without time zone | normal  
 pg_catalog | timestamptypmodout   | cstring          | integer                     | normal  
 pg_catalog | timestamptz_out      | cstring          | timestamp with time zone    | normal  
 pg_catalog | timestamptztypmodout | cstring          | integer                     | normal  
 pg_catalog | timetypmodout        | cstring          | integer                     | normal  
 pg_catalog | timetz_out           | cstring          | time with time zone         | normal  
 pg_catalog | timetztypmodout      | cstring          | integer                     | normal  
 pg_catalog | tintervalout         | cstring          | tinterval                   | normal  
 pg_catalog | trigger_out          | cstring          | trigger                     | normal  
 pg_catalog | tsm_handler_out      | cstring          | tsm_handler                 | normal  
 pg_catalog | tsqueryout           | cstring          | tsquery                     | normal  
 pg_catalog | tsvectorout          | cstring          | tsvector                    | normal  
 pg_catalog | txid_snapshot_out    | cstring          | txid_snapshot               | normal  
 pg_catalog | unknownout           | cstring          | unknown                     | normal  
 pg_catalog | uuid_out             | cstring          | uuid                        | normal  
 pg_catalog | varbit_out           | cstring          | bit varying                 | normal  
 pg_catalog | varbittypmodout      | cstring          | integer                     | normal  
 pg_catalog | varcharout           | cstring          | character varying           | normal  
 pg_catalog | varchartypmodout     | cstring          | integer                     | normal  
 pg_catalog | void_out             | cstring          | void                        | normal  
 pg_catalog | xidout               | cstring          | xid                         | normal  
 pg_catalog | xml_out              | cstring          | xml                         | normal  
postgres=# \df *.*in  
                                                           List of functions  
   Schema   |               Name                |      Result data type       |             Argument data types              |  Type     
------------+-----------------------------------+-----------------------------+----------------------------------------------+---------  
 pg_catalog | abstimein                         | abstime                     | cstring                                      | normal  
 pg_catalog | aclitemin                         | aclitem                     | cstring                                      | normal  
 pg_catalog | any_in                            | "any"                       | cstring                                      | normal  
 pg_catalog | anyarray_in                       | anyarray                    | cstring                                      | normal  
 pg_catalog | anyelement_in                     | anyelement                  | cstring                                      | normal  
 pg_catalog | anyenum_in                        | anyenum                     | cstring                                      | normal  
 pg_catalog | anynonarray_in                    | anynonarray                 | cstring                                      | normal  
 pg_catalog | anyrange_in                       | anyrange                    | cstring, oid, integer                        | normal  
 pg_catalog | array_in                          | anyarray                    | cstring, oid, integer                        | normal  
 pg_catalog | bit_in                            | bit                         | cstring, oid, integer                        | normal  
 pg_catalog | bittypmodin                       | integer                     | cstring[]                                    | normal  
 pg_catalog | boolin                            | boolean                     | cstring                                      | normal  
 pg_catalog | box_contain                       | boolean                     | box, box                                     | normal  
 pg_catalog | box_in                            | box                         | cstring                                      | normal  
 pg_catalog | bpcharin                          | character                   | cstring, oid, integer                        | normal  
 pg_catalog | bpchartypmodin                    | integer                     | cstring[]                                    | normal  
 pg_catalog | byteain                           | bytea                       | cstring                                      | normal  
 pg_catalog | cash_in                           | money                       | cstring                                      | normal  
 pg_catalog | charin                            | "char"                      | cstring                                      | normal  
 pg_catalog | cidin                             | cid                         | cstring                                      | normal  
 pg_catalog | cidr_in                           | cidr                        | cstring                                      | normal  
 pg_catalog | circle_contain                    | boolean                     | circle, circle                               | normal  
 pg_catalog | circle_in                         | circle                      | cstring                                      | normal  
 pg_catalog | cstring_in                        | cstring                     | cstring                                      | normal  
 pg_catalog | date_in                           | date                        | cstring                                      | normal  
 pg_catalog | domain_in                         | "any"                       | cstring, oid, integer                        | normal  
 pg_catalog | enum_in                           | anyenum                     | cstring, oid                                 | normal  
 pg_catalog | event_trigger_in                  | event_trigger               | cstring                                      | normal  
 pg_catalog | fdw_handler_in                    | fdw_handler                 | cstring                                      | normal  
 pg_catalog | float4in                          | real                        | cstring                                      | normal  
 pg_catalog | float8in                          | double precision            | cstring                                      | normal  
 pg_catalog | gtsvectorin                       | gtsvector                   | cstring                                      | normal  
 pg_catalog | index_am_handler_in               | index_am_handler            | cstring                                      | normal  
 pg_catalog | inet_in                           | inet                        | cstring                                      | normal  
 pg_catalog | int2in                            | smallint                    | cstring                                      | normal  
 pg_catalog | int2vectorin                      | int2vector                  | cstring                                      | normal  
 pg_catalog | int4in                            | integer                     | cstring                                      | normal  
 pg_catalog | int8in                            | bigint                      | cstring                                      | normal  
 pg_catalog | internal_in                       | internal                    | cstring                                      | normal  
 pg_catalog | interval_in                       | interval                    | cstring, oid, integer                        | normal  
 pg_catalog | intervaltypmodin                  | integer                     | cstring[]                                    | normal  
 pg_catalog | json_in                           | json                        | cstring                                      | normal  
 pg_catalog | jsonb_in                          | jsonb                       | cstring                                      | normal  
 pg_catalog | language_handler_in               | language_handler            | cstring                                      | normal  
 pg_catalog | line_in                           | line                        | cstring                                      | normal  
 pg_catalog | lseg_in                           | lseg                        | cstring                                      | normal  
 pg_catalog | macaddr8_in                       | macaddr8                    | cstring                                      | normal  
 pg_catalog | macaddr_in                        | macaddr                     | cstring                                      | normal  
 pg_catalog | namein                            | name                        | cstring                                      | normal  
 pg_catalog | numeric_in                        | numeric                     | cstring, oid, integer                        | normal  
 pg_catalog | numerictypmodin                   | integer                     | cstring[]                                    | normal  
 pg_catalog | oidin                             | oid                         | cstring                                      | normal  
 pg_catalog | oidvectorin                       | oidvector                   | cstring                                      | normal  
 pg_catalog | opaque_in                         | opaque                      | cstring                                      | normal  
 pg_catalog | path_in                           | path                        | cstring                                      | normal  
 pg_catalog | pg_ddl_command_in                 | pg_ddl_command              | cstring                                      | normal  
 pg_catalog | pg_dependencies_in                | pg_dependencies             | cstring                                      | normal  
 pg_catalog | pg_lsn_in                         | pg_lsn                      | cstring                                      | normal  
 pg_catalog | pg_ndistinct_in                   | pg_ndistinct                | cstring                                      | normal  
 pg_catalog | pg_node_tree_in                   | pg_node_tree                | cstring                                      | normal  
 pg_catalog | point_in                          | point                       | cstring                                      | normal  
 pg_catalog | poly_in                           | polygon                     | cstring                                      | normal  
 pg_catalog | range_in                          | anyrange                    | cstring, oid, integer                        | normal  
 pg_catalog | record_in                         | record                      | cstring, oid, integer                        | normal  
 pg_catalog | regclassin                        | regclass                    | cstring                                      | normal  
 pg_catalog | regconfigin                       | regconfig                   | cstring                                      | normal  
 pg_catalog | regdictionaryin                   | regdictionary               | cstring                                      | normal  
 pg_catalog | regnamespacein                    | regnamespace                | cstring                                      | normal  
 pg_catalog | regoperatorin                     | regoperator                 | cstring                                      | normal  
 pg_catalog | regoperin                         | regoper                     | cstring                                      | normal  
 pg_catalog | regprocedurein                    | regprocedure                | cstring                                      | normal  
 pg_catalog | regprocin                         | regproc                     | cstring                                      | normal  
 pg_catalog | regrolein                         | regrole                     | cstring                                      | normal  
 pg_catalog | regtypein                         | regtype                     | cstring                                      | normal  
 pg_catalog | reltimein                         | reltime                     | cstring                                      | normal  
 pg_catalog | shell_in                          | opaque                      | cstring                                      | normal  
 pg_catalog | smgrin                            | smgr                        | cstring                                      | normal  
 pg_catalog | textin                            | text                        | cstring                                      | normal  
 pg_catalog | tidin                             | tid                         | cstring                                      | normal  
 pg_catalog | time_in                           | time without time zone      | cstring, oid, integer                        | normal  
 pg_catalog | timestamp_in                      | timestamp without time zone | cstring, oid, integer                        | normal  
 pg_catalog | timestamptypmodin                 | integer                     | cstring[]                                    | normal  
 pg_catalog | timestamptz_in                    | timestamp with time zone    | cstring, oid, integer                        | normal  
 pg_catalog | timestamptztypmodin               | integer                     | cstring[]                                    | normal  
 pg_catalog | timetypmodin                      | integer                     | cstring[]                                    | normal  
 pg_catalog | timetz_in                         | time with time zone         | cstring, oid, integer                        | normal  
 pg_catalog | timetztypmodin                    | integer                     | cstring[]                                    | normal  
 pg_catalog | tintervalin                       | tinterval                   | cstring                                      | normal  
 pg_catalog | trigger_in                        | trigger                     | cstring                                      | trigger  
 pg_catalog | tsm_handler_in                    | tsm_handler                 | cstring                                      | normal  
 pg_catalog | tsqueryin                         | tsquery                     | cstring                                      | normal  
 pg_catalog | tsvectorin                        | tsvector                    | cstring                                      | normal  
 pg_catalog | txid_snapshot_in                  | txid_snapshot               | cstring                                      | normal  
 pg_catalog | unknownin                         | unknown                     | cstring                                      | normal  
 pg_catalog | uuid_in                           | uuid                        | cstring                                      | normal  
 pg_catalog | varbit_in                         | bit varying                 | cstring, oid, integer                        | normal  
 pg_catalog | varbittypmodin                    | integer                     | cstring[]                                    | normal  
 pg_catalog | varcharin                         | character varying           | cstring, oid, integer                        | normal  
 pg_catalog | varchartypmodin                   | integer                     | cstring[]                                    | normal  
 pg_catalog | void_in                           | void                        | cstring                                      | normal  
 pg_catalog | xidin                             | xid                         | cstring                                      | normal  
 pg_catalog | xml_in                            | xml                         | cstring                                      | normal  

目前正在讨论的设计,语法如下

CREATE TABLE t(a tsvector COMPRESSED <cmname> WITH <options>);  
ALTER TABLE t ALTER COLUMN a SET COMPRESSED <cmname> WITH <options>;   
ALTER TABLE t ALTER COLUMN a SET NOT COMPRESSED;  
  
Also there is syntax of binding compression methods to types:  
  
ALTER TYPE <type> SET COMPRESSED <cmname>;  
ALTER TYPE <type> SET NOT COMPRESSED;  

jsonbd插件,使用了类似的方法实现jsonb数据的压缩。

https://github.com/postgrespro/jsonbd

CREATE EXTENSION jsonbd;  
CREATE COMPRESSION METHOD cm1 HANDLER jsonbd_compression_handler;  
CREATE TABLE t(a JSONB);  
ALTER TABLE t ALTER COLUMN a SET COMPRESSED cm1;  
相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
相关文章
|
1月前
|
消息中间件 NoSQL atlas
|
5月前
|
缓存 API 数据格式
阿里云国际站代理商:阿里云解决swagger提示Failed to load API definition Fetch errorundefined
@luotuoemo飞机@TG阿里云国际站代理商:将Swagger集成到项目中可以方便地生成和管理API文档,但有时候在使用Swagger时可能会遇到`Failed to load API definition Fetch errorundefined`这样的错误提示。这个错误通常是由以下几个原因引起的:
|
7月前
|
关系型数据库 调度 数据库
直播预告 | PolarDB-PG 企业级特性 —— Shared Server特性详解
PolarDB-PG 提供了 Shared Server 内置连接池功能,实现了用户连接与后端进程的解绑。后端进程在运行时可以根据实时负载和进程污染情况进行动态转换。负载调度算法使用 Stall 机制弹性控制 Worker 数量,同时避免用户连接饿死。从根本上解决了高并发或者大量短连接带来的性能、稳定性问题。
|
缓存 API 开发者
API开放 | 国际包裹查询接口解决方案International Package Tracking 17TRACK
物流环节信息化升级,用户物流体验升级,国际包裹查询接口解决方案International Package Tracking 17TRACK接口使用教程。有100单免费测试额度,需要完整的技术开发文档v我837094255
API开放 | 国际包裹查询接口解决方案International Package Tracking 17TRACK
|
XML JSON 网络协议
|
关系型数据库 物联网 数据库连接
【DB吐槽大会】第22期 - PG 不支持libpq协议层压缩
大家好,这里是DB吐槽大会,第22期 - PG 不支持libpq协议层压缩
|
关系型数据库 RDS SQL
强强联合 阿里云 RDS for SQL Server 与 金蝶 K/3 WISE 产品实现兼容适配
强强联合 阿里云 RDS for SQL Server 与 金蝶 K/3 WISE 产品实现兼容适配,原K/3 WISE用户通过简单配置就可以无缝搭配RDS SQL Server使用,不需再费时费力自建SQL Server数据库。
1138 0
|
关系型数据库 PostgreSQL 存储
PostgreSQL 10.1 手册_部分 IV. 客户端接口_第 33 章 libpq - C 库_33.7. 快速路径接口
33.7. 快速路径接口 PostgreSQL提供一种快速路径接口来向服务器发送简单的函数调用。 提示 这个接口在某种程度上已被废弃,因为我们可以通过创建一个定义该函数调用的预备语句来达到类似或者更强大的功能。
1105 0
|
存储 关系型数据库 数据库
PostgreSQL 10.1 手册_部分 IV. 客户端接口_第 34 章 大对象_34.2. 实现特性
34.2. 实现特性 大对象的实现将大对象分解成很多“数据块”并且将这些数据块存储在数据库的行中。一个B-tree索引用来保证在进行随机访问读写时能够根据数据块号快速地搜索到正确的数据块。 为一个大对象存储的数据块并不需要是连续的。
1071 0