mirror of
https://github.com/postgres/postgres.git
synced 2025-06-17 17:02:08 +03:00
Harden tableam against nonexistant / wrong kind of AMs.
Previously it was allowed to set default_table_access_method to an
empty string. That makes sense for default_tablespace, where that was
copied from, as it signals falling back to the database's default
tablespace. As there is no equivalent for table AMs, forbid that.
Also make sure to throw a usable error when creating a table using an
index AM, by using get_am_type_oid() to implement get_table_am_oid()
instead of a separate copy. Previously we'd error out only later, in
GetTableAmRoutine().
Thirdly remove GetTableAmRoutineByAmId() - it was only used in an
earlier version of 8586bf7ed8
.
Add tests for the above (some for index AMs as well).
This commit is contained in:
@ -832,22 +832,9 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
|
||||
relkind == RELKIND_MATVIEW)
|
||||
accessMethod = default_table_access_method;
|
||||
|
||||
/*
|
||||
* look up the access method, verify it can handle the requested features
|
||||
*/
|
||||
/* look up the access method, verify it is for a table */
|
||||
if (accessMethod != NULL)
|
||||
{
|
||||
HeapTuple tuple;
|
||||
|
||||
tuple = SearchSysCache1(AMNAME, PointerGetDatum(accessMethod));
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("table access method \"%s\" does not exist",
|
||||
accessMethod)));
|
||||
accessMethodId = ((Form_pg_am) GETSTRUCT(tuple))->oid;
|
||||
ReleaseSysCache(tuple);
|
||||
}
|
||||
accessMethodId = get_table_am_oid(accessMethod, false);
|
||||
|
||||
/*
|
||||
* Create the relation. Inherited defaults and constraints are passed in
|
||||
|
Reference in New Issue
Block a user