听 diagoal 德哥 说 国产数据库 HaloDB 要集成 DuckDB 了,还是用 TAM 方式实现的,前排坐等 Halo 16 GA。
(图片来源:羲和(Halo)16 Release Preview 1)
恩,本文完。
等等,什么是 TAM?
从 PG 12 开始,在 PG 系统核心和表访问方法 (Table Access Methods) 之间增加了一层表访问方法接口,用于管理表的存储。
每个表访问方法由 pg_am
系统目录中的一行描述。该 pg_am
条目指定表访问方法的名称和处理程序函数。
手头刚好有上周装的 IvorySQL 3.3,就拿这个环境做个实验。
ivorysql=# table pg_am;
oid | amname | amhandler | amtype
------+--------+----------------------+--------
2 | heap | heap_tableam_handler | t
403 | btree | bthandler | i
405 | hash | hashhandler | i
783 | gist | gisthandler | i
2742 | gin | ginhandler | i
4000 | spgist | spghandler | i
3580 | brin | brinhandler | i
(7 rows)
创建 AM 语法 CREATE ACCESS METHOD
。
CREATE ACCESS METHOD name
TYPE access_method_type <TABLE|INDEX>
HANDLER handler_function
相关内容参见:
https://www.postgresql.org/docs/current/tableam.html
扩展 AM 示例
以 pgtam 为例,演示为 PG 增加一种内存表访问方法。
下载源码。
git clone https://github.com/eatonphil/pgtam.git
编译安装。
[root@ivorysql3 pgtam-main]# make
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wcast-function-type -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -Wno-stringop-truncation -O2 -fPIC -fvisibility=hidden -I. -I./ -I/opt/ivorysql-3.3/include/postgresql/server -I/opt/ivorysql-3.3/include/postgresql/internal -D_GNU_SOURCE -c -o pgtam.o pgtam.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wcast-function-type -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -Wno-stringop-truncation -O2 -fPIC -fvisibility=hidden pgtam.o -L/opt/ivorysql-3.3/lib -Wl,--as-needed -Wl,-rpath,'/opt/ivorysql-3.3/lib',--enable-new-dtags -fvisibility=hidden -shared -o pgtam.so
[root@ivorysql3 pgtam-main]# make install
/usr/bin/mkdir -p '/opt/ivorysql-3.3/share/postgresql/extension'
/usr/bin/mkdir -p '/opt/ivorysql-3.3/share/postgresql/extension'
/usr/bin/mkdir -p '/opt/ivorysql-3.3/lib/postgresql'
/usr/bin/install -c -m 644 .//pgtam.control '/opt/ivorysql-3.3/share/postgresql/extension/'
/usr/bin/install -c -m 644 .//pgtam--0.0.1.sql '/opt/ivorysql-3.3/share/postgresql/extension/'
/usr/bin/install -c -m 755 pgtam.so '/opt/ivorysql-3.3/lib/postgresql/'
连接数据库,创建扩展。
create extension pgtam;
创建 mem 引擎的表,并插入数据。
create table demo(a int) using mem;
INSERT INTO demo VALUES (20), (24);
查看 AM、表结构和数据。
ivorysql=# select * from pg_am where amtype = 't';
oid | amname | amhandler | amtype
-------+--------+----------------------+--------
2 | heap | heap_tableam_handler | t
16398 | mem | mem_tableam_handler | t
(2 rows)
ivorysql=# \dt+ demo
List of relations
Schema | Name | Type | Owner | Persistence | Access method | Size | Description
--------+------+-------+----------+-------------+---------------+---------+-------------
public | demo | table | ivorysql | permanent | mem | 0 bytes |
(1 row)
ivorysql=# table demo;
a
----
20
24
(2 rows)
参考资料
https://github.com/digoal/blog/blob/master/201903/20190331_03.md
🌻 往期精彩 ▼
[Oracle]
[MySQL]
[TiDB]
[PG]
- [[RL9] Rocky Linux 9.4 搭载 PG 16.1](https://mp.weixin.qq.com/s/-LYgMoaktYXZ1UG5V5neow)
- 即将告别PG 12,建议升级到PG 16.3版本
- 后 EL 7 时代,PG 16 如何在 CentOS 7 上运行
-- / END / --
👉 这里可以找到我
如果这篇文章为你带来了灵感或启发,就请帮忙点『赞』or『在看』or『转发』吧,感谢!ღ( ´・ᴗ・` )~
本文由mdnice多平台发布
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。