diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2016-03-23 23:01:35 -0300 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2016-03-23 23:01:35 -0300 |
commit | 473b93287040b20017cc25a157cffdc5b978c254 (patch) | |
tree | 58f662a65247525b2e5e178b9050feb3f3056590 /src/backend/commands/opclasscmds.c | |
parent | 2c6af4f44228d76d3351fe26f68b00b55cdd239a (diff) | |
download | postgresql-473b93287040b20017cc25a157cffdc5b978c254.tar.gz postgresql-473b93287040b20017cc25a157cffdc5b978c254.zip |
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
Diffstat (limited to 'src/backend/commands/opclasscmds.c')
-rw-r--r-- | src/backend/commands/opclasscmds.c | 42 |
1 files changed, 7 insertions, 35 deletions
diff --git a/src/backend/commands/opclasscmds.c b/src/backend/commands/opclasscmds.c index 8a661968cd9..ac559fc9b41 100644 --- a/src/backend/commands/opclasscmds.c +++ b/src/backend/commands/opclasscmds.c @@ -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; -} |