mirror of
https://github.com/postgres/postgres.git
synced 2025-07-08 11:42:09 +03:00
Support CREATE ACCESS METHOD
This enables external code to create access methods. This is useful so that extensions can add their own access methods which can be formally tracked for dependencies, so that DROP operates correctly. Also, having explicit support makes pg_dump work correctly. Currently only index AMs are supported, but we expect different types to be added in the future. Authors: Alexander Korotkov, Petr Jelínek Reviewed-By: Teodor Sigaev, Petr Jelínek, Jim Nasby Commitfest-URL: https://commitfest.postgresql.org/9/353/ Discussion: https://www.postgresql.org/message-id/CAPpHfdsXwZmojm6Dx+TJnpYk27kT4o7Ri6X_4OSWcByu1Rm+VA@mail.gmail.com
This commit is contained in:
@ -678,6 +678,12 @@ DefineOpClass(CreateOpClassStmt *stmt)
|
||||
myself.objectId = opclassoid;
|
||||
myself.objectSubId = 0;
|
||||
|
||||
/* dependency on access method */
|
||||
referenced.classId = AccessMethodRelationId;
|
||||
referenced.objectId = amoid;
|
||||
referenced.objectSubId = 0;
|
||||
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
||||
|
||||
/* dependency on namespace */
|
||||
referenced.classId = NamespaceRelationId;
|
||||
referenced.objectId = namespaceoid;
|
||||
@ -743,7 +749,7 @@ DefineOpFamily(CreateOpFamilyStmt *stmt)
|
||||
get_namespace_name(namespaceoid));
|
||||
|
||||
/* Get access method OID, throwing an error if it doesn't exist. */
|
||||
amoid = get_am_oid(stmt->amname, false);
|
||||
amoid = get_index_am_oid(stmt->amname, false);
|
||||
|
||||
/* XXX Should we make any privilege check against the AM? */
|
||||
|
||||
@ -1663,21 +1669,6 @@ RemoveAmProcEntryById(Oid entryOid)
|
||||
heap_close(rel, RowExclusiveLock);
|
||||
}
|
||||
|
||||
char *
|
||||
get_am_name(Oid amOid)
|
||||
{
|
||||
HeapTuple tup;
|
||||
char *result = NULL;
|
||||
|
||||
tup = SearchSysCache1(AMOID, ObjectIdGetDatum(amOid));
|
||||
if (HeapTupleIsValid(tup))
|
||||
{
|
||||
result = pstrdup(NameStr(((Form_pg_am) GETSTRUCT(tup))->amname));
|
||||
ReleaseSysCache(tup);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Subroutine for ALTER OPERATOR CLASS SET SCHEMA/RENAME
|
||||
*
|
||||
@ -1723,22 +1714,3 @@ IsThereOpFamilyInNamespace(const char *opfname, Oid opfmethod,
|
||||
get_am_name(opfmethod),
|
||||
get_namespace_name(opfnamespace))));
|
||||
}
|
||||
|
||||
/*
|
||||
* get_am_oid - given an access method name, look up the OID
|
||||
*
|
||||
* If missing_ok is false, throw an error if access method not found. If
|
||||
* true, just return InvalidOid.
|
||||
*/
|
||||
Oid
|
||||
get_am_oid(const char *amname, bool missing_ok)
|
||||
{
|
||||
Oid oid;
|
||||
|
||||
oid = GetSysCacheOid1(AMNAME, CStringGetDatum(amname));
|
||||
if (!OidIsValid(oid) && !missing_ok)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("access method \"%s\" does not exist", amname)));
|
||||
return oid;
|
||||
}
|
||||
|
Reference in New Issue
Block a user