← ClaudeAtlas

access-method-apislisted

Implement or modify a PostgreSQL pluggable index AM or table AM — covers IndexAmRoutine callbacks (ambuild, aminsert, amgettuple, amgetbitmap, ambulkdelete, amvacuumcleanup, amparallelrescan), TableAmRoutine callbacks (scan_begin, scan_getnextslot, tuple_insert, tuple_insert_speculative, slot_callbacks, index_fetch_*), opclass / strategy numbers / support functions, TID semantics for non-heap stores, genam.c and tableam.h wrappers, plus CREATE ACCESS METHOD + pg_am / pg_opclass / pg_amproc / pg_amop catalog registration. Use whenever a PG patch implements or modifies an index AM (btree variant, hash, gin, gist, spgist, brin, custom) or a table AM (heap, columnar, in-memory, custom store), or designs TID semantics for a non-heap storage. Skip user-facing "which index type should I use" / "should this be a btree or hash index" advice, EXPLAIN tuning questions, GIN / GIST / btree CONCURRENTLY operational guidance, application-side ORM index hints, and non-PG storage engines (MySQL InnoDB / MyRocks, RocksDB, Leve
matejformanek/postgres-claude · ★ 0 · API & Backend · score 70
Install: claude install-skill matejformanek/postgres-claude
# Access-method APIs — operational guide This skill is for code that **implements** an AM (or significantly extends one). Read-only "how does btree work" questions don't need it — go straight to the per-AM README. ## Two completely separate plug points | | Index AM | Table AM | |---|---|---| | Struct | `IndexAmRoutine` in `src/include/access/amapi.h` | `TableAmRoutine` in `src/include/access/tableam.h` | | Resolver | `GetIndexAmRoutine(amhandler)` in `src/backend/access/index/amapi.c` | `GetTableAmRoutine(amhandler)` in `src/backend/access/table/tableamapi.c` | | Catalog | `pg_am.amtype = 'i'` | `pg_am.amtype = 't'` | | Executor wrapper | `genam.c` / `indexam.c` | inline wrappers in `tableam.h` (`table_beginscan`, `table_tuple_insert`, …) | | Canonical impl | `nbtree.c`, also `brin.c`, `gin.c`, `gist.c`, `hash.c`, `spgist.c` | `heapam_handler.c` (the only in-tree one) | | Minimal stub | `src/test/modules/dummy_index_am/dummy_index_am.c` | none in tree | | Added | Index AM API since 9.6 (`amapi.h`); table AM since v12 | | Both APIs work the same way at the dispatch level: a `pg_am` row's `amhandler` column names a SQL-callable C function (`PG_FUNCTION_INFO_V1`) that returns a pointer to a **statically allocated** `IndexAmRoutine`/`TableAmRoutine`. The core never copies or frees the struct. ```c Datum myhandler(PG_FUNCTION_ARGS) { static const IndexAmRoutine amroutine = { .type = T_IndexAmRoutine, ... }; PG_RETURN_POINTER(&amroutine); } ``` ## Index AM (IndexAmRou