diff options
Diffstat (limited to 'src/backend/commands/extension.c')
-rw-r--r-- | src/backend/commands/extension.c | 64 |
1 files changed, 43 insertions, 21 deletions
diff --git a/src/backend/commands/extension.c b/src/backend/commands/extension.c index 3b95552a60f..aa733575e46 100644 --- a/src/backend/commands/extension.c +++ b/src/backend/commands/extension.c @@ -1170,7 +1170,7 @@ find_update_path(List *evi_list, /* * CREATE EXTENSION */ -Oid +ObjectAddress CreateExtension(CreateExtensionStmt *stmt) { DefElem *d_schema = NULL; @@ -1188,6 +1188,7 @@ CreateExtension(CreateExtensionStmt *stmt) List *requiredSchemas; Oid extensionOid; ListCell *lc; + ObjectAddress address; /* Check extension name validity before any filesystem access */ check_valid_extension_name(stmt->extname); @@ -1206,7 +1207,7 @@ CreateExtension(CreateExtensionStmt *stmt) (errcode(ERRCODE_DUPLICATE_OBJECT), errmsg("extension \"%s\" already exists, skipping", stmt->extname))); - return InvalidOid; + return InvalidObjectAddress; } else ereport(ERROR, @@ -1443,12 +1444,13 @@ CreateExtension(CreateExtensionStmt *stmt) /* * Insert new tuple into pg_extension, and create dependency entries. */ - extensionOid = InsertExtensionTuple(control->name, extowner, - schemaOid, control->relocatable, - versionName, - PointerGetDatum(NULL), - PointerGetDatum(NULL), - requiredExtensions); + address = InsertExtensionTuple(control->name, extowner, + schemaOid, control->relocatable, + versionName, + PointerGetDatum(NULL), + PointerGetDatum(NULL), + requiredExtensions); + extensionOid = address.objectId; /* * Apply any control-file comment on extension @@ -1471,7 +1473,7 @@ CreateExtension(CreateExtensionStmt *stmt) ApplyExtensionUpdates(extensionOid, pcontrol, versionName, updateVersions); - return extensionOid; + return address; } /* @@ -1487,7 +1489,7 @@ CreateExtension(CreateExtensionStmt *stmt) * extConfig and extCondition should be arrays or PointerGetDatum(NULL). * We declare them as plain Datum to avoid needing array.h in extension.h. */ -Oid +ObjectAddress InsertExtensionTuple(const char *extName, Oid extOwner, Oid schemaOid, bool relocatable, const char *extVersion, Datum extConfig, Datum extCondition, @@ -1564,7 +1566,7 @@ InsertExtensionTuple(const char *extName, Oid extOwner, /* Post creation hook for new extension */ InvokeObjectPostCreateHook(ExtensionRelationId, extensionOid, 0); - return extensionOid; + return myself; } /* @@ -2399,8 +2401,8 @@ extension_config_remove(Oid extensionoid, Oid tableoid) /* * Execute ALTER EXTENSION SET SCHEMA */ -Oid -AlterExtensionNamespace(List *names, const char *newschema) +ObjectAddress +AlterExtensionNamespace(List *names, const char *newschema, Oid *oldschema) { char *extensionName; Oid extensionOid; @@ -2416,6 +2418,7 @@ AlterExtensionNamespace(List *names, const char *newschema) SysScanDesc depScan; HeapTuple depTup; ObjectAddresses *objsMoved; + ObjectAddress extAddr; if (list_length(names) != 1) ereport(ERROR, @@ -2480,7 +2483,7 @@ AlterExtensionNamespace(List *names, const char *newschema) if (extForm->extnamespace == nspOid) { heap_close(extRel, RowExclusiveLock); - return InvalidOid; + return InvalidObjectAddress; } /* Check extension is supposed to be relocatable */ @@ -2557,6 +2560,10 @@ AlterExtensionNamespace(List *names, const char *newschema) get_namespace_name(oldNspOid)))); } + /* report old schema, if caller wants it */ + if (oldschema) + *oldschema = oldNspOid; + systable_endscan(depScan); relation_close(depRel, AccessShareLock); @@ -2575,13 +2582,15 @@ AlterExtensionNamespace(List *names, const char *newschema) InvokeObjectPostAlterHook(ExtensionRelationId, extensionOid, 0); - return extensionOid; + ObjectAddressSet(extAddr, ExtensionRelationId, extensionOid); + + return extAddr; } /* * Execute ALTER EXTENSION UPDATE */ -Oid +ObjectAddress ExecAlterExtensionStmt(AlterExtensionStmt *stmt) { DefElem *d_new_version = NULL; @@ -2597,6 +2606,7 @@ ExecAlterExtensionStmt(AlterExtensionStmt *stmt) Datum datum; bool isnull; ListCell *lc; + ObjectAddress address; /* * We use global variables to track the extension being created, so we can @@ -2698,7 +2708,7 @@ ExecAlterExtensionStmt(AlterExtensionStmt *stmt) ereport(NOTICE, (errmsg("version \"%s\" of extension \"%s\" is already installed", versionName, stmt->extname))); - return InvalidOid; + return InvalidObjectAddress; } /* @@ -2715,7 +2725,9 @@ ExecAlterExtensionStmt(AlterExtensionStmt *stmt) ApplyExtensionUpdates(extensionOid, control, oldVersionName, updateVersions); - return extensionOid; + ObjectAddressSet(address, ExtensionRelationId, extensionOid); + + return address; } /* @@ -2879,9 +2891,15 @@ ApplyExtensionUpdates(Oid extensionOid, /* * Execute ALTER EXTENSION ADD/DROP + * + * Return value is the address of the altered extension. + * + * objAddr is an output argument which, if not NULL, is set to the address of + * the added/dropped object. */ -Oid -ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt) +ObjectAddress +ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt, + ObjectAddress *objAddr) { ObjectAddress extension; ObjectAddress object; @@ -2906,6 +2924,10 @@ ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt) object = get_object_address(stmt->objtype, stmt->objname, stmt->objargs, &relation, ShareUpdateExclusiveLock, false); + Assert(object.objectSubId == 0); + if (objAddr) + *objAddr = object; + /* Permission check: must own target object, too */ check_object_ownership(GetUserId(), stmt->objtype, object, stmt->objname, stmt->objargs, relation); @@ -2984,5 +3006,5 @@ ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt) if (relation != NULL) relation_close(relation, NoLock); - return extension.objectId; + return extension; } |