aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/extension.c
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2015-03-03 14:10:50 -0300
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2015-03-03 14:10:50 -0300
commita2e35b53c39b2a27d3e332dc7c506539c306fd44 (patch)
tree1f4cd33208d33f4a8b3159b0d3757109c67d4b14 /src/backend/commands/extension.c
parent6f9d79904748c26a58991942dc6719db558f77b0 (diff)
downloadpostgresql-a2e35b53c39b2a27d3e332dc7c506539c306fd44.tar.gz
postgresql-a2e35b53c39b2a27d3e332dc7c506539c306fd44.zip
Change many routines to return ObjectAddress rather than OID
The changed routines are mostly those that can be directly called by ProcessUtilitySlow; the intention is to make the affected object information more precise, in support for future event trigger changes. Originally it was envisioned that the OID of the affected object would be enough, and in most cases that is correct, but upon actually implementing the event trigger changes it turned out that ObjectAddress is more widely useful. Additionally, some command execution routines grew an output argument that's an object address which provides further info about the executed command. To wit: * for ALTER DOMAIN / ADD CONSTRAINT, it corresponds to the address of the new constraint * for ALTER OBJECT / SET SCHEMA, it corresponds to the address of the schema that originally contained the object. * for ALTER EXTENSION {ADD, DROP} OBJECT, it corresponds to the address of the object added to or dropped from the extension. There's no user-visible change in this commit, and no functional change either. Discussion: 20150218213255.GC6717@tamriel.snowman.net Reviewed-By: Stephen Frost, Andres Freund
Diffstat (limited to 'src/backend/commands/extension.c')
-rw-r--r--src/backend/commands/extension.c64
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;
}