|
| 1 | +## PostgreSQL 12 preview - 意义重大改进:增加一层access manager API - 支持 TABLE、INDEX AM(access method) - 为storage pluggable 开路 |
| 2 | + |
| 3 | +### 作者 |
| 4 | +digoal |
| 5 | + |
| 6 | +### 日期 |
| 7 | +2019-03-31 |
| 8 | + |
| 9 | +### 标签 |
| 10 | +PostgreSQL , am , indexam , tableam , access method , access manager |
| 11 | + |
| 12 | +---- |
| 13 | + |
| 14 | +## 背景 |
| 15 | +PostgreSQL 12 新增一层 access manager API - 支持 TABLE、INDEX AM(access method) - 为storage pluggable 开路 。 |
| 16 | + |
| 17 | +意义重大:将来支持zheap(undo引擎),列存储,内存表,压缩表等会非常的便捷。 |
| 18 | + |
| 19 | +PG 11 |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | +PG 12 |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | +[Pluggable Storage in PostgreSQL](20190331_03_pdf_001.pdf) |
| 28 | + |
| 29 | +``` |
| 30 | +CREATE TABLE …(...) USING heap; |
| 31 | +``` |
| 32 | + |
| 33 | +https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=8586bf7ed8889f39a59dd99b292014b73be85342 |
| 34 | + |
| 35 | +``` |
| 36 | +tableam: introduce table AM infrastructure. |
| 37 | + |
| 38 | +This introduces the concept of table access methods, i.e. |
| 39 | + CREATE ACCESS METHOD ... TYPE TABLE and |
| 40 | + CREATE TABLE ... USING (storage-engine). |
| 41 | +No table access functionality is delegated to table AMs as of this |
| 42 | +commit, that'll be done in following commits. |
| 43 | + |
| 44 | +Subsequent commits will incrementally abstract table access |
| 45 | +functionality to be routed through table access methods. That change |
| 46 | +is too large to be reviewed & committed at once, so it'll be done |
| 47 | +incrementally. |
| 48 | + |
| 49 | +Docs will be updated at the end, as adding them incrementally would |
| 50 | +likely make them less coherent, and definitely is a lot more work, |
| 51 | +without a lot of benefit. |
| 52 | + |
| 53 | +Table access methods are specified similar to index access methods, |
| 54 | +i.e. pg_am.amhandler returns, as INTERNAL, a pointer to a struct with |
| 55 | +callbacks. In contrast to index AMs that struct needs to live as long |
| 56 | +as a backend, typically that's achieved by just returning a pointer to |
| 57 | +a constant struct. |
| 58 | + |
| 59 | +Psql's \d+ now displays a table's access method. That can be disabled |
| 60 | +with HIDE_TABLEAM=true, which is mainly useful so regression tests can |
| 61 | +be run against different AMs. It's quite possible that this behaviour |
| 62 | +still needs to be fine tuned. |
| 63 | + |
| 64 | +For now it's not allowed to set a table AM for a partitioned table, as |
| 65 | +we've not resolved how partitions would inherit that. Disallowing |
| 66 | +allows us to introduce, if we decide that's the way forward, such a |
| 67 | +behaviour without a compatibility break. |
| 68 | + |
| 69 | +Catversion bumped, to add the heap table AM and references to it. |
| 70 | + |
| 71 | +Author: Haribabu Kommi, Andres Freund, Alvaro Herrera, Dimitri Golgov and others |
| 72 | +Discussion: |
| 73 | + https://postgr.es/m/[email protected] |
| 74 | + https://postgr.es/m/[email protected] |
| 75 | + https://postgr.es/m/[email protected] |
| 76 | + https://postgr.es/m/[email protected] |
| 77 | +``` |
| 78 | + |
| 79 | +## 查看当前支持的AM |
| 80 | +``` |
| 81 | +postgres=# select * from pg_am; |
| 82 | + oid | amname | amhandler | amtype |
| 83 | +------+--------+----------------------+-------- |
| 84 | + 2 | heap | heap_tableam_handler | t |
| 85 | + 403 | btree | bthandler | i |
| 86 | + 405 | hash | hashhandler | i |
| 87 | + 783 | gist | gisthandler | i |
| 88 | + 2742 | gin | ginhandler | i |
| 89 | + 4000 | spgist | spghandler | i |
| 90 | + 3580 | brin | brinhandler | i |
| 91 | +(7 rows) |
| 92 | + |
| 93 | +postgres=# \d+ pg_am |
| 94 | + Table "pg_catalog.pg_am" |
| 95 | + Column | Type | Collation | Nullable | Default | Storage | Stats target | Description |
| 96 | +-----------+---------+-----------+----------+---------+---------+--------------+------------- |
| 97 | + oid | oid | | not null | | plain | | |
| 98 | + amname | name | | not null | | plain | | |
| 99 | + amhandler | regproc | | not null | | plain | | |
| 100 | + amtype | "char" | | not null | | plain | | |
| 101 | +Indexes: |
| 102 | + "pg_am_name_index" UNIQUE, btree (amname) |
| 103 | + "pg_am_oid_index" UNIQUE, btree (oid) |
| 104 | +Access method: heap |
| 105 | +``` |
| 106 | + |
| 107 | +## 扩展AM例子(扩展bloom indexam) |
| 108 | + |
| 109 | +``` |
| 110 | +postgres=# create extension bloom ; |
| 111 | +CREATE EXTENSION |
| 112 | + |
| 113 | +postgres=# select * from pg_am; |
| 114 | + oid | amname | amhandler | amtype |
| 115 | +-------+--------+----------------------+-------- |
| 116 | + 2 | heap | heap_tableam_handler | t |
| 117 | + 403 | btree | bthandler | i |
| 118 | + 405 | hash | hashhandler | i |
| 119 | + 783 | gist | gisthandler | i |
| 120 | + 2742 | gin | ginhandler | i |
| 121 | + 4000 | spgist | spghandler | i |
| 122 | + 3580 | brin | brinhandler | i |
| 123 | + 23030 | bloom | blhandler | i |
| 124 | +(8 rows) |
| 125 | + |
| 126 | +postgres=# \dA+ |
| 127 | + List of access methods |
| 128 | + Name | Type | Handler | Description |
| 129 | +--------+-------+----------------------+---------------------------------------- |
| 130 | + bloom | Index | blhandler | bloom index access method |
| 131 | + brin | Index | brinhandler | block range index (BRIN) access method |
| 132 | + btree | Index | bthandler | b-tree index access method |
| 133 | + gin | Index | ginhandler | GIN index access method |
| 134 | + gist | Index | gisthandler | GiST index access method |
| 135 | + hash | Index | hashhandler | hash index access method |
| 136 | + heap | Table | heap_tableam_handler | heap table access method |
| 137 | + spgist | Index | spghandler | SP-GiST index access method |
| 138 | +(8 rows) |
| 139 | +``` |
| 140 | + |
| 141 | +## 参考 |
| 142 | +https://anarazel.de/talks/2018-10-25-pgconfeu-pluggable-storage/pluggable.pdf |
| 143 | + |
| 144 | +https://commitfest.postgresql.org/22/1283/ |
| 145 | + |
| 146 | +[《PostgreSQL undo多版本存储引擎 zheap测试》](../201809/20180922_01.md) |
| 147 | + |
| 148 | +[《[未完待续] PostgreSQL 扩展存储引擎介绍 - zheap - 1》](../201803/20180311_02.md) |
| 149 | + |
| 150 | + |
| 151 | +<a rel="nofollow" href="http://info.flagcounter.com/h9V1" ><img src="http://s03.flagcounter.com/count/h9V1/bg_FFFFFF/txt_000000/border_CCCCCC/columns_2/maxflags_12/viewers_0/labels_0/pageviews_0/flags_0/" alt="Flag Counter" border="0" ></a> |
| 152 | + |
| 153 | + |
| 154 | +## [digoal's 大量PostgreSQL文章入口](https://github.com/digoal/blog/blob/master/README.md "22709685feb7cab07d30f30387f0a9ae") |
| 155 | + |
| 156 | + |
| 157 | +## [免费领取阿里云RDS PostgreSQL实例、ECS虚拟机](https://free.aliyun.com/ "57258f76c37864c6e6d23383d05714ea") |
| 158 | + |
0 commit comments