1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-07 00:36:50 +03:00

tableam: introduce table AM infrastructure.

This introduces the concept of table access methods, i.e. CREATE
  ACCESS METHOD ... TYPE TABLE and
  CREATE TABLE ... USING (storage-engine).
No table access functionality is delegated to table AMs as of this
commit, that'll be done in following commits.

Subsequent commits will incrementally abstract table access
functionality to be routed through table access methods. That change
is too large to be reviewed & committed at once, so it'll be done
incrementally.

Docs will be updated at the end, as adding them incrementally would
likely make them less coherent, and definitely is a lot more work,
without a lot of benefit.

Table access methods are specified similar to index access methods,
i.e. pg_am.amhandler returns, as INTERNAL, a pointer to a struct with
callbacks. In contrast to index AMs that struct needs to live as long
as a backend, typically that's achieved by just returning a pointer to
a constant struct.

Psql's \d+ now displays a table's access method. That can be disabled
with HIDE_TABLEAM=true, which is mainly useful so regression tests can
be run against different AMs.  It's quite possible that this behaviour
still needs to be fine tuned.

For now it's not allowed to set a table AM for a partitioned table, as
we've not resolved how partitions would inherit that. Disallowing
allows us to introduce, if we decide that's the way forward, such a
behaviour without a compatibility break.

Catversion bumped, to add the heap table AM and references to it.

Author: Haribabu Kommi, Andres Freund, Alvaro Herrera, Dimitri Golgov and others
Discussion:
    https://postgr.es/m/20180703070645.wchpu5muyto5n647@alap3.anarazel.de
    https://postgr.es/m/20160812231527.GA690404@alvherre.pgsql
    https://postgr.es/m/20190107235616.6lur25ph22u5u5av@alap3.anarazel.de
    https://postgr.es/m/20190304234700.w5tmhducs5wxgzls@alap3.anarazel.de
This commit is contained in:
Andres Freund
2019-03-06 09:54:38 -08:00
parent f217761856
commit 8586bf7ed8
50 changed files with 1056 additions and 75 deletions

View File

@ -30,7 +30,7 @@
#include "utils/syscache.h"
static Oid lookup_index_am_handler_func(List *handler_name, char amtype);
static Oid lookup_am_handler_func(List *handler_name, char amtype);
static const char *get_am_type_string(char amtype);
@ -74,7 +74,7 @@ CreateAccessMethod(CreateAmStmt *stmt)
/*
* Get the handler function oid, verifying the AM type while at it.
*/
amhandler = lookup_index_am_handler_func(stmt->handler_name, stmt->amtype);
amhandler = lookup_am_handler_func(stmt->handler_name, stmt->amtype);
/*
* Insert tuple into pg_am.
@ -229,6 +229,8 @@ get_am_type_string(char amtype)
{
case AMTYPE_INDEX:
return "INDEX";
case AMTYPE_TABLE:
return "TABLE";
default:
/* shouldn't happen */
elog(ERROR, "invalid access method type '%c'", amtype);
@ -243,10 +245,11 @@ get_am_type_string(char amtype)
* This function either return valid function Oid or throw an error.
*/
static Oid
lookup_index_am_handler_func(List *handler_name, char amtype)
lookup_am_handler_func(List *handler_name, char amtype)
{
Oid handlerOid;
static const Oid funcargtypes[1] = {INTERNALOID};
Oid funcargtypes[1] = {INTERNALOID};
Oid expectedType = InvalidOid;
if (handler_name == NIL)
ereport(ERROR,
@ -260,16 +263,21 @@ lookup_index_am_handler_func(List *handler_name, char amtype)
switch (amtype)
{
case AMTYPE_INDEX:
if (get_func_rettype(handlerOid) != INDEX_AM_HANDLEROID)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("function %s must return type %s",
NameListToString(handler_name),
"index_am_handler")));
expectedType = INDEX_AM_HANDLEROID;
break;
case AMTYPE_TABLE:
expectedType = TABLE_AM_HANDLEROID;
break;
default:
elog(ERROR, "unrecognized access method type \"%c\"", amtype);
}
if (get_func_rettype(handlerOid) != expectedType)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("function %s must return type %s",
get_func_name(handlerOid),
format_type_extended(expectedType, -1, 0))));
return handlerOid;
}