(Datum) 0,
false,
true,
- false);
+ false,
+ NULL);
elog(DEBUG4, "relation created with OID %u", id);
}
do_end();
char relkind,
Datum relacl,
Datum reloptions);
-static Oid AddNewRelationType(const char *typeName,
+static ObjectAddress AddNewRelationType(const char *typeName,
Oid typeNamespace,
Oid new_rel_oid,
char new_rel_kind,
* define a composite type corresponding to the new relation
* --------------------------------
*/
-static Oid
+static ObjectAddress
AddNewRelationType(const char *typeName,
Oid typeNamespace,
Oid new_rel_oid,
* allow_system_table_mods: TRUE to allow creation in system namespaces
* is_internal: is this a system-generated catalog?
*
+ * Output parameters:
+ * typaddress: if not null, gets the object address of the new pg_type entry
+ *
* Returns the OID of the new relation
* --------------------------------
*/
Datum reloptions,
bool use_user_acl,
bool allow_system_table_mods,
- bool is_internal)
+ bool is_internal,
+ ObjectAddress *typaddress)
{
Relation pg_class_desc;
Relation new_rel_desc;
Oid existing_relid;
Oid old_type_oid;
Oid new_type_oid;
+ ObjectAddress new_type_addr;
Oid new_array_oid = InvalidOid;
pg_class_desc = heap_open(RelationRelationId, RowExclusiveLock);
* creating the same type name in parallel but hadn't committed yet when
* we checked for a duplicate name above.
*/
- new_type_oid = AddNewRelationType(relname,
- relnamespace,
- relid,
- relkind,
- ownerid,
- reltypeid,
- new_array_oid);
+ new_type_addr = AddNewRelationType(relname,
+ relnamespace,
+ relid,
+ relkind,
+ ownerid,
+ reltypeid,
+ new_array_oid);
+ new_type_oid = new_type_addr.objectId;
+ if (typaddress)
+ *typaddress = new_type_addr;
/*
* Now make the array type if wanted.
{ "policy", OBJECT_POLICY }
};
+const ObjectAddress InvalidObjectAddress =
+{
+ InvalidOid,
+ InvalidOid,
+ 0
+};
static ObjectAddress get_object_address_unqualified(ObjectType objtype,
List *qualname, bool missing_ok);
/*
* AggregateCreate
*/
-Oid
+ObjectAddress
AggregateCreate(const char *aggName,
Oid aggNamespace,
char aggKind,
* aggregate. (This could fail if there's already a conflicting entry.)
*/
- procOid = ProcedureCreate(aggName,
- aggNamespace,
- false, /* no replacement */
- false, /* doesn't return a set */
- finaltype, /* returnType */
- GetUserId(), /* proowner */
- INTERNALlanguageId, /* languageObjectId */
- InvalidOid, /* no validator */
- "aggregate_dummy", /* placeholder proc */
- NULL, /* probin */
- true, /* isAgg */
- false, /* isWindowFunc */
- false, /* security invoker (currently not
+ myself = ProcedureCreate(aggName,
+ aggNamespace,
+ false, /* no replacement */
+ false, /* doesn't return a set */
+ finaltype, /* returnType */
+ GetUserId(), /* proowner */
+ INTERNALlanguageId, /* languageObjectId */
+ InvalidOid, /* no validator */
+ "aggregate_dummy", /* placeholder proc */
+ NULL, /* probin */
+ true, /* isAgg */
+ false, /* isWindowFunc */
+ false, /* security invoker (currently not
* definable for agg) */
- false, /* isLeakProof */
- false, /* isStrict (not needed for agg) */
- PROVOLATILE_IMMUTABLE, /* volatility (not
+ false, /* isLeakProof */
+ false, /* isStrict (not needed for agg) */
+ PROVOLATILE_IMMUTABLE, /* volatility (not
* needed for agg) */
- parameterTypes, /* paramTypes */
- allParameterTypes, /* allParamTypes */
- parameterModes, /* parameterModes */
- parameterNames, /* parameterNames */
- parameterDefaults, /* parameterDefaults */
- PointerGetDatum(NULL), /* proconfig */
- 1, /* procost */
- 0); /* prorows */
+ parameterTypes, /* paramTypes */
+ allParameterTypes, /* allParamTypes */
+ parameterModes, /* parameterModes */
+ parameterNames, /* parameterNames */
+ parameterDefaults, /* parameterDefaults */
+ PointerGetDatum(NULL), /* proconfig */
+ 1, /* procost */
+ 0); /* prorows */
+ procOid = myself.objectId;
/*
* Okay to create the pg_aggregate entry.
* on aggTransType since we depend on it indirectly through transfn.
* Likewise for aggmTransType if any.
*/
- myself.classId = ProcedureRelationId;
- myself.objectId = procOid;
- myself.objectSubId = 0;
/* Depends on transition function */
referenced.classId = ProcedureRelationId;
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
}
- return procOid;
+ return myself;
}
/*
*
* Add a new tuple to pg_conversion.
*/
-Oid
+ObjectAddress
ConversionCreate(const char *conname, Oid connamespace,
Oid conowner,
int32 conforencoding, int32 contoencoding,
heap_freetuple(tup);
heap_close(rel, RowExclusiveLock);
- return oid;
+ return myself;
}
/*
Oid leftTypeId, Oid rightTypeId,
bool isCommutator);
-static void makeOperatorDependencies(HeapTuple tuple);
+static ObjectAddress makeOperatorDependencies(HeapTuple tuple);
/*
* Forward declaration is used only for this purpose, it is
* not available to the user as it is for type definition.
*/
-Oid
+ObjectAddress
OperatorCreate(const char *operatorName,
Oid operatorNamespace,
Oid leftTypeId,
NameData oname;
TupleDesc tupDesc;
int i;
+ ObjectAddress address;
/*
* Sanity checks
CatalogUpdateIndexes(pg_operator_desc, tup);
/* Add dependencies for the entry */
- makeOperatorDependencies(tup);
+ address = makeOperatorDependencies(tup);
/* Post creation hook for new operator */
InvokeObjectPostCreateHook(OperatorRelationId, operatorObjectId, 0);
if (OidIsValid(commutatorId) || OidIsValid(negatorId))
OperatorUpd(operatorObjectId, commutatorId, negatorId);
- return operatorObjectId;
+ return address;
}
/*
* NB: the OidIsValid tests in this routine are necessary, in case
* the given operator is a shell.
*/
-static void
+static ObjectAddress
makeOperatorDependencies(HeapTuple tuple)
{
Form_pg_operator oper = (Form_pg_operator) GETSTRUCT(tuple);
/* Dependency on extension */
recordDependencyOnCurrentExtension(&myself, true);
+
+ return myself;
}
* not "ArrayType *", to avoid importing array.h into pg_proc_fn.h.
* ----------------------------------------------------------------
*/
-Oid
+ObjectAddress
ProcedureCreate(const char *procedureName,
Oid procNamespace,
bool replace,
AtEOXact_GUC(true, save_nestlevel);
}
- return retval;
+ return myself;
}
* with correct ones, and "typisdefined" will be set to true.
* ----------------------------------------------------------------
*/
-Oid
+ObjectAddress
TypeShellMake(const char *typeName, Oid typeNamespace, Oid ownerId)
{
Relation pg_type_desc;
bool nulls[Natts_pg_type];
Oid typoid;
NameData name;
+ ObjectAddress address;
Assert(PointerIsValid(typeName));
/* Post creation hook for new shell type */
InvokeObjectPostCreateHook(TypeRelationId, typoid, 0);
+ ObjectAddressSet(address, TypeRelationId, typoid);
+
/*
* clean up and return the type-oid
*/
heap_freetuple(tup);
heap_close(pg_type_desc, RowExclusiveLock);
- return typoid;
+ return address;
}
/* ----------------------------------------------------------------
*
* This does all the necessary work needed to define a new type.
*
- * Returns the OID assigned to the new type. If newTypeOid is
- * zero (the normal case), a new OID is created; otherwise we
- * use exactly that OID.
+ * Returns the ObjectAddress assigned to the new type.
+ * If newTypeOid is zero (the normal case), a new OID is created;
+ * otherwise we use exactly that OID.
* ----------------------------------------------------------------
*/
-Oid
+ObjectAddress
TypeCreate(Oid newTypeOid,
const char *typeName,
Oid typeNamespace,
NameData name;
int i;
Acl *typacl = NULL;
+ ObjectAddress address;
/*
* We assume that the caller validated the arguments individually, but did
/* Post creation hook for new type */
InvokeObjectPostCreateHook(TypeRelationId, typeObjectId, 0);
+ ObjectAddressSet(address, TypeRelationId, typeObjectId);
+
/*
* finish up
*/
heap_close(pg_type_desc, RowExclusiveLock);
- return typeObjectId;
+ return address;
}
/*
reloptions,
false,
true,
- true);
+ true,
+ NULL);
Assert(toast_relid != InvalidOid);
/* make the toast relation visible, else heap_open will fail */
* isn't an ordered-set aggregate.
* "parameters" is a list of DefElem representing the agg's definition clauses.
*/
-Oid
+ObjectAddress
DefineAggregate(List *name, List *args, bool oldstyle, List *parameters,
const char *queryString)
{
/*
* Executes an ALTER OBJECT / RENAME TO statement. Based on the object
* type, the function appropriate to that type is executed.
+ *
+ * Return value is the address of the renamed object.
*/
-Oid
+ObjectAddress
ExecRenameStmt(RenameStmt *stmt)
{
switch (stmt->renameType)
stmt->newname);
heap_close(catalog, RowExclusiveLock);
- return address.objectId;
+ return address;
}
default:
elog(ERROR, "unrecognized rename stmt type: %d",
(int) stmt->renameType);
- return InvalidOid; /* keep compiler happy */
+ return InvalidObjectAddress; /* keep compiler happy */
}
}
/*
* Executes an ALTER OBJECT / SET SCHEMA statement. Based on the object
* type, the function appropriate to that type is executed.
+ *
+ * Return value is that of the altered object.
+ *
+ * oldSchemaAddr is an output argument which, if not NULL, is set to the object
+ * address of the original schema.
*/
-Oid
-ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt)
+ObjectAddress
+ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt,
+ ObjectAddress *oldSchemaAddr)
{
+ ObjectAddress address;
+ Oid oldNspOid;
+
switch (stmt->objectType)
{
case OBJECT_EXTENSION:
- return AlterExtensionNamespace(stmt->object, stmt->newschema);
+ address = AlterExtensionNamespace(stmt->object, stmt->newschema,
+ oldSchemaAddr ? &oldNspOid : NULL);
+ break;
case OBJECT_FOREIGN_TABLE:
case OBJECT_SEQUENCE:
case OBJECT_TABLE:
case OBJECT_VIEW:
case OBJECT_MATVIEW:
- return AlterTableNamespace(stmt);
+ address = AlterTableNamespace(stmt,
+ oldSchemaAddr ? &oldNspOid : NULL);
+ break;
case OBJECT_DOMAIN:
case OBJECT_TYPE:
- return AlterTypeNamespace(stmt->object, stmt->newschema,
- stmt->objectType);
+ address = AlterTypeNamespace(stmt->object, stmt->newschema,
+ stmt->objectType,
+ oldSchemaAddr ? &oldNspOid : NULL);
+ break;
/* generic code path */
case OBJECT_AGGREGATE:
catalog = heap_open(classId, RowExclusiveLock);
nspOid = LookupCreationNamespace(stmt->newschema);
- AlterObjectNamespace_internal(catalog, address.objectId,
- nspOid);
+ oldNspOid = AlterObjectNamespace_internal(catalog, address.objectId,
+ nspOid);
heap_close(catalog, RowExclusiveLock);
-
- return address.objectId;
}
break;
default:
elog(ERROR, "unrecognized AlterObjectSchemaStmt type: %d",
(int) stmt->objectType);
- return InvalidOid; /* keep compiler happy */
+ return InvalidObjectAddress; /* keep compiler happy */
}
+
+ if (oldSchemaAddr)
+ ObjectAddressSet(*oldSchemaAddr, NamespaceRelationId, oldNspOid);
+
+ return address;
}
/*
* Executes an ALTER OBJECT / OWNER TO statement. Based on the object
* type, the function appropriate to that type is executed.
*/
-Oid
+ObjectAddress
ExecAlterOwnerStmt(AlterOwnerStmt *stmt)
{
Oid newowner = get_role_oid(stmt->newowner, false);
AlterObjectOwner_internal(catalog, address.objectId, newowner);
heap_close(catalog, RowExclusiveLock);
- return address.objectId;
+ return address;
}
break;
default:
elog(ERROR, "unrecognized AlterOwnerStmt type: %d",
(int) stmt->objectType);
-
- return InvalidOid; /* keep compiler happy */
+ return InvalidObjectAddress; /* keep compiler happy */
}
}
reloptions,
false,
true,
- true);
+ true,
+ NULL);
Assert(OIDNewHeap != InvalidOid);
ReleaseSysCache(tuple);
/*
* CREATE COLLATION
*/
-Oid
+ObjectAddress
DefineCollation(List *names, List *parameters)
{
char *collName;
char *collcollate = NULL;
char *collctype = NULL;
Oid newoid;
+ ObjectAddress address;
collNamespace = QualifiedNameGetCreationNamespace(names, &collName);
collcollate,
collctype);
+ ObjectAddressSet(address, CollationRelationId, newoid);
+
/* check that the locales can be loaded */
CommandCounterIncrement();
(void) pg_newlocale_from_collation(newoid);
- return newoid;
+ return address;
}
/*
* This routine is used to add the associated comment into
* pg_description for the object specified by the given SQL command.
*/
-Oid
+ObjectAddress
CommentObject(CommentStmt *stmt)
{
- ObjectAddress address;
Relation relation;
+ ObjectAddress address = InvalidObjectAddress;
/*
* When loading a dump, we may see a COMMENT ON DATABASE for the old name
ereport(WARNING,
(errcode(ERRCODE_UNDEFINED_DATABASE),
errmsg("database \"%s\" does not exist", database)));
- return InvalidOid;
+ return address;
}
}
if (relation != NULL)
relation_close(relation, NoLock);
- return address.objectId;
+ return address;
}
/*
/*
* CREATE CONVERSION
*/
-Oid
+ObjectAddress
CreateConversionCommand(CreateConversionStmt *stmt)
{
Oid namespaceId;
BulkInsertState bistate; /* bulk insert state */
} DR_intorel;
-/* the OID of the created table, for ExecCreateTableAs consumption */
-static Oid CreateAsRelid = InvalidOid;
+/* the address of the created table, for ExecCreateTableAs consumption */
+static ObjectAddress CreateAsReladdr = {InvalidOid, InvalidOid, 0};
static void intorel_startup(DestReceiver *self, int operation, TupleDesc typeinfo);
static void intorel_receive(TupleTableSlot *slot, DestReceiver *self);
/*
* ExecCreateTableAs -- execute a CREATE TABLE AS command
*/
-Oid
+ObjectAddress
ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString,
ParamListInfo params, char *completionTag)
{
Oid save_userid = InvalidOid;
int save_sec_context = 0;
int save_nestlevel = 0;
- Oid relOid;
+ ObjectAddress address;
List *rewritten;
PlannedStmt *plan;
QueryDesc *queryDesc;
(errcode(ERRCODE_DUPLICATE_TABLE),
errmsg("relation \"%s\" already exists, skipping",
stmt->into->rel->relname)));
- return InvalidOid;
+ return InvalidObjectAddress;
}
}
Assert(!is_matview); /* excluded by syntax */
ExecuteQuery(estmt, into, queryString, params, dest, completionTag);
- relOid = CreateAsRelid;
- CreateAsRelid = InvalidOid;
- return relOid;
+ address = CreateAsReladdr;
+ CreateAsReladdr = InvalidObjectAddress;
+ return address;
}
Assert(query->commandType == CMD_SELECT);
SetUserIdAndSecContext(save_userid, save_sec_context);
}
- relOid = CreateAsRelid;
- CreateAsRelid = InvalidOid;
+ address = CreateAsReladdr;
+ CreateAsReladdr = InvalidObjectAddress;
- return relOid;
+ return address;
}
/*
bool is_matview;
char relkind;
CreateStmt *create;
- Oid intoRelationId;
+ ObjectAddress intoRelationAddr;
Relation intoRelationDesc;
RangeTblEntry *rte;
Datum toast_options;
/*
* Actually create the target table
*/
- intoRelationId = DefineRelation(create, relkind, InvalidOid);
+ intoRelationAddr = DefineRelation(create, relkind, InvalidOid, NULL);
/*
* If necessary, create a TOAST table for the target table. Note that
(void) heap_reloptions(RELKIND_TOASTVALUE, toast_options, true);
- NewRelationCreateToastTable(intoRelationId, toast_options);
+ NewRelationCreateToastTable(intoRelationAddr.objectId, toast_options);
/* Create the "view" part of a materialized view. */
if (is_matview)
/* StoreViewQuery scribbles on tree, so make a copy */
Query *query = (Query *) copyObject(into->viewQuery);
- StoreViewQuery(intoRelationId, query, false);
+ StoreViewQuery(intoRelationAddr.objectId, query, false);
CommandCounterIncrement();
}
/*
* Finally we can open the target table
*/
- intoRelationDesc = heap_open(intoRelationId, AccessExclusiveLock);
+ intoRelationDesc = heap_open(intoRelationAddr.objectId, AccessExclusiveLock);
/*
* Check INSERT permission on the constructed table.
*/
rte = makeNode(RangeTblEntry);
rte->rtekind = RTE_RELATION;
- rte->relid = intoRelationId;
+ rte->relid = intoRelationAddr.objectId;
rte->relkind = relkind;
rte->requiredPerms = ACL_INSERT;
* be enabled here. We don't actually support that currently, so throw
* our own ereport(ERROR) if that happens.
*/
- if (check_enable_rls(intoRelationId, InvalidOid, false) == RLS_ENABLED)
+ if (check_enable_rls(intoRelationAddr.objectId, InvalidOid, false) == RLS_ENABLED)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
(errmsg("policies not yet implemented for this command"))));
myState->rel = intoRelationDesc;
myState->output_cid = GetCurrentCommandId(true);
- /* and remember the new relation's OID for ExecCreateTableAs */
- CreateAsRelid = RelationGetRelid(myState->rel);
+ /* and remember the new relation's address for ExecCreateTableAs */
+ CreateAsReladdr = intoRelationAddr;
/*
* We can skip WAL-logging the insertions, unless PITR or streaming
/*
* Rename database
*/
-Oid
+ObjectAddress
RenameDatabase(const char *oldname, const char *newname)
{
Oid db_id;
Relation rel;
int notherbackends;
int npreparedxacts;
+ ObjectAddress address;
/*
* Look up the target database's OID, and get exclusive lock on it. We
InvokeObjectPostAlterHook(DatabaseRelationId, db_id, 0);
+ ObjectAddressSet(address, DatabaseRelationId, db_id);
+
/*
* Close pg_database, but keep lock till commit.
*/
heap_close(rel, NoLock);
- return db_id;
+ return address;
}
/*
* ALTER DATABASE name OWNER TO newowner
*/
-Oid
+ObjectAddress
AlterDatabaseOwner(const char *dbname, Oid newOwnerId)
{
Oid db_id;
ScanKeyData scankey;
SysScanDesc scan;
Form_pg_database datForm;
+ ObjectAddress address;
/*
* Get the old tuple. We don't need a lock on the database per se,
InvokeObjectPostAlterHook(DatabaseRelationId, HeapTupleGetOid(tuple), 0);
+ ObjectAddressSet(address, DatabaseRelationId, db_id);
+
systable_endscan(scan);
/* Close pg_database, but keep lock till commit */
heap_close(rel, NoLock);
- return db_id;
+ return address;
}
/*
* Change event trigger's owner -- by name
*/
-Oid
+ObjectAddress
AlterEventTriggerOwner(const char *name, Oid newOwnerId)
{
Oid evtOid;
HeapTuple tup;
Relation rel;
+ ObjectAddress address;
rel = heap_open(EventTriggerRelationId, RowExclusiveLock);
AlterEventTriggerOwner_internal(rel, tup, newOwnerId);
+ ObjectAddressSet(address, EventTriggerRelationId, evtOid);
+
heap_freetuple(tup);
heap_close(rel, RowExclusiveLock);
- return evtOid;
+ return address;
}
/*
/*
* CREATE EXTENSION
*/
-Oid
+ObjectAddress
CreateExtension(CreateExtensionStmt *stmt)
{
DefElem *d_schema = NULL;
List *requiredSchemas;
Oid extensionOid;
ListCell *lc;
+ ObjectAddress address;
/* Check extension name validity before any filesystem access */
check_valid_extension_name(stmt->extname);
(errcode(ERRCODE_DUPLICATE_OBJECT),
errmsg("extension \"%s\" already exists, skipping",
stmt->extname)));
- return InvalidOid;
+ return InvalidObjectAddress;
}
else
ereport(ERROR,
/*
* 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
ApplyExtensionUpdates(extensionOid, pcontrol,
versionName, updateVersions);
- return extensionOid;
+ return address;
}
/*
* 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,
/* Post creation hook for new extension */
InvokeObjectPostCreateHook(ExtensionRelationId, extensionOid, 0);
- return extensionOid;
+ return myself;
}
/*
/*
* 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;
SysScanDesc depScan;
HeapTuple depTup;
ObjectAddresses *objsMoved;
+ ObjectAddress extAddr;
if (list_length(names) != 1)
ereport(ERROR,
if (extForm->extnamespace == nspOid)
{
heap_close(extRel, RowExclusiveLock);
- return InvalidOid;
+ return InvalidObjectAddress;
}
/* Check extension is supposed to be relocatable */
get_namespace_name(oldNspOid))));
}
+ /* report old schema, if caller wants it */
+ if (oldschema)
+ *oldschema = oldNspOid;
+
systable_endscan(depScan);
relation_close(depRel, AccessShareLock);
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;
Datum datum;
bool isnull;
ListCell *lc;
+ ObjectAddress address;
/*
* We use global variables to track the extension being created, so we can
ereport(NOTICE,
(errmsg("version \"%s\" of extension \"%s\" is already installed",
versionName, stmt->extname)));
- return InvalidOid;
+ return InvalidObjectAddress;
}
/*
ApplyExtensionUpdates(extensionOid, control,
oldVersionName, updateVersions);
- return extensionOid;
+ ObjectAddressSet(address, ExtensionRelationId, extensionOid);
+
+ return address;
}
/*
/*
* 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;
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);
if (relation != NULL)
relation_close(relation, NoLock);
- return extension.objectId;
+ return extension;
}
*
* Note restrictions in the "_internal" function, above.
*/
-Oid
+ObjectAddress
AlterForeignDataWrapperOwner(const char *name, Oid newOwnerId)
{
Oid fdwId;
HeapTuple tup;
Relation rel;
+ ObjectAddress address;
rel = heap_open(ForeignDataWrapperRelationId, RowExclusiveLock);
AlterForeignDataWrapperOwner_internal(rel, tup, newOwnerId);
+ ObjectAddressSet(address, ForeignDataWrapperRelationId, fdwId);
+
heap_freetuple(tup);
heap_close(rel, RowExclusiveLock);
- return fdwId;
+ return address;
}
/*
/*
* Change foreign server owner -- by name
*/
-Oid
+ObjectAddress
AlterForeignServerOwner(const char *name, Oid newOwnerId)
{
Oid servOid;
HeapTuple tup;
Relation rel;
+ ObjectAddress address;
rel = heap_open(ForeignServerRelationId, RowExclusiveLock);
AlterForeignServerOwner_internal(rel, tup, newOwnerId);
+ ObjectAddressSet(address, ForeignServerRelationId, servOid);
+
heap_freetuple(tup);
heap_close(rel, RowExclusiveLock);
- return servOid;
+ return address;
}
/*
/*
* Create a foreign-data wrapper
*/
-Oid
+ObjectAddress
CreateForeignDataWrapper(CreateFdwStmt *stmt)
{
Relation rel;
heap_close(rel, RowExclusiveLock);
- return fdwId;
+ return myself;
}
/*
* Alter foreign-data wrapper
*/
-Oid
+ObjectAddress
AlterForeignDataWrapper(AlterFdwStmt *stmt)
{
Relation rel;
bool validator_given;
Oid fdwhandler;
Oid fdwvalidator;
+ ObjectAddress myself;
rel = heap_open(ForeignDataWrapperRelationId, RowExclusiveLock);
heap_freetuple(tp);
+ ObjectAddressSet(myself, ForeignDataWrapperRelationId, fdwId);
+
/* Update function dependencies if we changed them */
if (handler_given || validator_given)
{
- ObjectAddress myself;
ObjectAddress referenced;
/*
DEPENDENCY_NORMAL);
/* And build new ones. */
- myself.classId = ForeignDataWrapperRelationId;
- myself.objectId = fdwId;
- myself.objectSubId = 0;
if (OidIsValid(fdwhandler))
{
heap_close(rel, RowExclusiveLock);
- return fdwId;
+ return myself;
}
/*
* Create a foreign server
*/
-Oid
+ObjectAddress
CreateForeignServer(CreateForeignServerStmt *stmt)
{
Relation rel;
heap_close(rel, RowExclusiveLock);
- return srvId;
+ return myself;
}
/*
* Alter foreign server
*/
-Oid
+ObjectAddress
AlterForeignServer(AlterForeignServerStmt *stmt)
{
Relation rel;
bool repl_repl[Natts_pg_foreign_server];
Oid srvId;
Form_pg_foreign_server srvForm;
+ ObjectAddress address;
rel = heap_open(ForeignServerRelationId, RowExclusiveLock);
InvokeObjectPostAlterHook(ForeignServerRelationId, srvId, 0);
+ ObjectAddressSet(address, ForeignServerRelationId, srvId);
+
heap_freetuple(tp);
heap_close(rel, RowExclusiveLock);
- return srvId;
+ return address;
}
/*
* Create user mapping
*/
-Oid
+ObjectAddress
CreateUserMapping(CreateUserMappingStmt *stmt)
{
Relation rel;
heap_close(rel, RowExclusiveLock);
- return umId;
+ return myself;
}
/*
* Alter user mapping
*/
-Oid
+ObjectAddress
AlterUserMapping(AlterUserMappingStmt *stmt)
{
Relation rel;
Oid useId;
Oid umId;
ForeignServer *srv;
+ ObjectAddress address;
rel = heap_open(UserMappingRelationId, RowExclusiveLock);
simple_heap_update(rel, &tp->t_self, tp);
CatalogUpdateIndexes(rel, tp);
+ ObjectAddressSet(address, UserMappingRelationId, umId);
+
heap_freetuple(tp);
heap_close(rel, RowExclusiveLock);
- return umId;
+ return address;
}
Oid namespaceId;
AclResult aclresult;
char *typname;
+ ObjectAddress address;
/*
* Only C-coded functions can be I/O functions. We enforce this
if (aclresult != ACLCHECK_OK)
aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
get_namespace_name(namespaceId));
- rettype = TypeShellMake(typname, namespaceId, GetUserId());
+ address = TypeShellMake(typname, namespaceId, GetUserId());
+ rettype = address.objectId;
Assert(OidIsValid(rettype));
}
* CreateFunction
* Execute a CREATE FUNCTION utility statement.
*/
-Oid
+ObjectAddress
CreateFunction(CreateFunctionStmt *stmt, const char *queryString)
{
char *probin_str;
* RENAME and OWNER clauses, which are handled as part of the generic
* ALTER framework).
*/
-Oid
+ObjectAddress
AlterFunction(AlterFunctionStmt *stmt)
{
HeapTuple tup;
List *set_items = NIL;
DefElem *cost_item = NULL;
DefElem *rows_item = NULL;
+ ObjectAddress address;
rel = heap_open(ProcedureRelationId, RowExclusiveLock);
InvokeObjectPostAlterHook(ProcedureRelationId, funcOid, 0);
+ ObjectAddressSet(address, ProcedureRelationId, funcOid);
+
heap_close(rel, NoLock);
heap_freetuple(tup);
- return funcOid;
+ return address;
}
/*
/*
* CREATE CAST
*/
-Oid
+ObjectAddress
CreateCast(CreateCastStmt *stmt)
{
Oid sourcetypeid;
heap_close(relation, RowExclusiveLock);
- return castid;
+ return myself;
}
/*
* it will be filled later.
* 'quiet': suppress the NOTICE chatter ordinarily provided for constraints.
*
- * Returns the OID of the created index.
+ * Returns the object address of the created index.
*/
-Oid
+ObjectAddress
DefineIndex(Oid relationId,
IndexStmt *stmt,
Oid indexRelationId,
int numberOfAttributes;
TransactionId limitXmin;
VirtualTransactionId *old_snapshots;
+ ObjectAddress address;
int n_old_snapshots;
LockRelId heaprelid;
LOCKTAG heaplocktag;
stmt->concurrent, !check_rights,
stmt->if_not_exists);
+ ObjectAddressSet(address, RelationRelationId, indexRelationId);
+
if (!OidIsValid(indexRelationId))
{
heap_close(rel, NoLock);
- return indexRelationId;
+ return address;
}
/* Add any requested comment */
{
/* Close the heap and we're done, in the non-concurrent case */
heap_close(rel, NoLock);
- return indexRelationId;
+ return address;
}
/* save lockrelid and locktag for below, then close rel */
*/
UnlockRelationIdForSession(&heaprelid, ShareUpdateExclusiveLock);
- return indexRelationId;
+ return address;
}
* The matview's "populated" state is changed based on whether the contents
* reflect the result set of the materialized view's query.
*/
-Oid
+ObjectAddress
ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString,
ParamListInfo params, char *completionTag)
{
Oid save_userid;
int save_sec_context;
int save_nestlevel;
+ ObjectAddress address;
/* Determine strength of lock needed. */
concurrent = stmt->concurrent;
/* Restore userid and security context */
SetUserIdAndSecContext(save_userid, save_sec_context);
- return matviewOid;
+ ObjectAddressSet(address, RelationRelationId, matviewOid);
+
+ return address;
}
/*
*
* Caller must have done permissions checks etc. already.
*/
-static Oid
+static ObjectAddress
CreateOpFamily(char *amname, char *opfname, Oid namespaceoid, Oid amoid)
{
Oid opfamilyoid;
heap_close(rel, RowExclusiveLock);
- return opfamilyoid;
+ return myself;
}
/*
* DefineOpClass
* Define a new index operator class.
*/
-Oid
+ObjectAddress
DefineOpClass(CreateOpClassStmt *stmt)
{
char *opcname; /* name of opclass we're creating */
}
else
{
+ ObjectAddress tmpAddr;
+
/*
* Create it ... again no need for more permissions ...
*/
- opfamilyoid = CreateOpFamily(stmt->amname, opcname,
- namespaceoid, amoid);
+ tmpAddr = CreateOpFamily(stmt->amname, opcname,
+ namespaceoid, amoid);
+ opfamilyoid = tmpAddr.objectId;
}
}
heap_close(rel, RowExclusiveLock);
- return opclassoid;
+ return myself;
}
* DefineOpFamily
* Define a new index operator family.
*/
-Oid
+ObjectAddress
DefineOpFamily(CreateOpFamilyStmt *stmt)
{
char *opfname; /* name of opfamily we're creating */
*
* 'parameters' is a list of DefElem
*/
-Oid
+ObjectAddress
DefineOperator(List *names, List *parameters)
{
char *oprName;
*
* stmt - the CreatePolicyStmt that describes the policy to create.
*/
-Oid
+ObjectAddress
CreatePolicy(CreatePolicyStmt *stmt)
{
Relation pg_policy_rel;
relation_close(target_table, NoLock);
heap_close(pg_policy_rel, RowExclusiveLock);
- return policy_id;
+ return myself;
}
/*
*
* stmt - the AlterPolicyStmt that describes the policy and how to alter it.
*/
-Oid
+ObjectAddress
AlterPolicy(AlterPolicyStmt *stmt)
{
Relation pg_policy_rel;
relation_close(target_table, NoLock);
heap_close(pg_policy_rel, RowExclusiveLock);
- return policy_id;
+ return myself;
}
/*
* rename_policy -
* change the name of a policy on a relation
*/
-Oid
+ObjectAddress
rename_policy(RenameStmt *stmt)
{
Relation pg_policy_rel;
ScanKeyData skey[2];
SysScanDesc sscan;
HeapTuple policy_tuple;
+ ObjectAddress address;
/* Get id of table. Also handles permissions checks. */
table_id = RangeVarGetRelidExtended(stmt->relation, AccessExclusiveLock,
InvokeObjectPostAlterHook(PolicyRelationId,
HeapTupleGetOid(policy_tuple), 0);
+ ObjectAddressSet(address, PolicyRelationId, opoloid);
+
/*
* Invalidate relation's relcache entry so that other backends (and
* this one too!) are sent SI message to make them rebuild relcache
heap_close(pg_policy_rel, RowExclusiveLock);
relation_close(target_table, NoLock);
- return opoloid;
+ return address;
}
/*
char *tmpllibrary; /* path of shared library */
} PLTemplate;
-static Oid create_proc_lang(const char *languageName, bool replace,
+static ObjectAddress create_proc_lang(const char *languageName, bool replace,
Oid languageOwner, Oid handlerOid, Oid inlineOid,
Oid valOid, bool trusted);
static PLTemplate *find_language_template(const char *languageName);
* CREATE PROCEDURAL LANGUAGE
* ---------------------------------------------------------------------
*/
-Oid
+ObjectAddress
CreateProceduralLanguage(CreatePLangStmt *stmt)
{
PLTemplate *pltemplate;
+ ObjectAddress tmpAddr;
Oid handlerOid,
inlineOid,
valOid;
}
else
{
- handlerOid = ProcedureCreate(pltemplate->tmplhandler,
- PG_CATALOG_NAMESPACE,
- false, /* replace */
- false, /* returnsSet */
- LANGUAGE_HANDLEROID,
- BOOTSTRAP_SUPERUSERID,
- ClanguageId,
- F_FMGR_C_VALIDATOR,
- pltemplate->tmplhandler,
- pltemplate->tmpllibrary,
- false, /* isAgg */
- false, /* isWindowFunc */
- false, /* security_definer */
- false, /* isLeakProof */
- false, /* isStrict */
- PROVOLATILE_VOLATILE,
- buildoidvector(funcargtypes, 0),
- PointerGetDatum(NULL),
- PointerGetDatum(NULL),
- PointerGetDatum(NULL),
- NIL,
- PointerGetDatum(NULL),
- 1,
- 0);
+ tmpAddr = ProcedureCreate(pltemplate->tmplhandler,
+ PG_CATALOG_NAMESPACE,
+ false, /* replace */
+ false, /* returnsSet */
+ LANGUAGE_HANDLEROID,
+ BOOTSTRAP_SUPERUSERID,
+ ClanguageId,
+ F_FMGR_C_VALIDATOR,
+ pltemplate->tmplhandler,
+ pltemplate->tmpllibrary,
+ false, /* isAgg */
+ false, /* isWindowFunc */
+ false, /* security_definer */
+ false, /* isLeakProof */
+ false, /* isStrict */
+ PROVOLATILE_VOLATILE,
+ buildoidvector(funcargtypes, 0),
+ PointerGetDatum(NULL),
+ PointerGetDatum(NULL),
+ PointerGetDatum(NULL),
+ NIL,
+ PointerGetDatum(NULL),
+ 1,
+ 0);
+ handlerOid = tmpAddr.objectId;
}
/*
inlineOid = LookupFuncName(funcname, 1, funcargtypes, true);
if (!OidIsValid(inlineOid))
{
- inlineOid = ProcedureCreate(pltemplate->tmplinline,
- PG_CATALOG_NAMESPACE,
- false, /* replace */
- false, /* returnsSet */
- VOIDOID,
- BOOTSTRAP_SUPERUSERID,
- ClanguageId,
- F_FMGR_C_VALIDATOR,
- pltemplate->tmplinline,
- pltemplate->tmpllibrary,
- false, /* isAgg */
- false, /* isWindowFunc */
- false, /* security_definer */
- false, /* isLeakProof */
- true, /* isStrict */
- PROVOLATILE_VOLATILE,
- buildoidvector(funcargtypes, 1),
- PointerGetDatum(NULL),
- PointerGetDatum(NULL),
- PointerGetDatum(NULL),
- NIL,
- PointerGetDatum(NULL),
- 1,
- 0);
+ tmpAddr = ProcedureCreate(pltemplate->tmplinline,
+ PG_CATALOG_NAMESPACE,
+ false, /* replace */
+ false, /* returnsSet */
+ VOIDOID,
+ BOOTSTRAP_SUPERUSERID,
+ ClanguageId,
+ F_FMGR_C_VALIDATOR,
+ pltemplate->tmplinline,
+ pltemplate->tmpllibrary,
+ false, /* isAgg */
+ false, /* isWindowFunc */
+ false, /* security_definer */
+ false, /* isLeakProof */
+ true, /* isStrict */
+ PROVOLATILE_VOLATILE,
+ buildoidvector(funcargtypes, 1),
+ PointerGetDatum(NULL),
+ PointerGetDatum(NULL),
+ PointerGetDatum(NULL),
+ NIL,
+ PointerGetDatum(NULL),
+ 1,
+ 0);
+ inlineOid = tmpAddr.objectId;
}
}
else
valOid = LookupFuncName(funcname, 1, funcargtypes, true);
if (!OidIsValid(valOid))
{
- valOid = ProcedureCreate(pltemplate->tmplvalidator,
- PG_CATALOG_NAMESPACE,
- false, /* replace */
- false, /* returnsSet */
- VOIDOID,
- BOOTSTRAP_SUPERUSERID,
- ClanguageId,
- F_FMGR_C_VALIDATOR,
- pltemplate->tmplvalidator,
- pltemplate->tmpllibrary,
- false, /* isAgg */
- false, /* isWindowFunc */
- false, /* security_definer */
- false, /* isLeakProof */
- true, /* isStrict */
- PROVOLATILE_VOLATILE,
- buildoidvector(funcargtypes, 1),
- PointerGetDatum(NULL),
- PointerGetDatum(NULL),
- PointerGetDatum(NULL),
- NIL,
- PointerGetDatum(NULL),
- 1,
- 0);
+ tmpAddr = ProcedureCreate(pltemplate->tmplvalidator,
+ PG_CATALOG_NAMESPACE,
+ false, /* replace */
+ false, /* returnsSet */
+ VOIDOID,
+ BOOTSTRAP_SUPERUSERID,
+ ClanguageId,
+ F_FMGR_C_VALIDATOR,
+ pltemplate->tmplvalidator,
+ pltemplate->tmpllibrary,
+ false, /* isAgg */
+ false, /* isWindowFunc */
+ false, /* security_definer */
+ false, /* isLeakProof */
+ true, /* isStrict */
+ PROVOLATILE_VOLATILE,
+ buildoidvector(funcargtypes, 1),
+ PointerGetDatum(NULL),
+ PointerGetDatum(NULL),
+ PointerGetDatum(NULL),
+ NIL,
+ PointerGetDatum(NULL),
+ 1,
+ 0);
+ valOid = tmpAddr.objectId;
}
}
else
/*
* Guts of language creation.
*/
-static Oid
+static ObjectAddress
create_proc_lang(const char *languageName, bool replace,
Oid languageOwner, Oid handlerOid, Oid inlineOid,
Oid valOid, bool trusted)
heap_close(rel, RowExclusiveLock);
- return myself.objectId;
+ return myself;
}
/*
/*
* Rename schema
*/
-Oid
+ObjectAddress
RenameSchema(const char *oldname, const char *newname)
{
Oid nspOid;
HeapTuple tup;
Relation rel;
AclResult aclresult;
+ ObjectAddress address;
rel = heap_open(NamespaceRelationId, RowExclusiveLock);
InvokeObjectPostAlterHook(NamespaceRelationId, HeapTupleGetOid(tup), 0);
+ ObjectAddressSet(address, NamespaceRelationId, nspOid);
+
heap_close(rel, NoLock);
heap_freetuple(tup);
- return nspOid;
+ return address;
}
void
/*
* Change schema owner
*/
-Oid
+ObjectAddress
AlterSchemaOwner(const char *name, Oid newOwnerId)
{
Oid nspOid;
HeapTuple tup;
Relation rel;
+ ObjectAddress address;
rel = heap_open(NamespaceRelationId, RowExclusiveLock);
AlterSchemaOwner_internal(tup, rel, newOwnerId);
+ ObjectAddressSet(address, NamespaceRelationId, nspOid);
+
ReleaseSysCache(tup);
heap_close(rel, RowExclusiveLock);
- return nspOid;
+ return address;
}
static void
* ExecSecLabelStmt --
*
* Apply a security label to a database object.
+ *
+ * Returns the ObjectAddress of the object to which the policy was applied.
*/
-Oid
+ObjectAddress
ExecSecLabelStmt(SecLabelStmt *stmt)
{
LabelProvider *provider = NULL;
if (relation != NULL)
relation_close(relation, NoLock);
- return address.objectId;
+ return address;
}
/*
* DefineSequence
* Creates a new sequence relation
*/
-Oid
+ObjectAddress
DefineSequence(CreateSeqStmt *seq)
{
FormData_pg_sequence new;
List *owned_by;
CreateStmt *stmt = makeNode(CreateStmt);
Oid seqoid;
+ ObjectAddress address;
Relation rel;
HeapTuple tuple;
TupleDesc tupDesc;
(errcode(ERRCODE_DUPLICATE_TABLE),
errmsg("relation \"%s\" already exists, skipping",
seq->sequence->relname)));
- return InvalidOid;
+ return InvalidObjectAddress;
}
}
stmt->tablespacename = NULL;
stmt->if_not_exists = seq->if_not_exists;
- seqoid = DefineRelation(stmt, RELKIND_SEQUENCE, seq->ownerId);
+ address = DefineRelation(stmt, RELKIND_SEQUENCE, seq->ownerId, NULL);
+ seqoid = address.objectId;
Assert(seqoid != InvalidOid);
rel = heap_open(seqoid, AccessExclusiveLock);
heap_close(rel, NoLock);
- return seqoid;
+ return address;
}
/*
*
* Modify the definition of a sequence relation
*/
-Oid
+ObjectAddress
AlterSequence(AlterSeqStmt *stmt)
{
Oid relid;
Form_pg_sequence seq;
FormData_pg_sequence new;
List *owned_by;
+ ObjectAddress address;
/* Open and lock sequence. */
relid = RangeVarGetRelid(stmt->sequence, AccessShareLock, stmt->missing_ok);
ereport(NOTICE,
(errmsg("relation \"%s\" does not exist, skipping",
stmt->sequence->relname)));
- return InvalidOid;
+ return InvalidObjectAddress;
}
init_sequence(relid, &elm, &seqrel);
InvokeObjectPostAlterHook(RelationRelationId, relid, 0);
+ ObjectAddressSet(address, RelationRelationId, relid);
+
relation_close(seqrel, NoLock);
- return relid;
+ return address;
}
* The other arguments are used to extend the behavior for other cases:
* relkind: relkind to assign to the new relation
* ownerId: if not InvalidOid, use this as the new relation's owner.
+ * typaddress: if not null, it's set to the pg_type entry's address.
*
* Note that permissions checks are done against current user regardless of
* ownerId. A nonzero ownerId is used when someone is creating a relation
* "on behalf of" someone else, so we still want to see that the current user
* has permissions to do it.
*
- * If successful, returns the OID of the new relation.
+ * If successful, returns the address of the new relation.
* ----------------------------------------------------------------
*/
-Oid
-DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId)
+ObjectAddress
+DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
+ ObjectAddress *typaddress)
{
char relname[NAMEDATALEN];
Oid namespaceId;
AttrNumber attnum;
static char *validnsps[] = HEAP_RELOPT_NAMESPACES;
Oid ofTypeId;
+ ObjectAddress address;
/*
* Truncate relname to appropriate length (probably a waste of time, as
reloptions,
true,
allowSystemTableMods,
- false);
+ false,
+ typaddress);
/* Store inheritance information for new rel. */
StoreCatalogInheritance(relationId, inheritOids);
AddRelationNewConstraints(rel, rawDefaults, stmt->constraints,
true, true, false);
+ ObjectAddressSet(address, RelationRelationId, relationId);
+
/*
* Clean up. We keep lock on new relation (although it shouldn't be
* visible to anyone else anyway, until commit).
*/
relation_close(rel, NoLock);
- return relationId;
+ return address;
}
/*
/*
* renameatt_internal - workhorse for renameatt
+ *
+ * Return value is the attribute number in the 'myrelid' relation.
*/
-static void
+static AttrNumber
renameatt_internal(Oid myrelid,
const char *oldattname,
const char *newattname,
Relation attrelation;
HeapTuple atttup;
Form_pg_attribute attform;
- int attnum;
+ AttrNumber attnum;
/*
* Grab an exclusive lock on the target table, which we will NOT release
heap_close(attrelation, RowExclusiveLock);
relation_close(targetrelation, NoLock); /* close rel but keep lock */
+
+ return attnum;
}
/*
/*
* renameatt - changes the name of a attribute in a relation
+ *
+ * The returned ObjectAddress is that of the renamed column.
*/
-Oid
+ObjectAddress
renameatt(RenameStmt *stmt)
{
Oid relid;
+ AttrNumber attnum;
+ ObjectAddress address;
/* lock level taken here should match renameatt_internal */
relid = RangeVarGetRelidExtended(stmt->relation, AccessExclusiveLock,
ereport(NOTICE,
(errmsg("relation \"%s\" does not exist, skipping",
stmt->relation->relname)));
- return InvalidOid;
+ return InvalidObjectAddress;
}
- renameatt_internal(relid,
- stmt->subname, /* old att name */
- stmt->newname, /* new att name */
- interpretInhOption(stmt->relation->inhOpt), /* recursive? */
- false, /* recursing? */
- 0, /* expected inhcount */
- stmt->behavior);
+ attnum =
+ renameatt_internal(relid,
+ stmt->subname, /* old att name */
+ stmt->newname, /* new att name */
+ interpretInhOption(stmt->relation->inhOpt), /* recursive? */
+ false, /* recursing? */
+ 0, /* expected inhcount */
+ stmt->behavior);
- /* This is an ALTER TABLE command so it's about the relid */
- return relid;
-}
+ ObjectAddressSubSet(address, RelationRelationId, relid, attnum);
+ return address;
+}
/*
* same logic as renameatt_internal
*/
-static Oid
+static ObjectAddress
rename_constraint_internal(Oid myrelid,
Oid mytypid,
const char *oldconname,
Oid constraintOid;
HeapTuple tuple;
Form_pg_constraint con;
+ ObjectAddress address;
AssertArg(!myrelid || !mytypid);
else
RenameConstraintById(constraintOid, newconname);
+ ObjectAddressSet(address, ConstraintRelationId, constraintOid);
+
ReleaseSysCache(tuple);
if (targetrelation)
relation_close(targetrelation, NoLock); /* close rel but keep lock */
- return constraintOid;
+ return address;
}
-Oid
+ObjectAddress
RenameConstraint(RenameStmt *stmt)
{
Oid relid = InvalidOid;
* Execute ALTER TABLE/INDEX/SEQUENCE/VIEW/MATERIALIZED VIEW/FOREIGN TABLE
* RENAME
*/
-Oid
+ObjectAddress
RenameRelation(RenameStmt *stmt)
{
Oid relid;
+ ObjectAddress address;
/*
* Grab an exclusive lock on the target table, index, sequence, view,
ereport(NOTICE,
(errmsg("relation \"%s\" does not exist, skipping",
stmt->relation->relname)));
- return InvalidOid;
+ return InvalidObjectAddress;
}
/* Do the work */
RenameRelationInternal(relid, stmt->newname, false);
- return relid;
+ ObjectAddressSet(address, RelationRelationId, relid);
+
+ return address;
}
/*
bool check_rights;
bool skip_build;
bool quiet;
- Oid new_index;
+ ObjectAddress address;
Assert(IsA(stmt, IndexStmt));
Assert(!stmt->concurrent);
/* suppress notices when rebuilding existing index */
quiet = is_rebuild;
- new_index = DefineIndex(RelationGetRelid(rel),
- stmt,
- InvalidOid, /* no predefined OID */
- true, /* is_alter_table */
- check_rights,
- skip_build,
- quiet);
+ address = DefineIndex(RelationGetRelid(rel),
+ stmt,
+ InvalidOid, /* no predefined OID */
+ true, /* is_alter_table */
+ check_rights,
+ skip_build,
+ quiet);
/*
* If TryReuseIndex() stashed a relfilenode for us, we used it for the new
*/
if (OidIsValid(stmt->oldNode))
{
- Relation irel = index_open(new_index, NoLock);
+ Relation irel = index_open(address.objectId, NoLock);
RelationPreserveStorage(irel->rd_node, true);
index_close(irel, NoLock);
/*
* Execute ALTER TABLE SET SCHEMA
*/
-Oid
-AlterTableNamespace(AlterObjectSchemaStmt *stmt)
+ObjectAddress
+AlterTableNamespace(AlterObjectSchemaStmt *stmt, Oid *oldschema)
{
Relation rel;
Oid relid;
Oid nspOid;
RangeVar *newrv;
ObjectAddresses *objsMoved;
+ ObjectAddress myself;
relid = RangeVarGetRelidExtended(stmt->relation, AccessExclusiveLock,
stmt->missing_ok, false,
ereport(NOTICE,
(errmsg("relation \"%s\" does not exist, skipping",
stmt->relation->relname)));
- return InvalidOid;
+ return InvalidObjectAddress;
}
rel = relation_open(relid, NoLock);
AlterTableNamespaceInternal(rel, oldNspOid, nspOid, objsMoved);
free_object_addresses(objsMoved);
+ ObjectAddressSet(myself, RelationRelationId, relid);
+
+ if (oldschema)
+ *oldschema = oldNspOid;
+
/* close rel, but keep lock until commit */
relation_close(rel, NoLock);
- return relid;
+ return myself;
}
/*
/*
* Rename a tablespace
*/
-Oid
+ObjectAddress
RenameTableSpace(const char *oldname, const char *newname)
{
Oid tspId;
HeapTuple tup;
HeapTuple newtuple;
Form_pg_tablespace newform;
+ ObjectAddress address;
/* Search pg_tablespace */
rel = heap_open(TableSpaceRelationId, RowExclusiveLock);
InvokeObjectPostAlterHook(TableSpaceRelationId, tspId, 0);
+ ObjectAddressSet(address, TableSpaceRelationId, tspId);
+
heap_close(rel, NoLock);
- return tspId;
+ return address;
}
/*
/*
- * Create a trigger. Returns the OID of the created trigger.
+ * Create a trigger. Returns the address of the created trigger.
*
* queryString is the source text of the CREATE TRIGGER command.
* This must be supplied if a whenClause is specified, else it can be NULL.
* relation, as well as ACL_EXECUTE on the trigger function. For internal
* triggers the caller must apply any required permission checks.
*
- * Note: can return InvalidOid if we decided to not create a trigger at all,
- * but a foreign-key constraint. This is a kluge for backwards compatibility.
+ * Note: can return InvalidObjectAddress if we decided to not create a trigger
+ * at all, but a foreign-key constraint. This is a kluge for backwards
+ * compatibility.
*/
-Oid
+ObjectAddress
CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
Oid relOid, Oid refRelOid, Oid constraintOid, Oid indexOid,
bool isInternal)
ConvertTriggerToFK(stmt, funcoid);
- return InvalidOid;
+ return InvalidObjectAddress;
}
/*
/* Keep lock on target rel until end of xact */
heap_close(rel, NoLock);
- return trigoid;
+ return myself;
}
* modify tgname in trigger tuple
* update row in catalog
*/
-Oid
+ObjectAddress
renametrig(RenameStmt *stmt)
{
Oid tgoid;
SysScanDesc tgscan;
ScanKeyData key[2];
Oid relid;
+ ObjectAddress address;
/*
* Look up name, check permissions, and acquire lock (which we will NOT
stmt->subname, RelationGetRelationName(targetrel))));
}
+ ObjectAddressSet(address, TriggerRelationId, tgoid);
+
systable_endscan(tgscan);
heap_close(tgrel, RowExclusiveLock);
*/
relation_close(targetrel, NoLock);
- return tgoid;
+ return address;
}
/*
* make pg_depend entries for a new pg_ts_parser entry
+ *
+ * Return value is the address of said new entry.
*/
-static void
+static ObjectAddress
makeParserDependencies(HeapTuple tuple)
{
Form_pg_ts_parser prs = (Form_pg_ts_parser) GETSTRUCT(tuple);
referenced.objectId = prs->prsheadline;
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
}
+
+ return myself;
}
/*
* CREATE TEXT SEARCH PARSER
*/
-Oid
+ObjectAddress
DefineTSParser(List *names, List *parameters)
{
char *prsname;
NameData pname;
Oid prsOid;
Oid namespaceoid;
+ ObjectAddress address;
if (!superuser())
ereport(ERROR,
CatalogUpdateIndexes(prsRel, tup);
- makeParserDependencies(tup);
+ address = makeParserDependencies(tup);
/* Post creation hook for new text search parser */
InvokeObjectPostCreateHook(TSParserRelationId, prsOid, 0);
heap_close(prsRel, RowExclusiveLock);
- return prsOid;
+ return address;
}
/*
/*
* make pg_depend entries for a new pg_ts_dict entry
+ *
+ * Return value is address of the new entry
*/
-static void
+static ObjectAddress
makeDictionaryDependencies(HeapTuple tuple)
{
Form_pg_ts_dict dict = (Form_pg_ts_dict) GETSTRUCT(tuple);
referenced.objectId = dict->dicttemplate;
referenced.objectSubId = 0;
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
+
+ return myself;
}
/*
/*
* CREATE TEXT SEARCH DICTIONARY
*/
-Oid
+ObjectAddress
DefineTSDictionary(List *names, List *parameters)
{
ListCell *pl;
Oid namespaceoid;
AclResult aclresult;
char *dictname;
+ ObjectAddress address;
/* Convert list of names to a name and namespace */
namespaceoid = QualifiedNameGetCreationNamespace(names, &dictname);
CatalogUpdateIndexes(dictRel, tup);
- makeDictionaryDependencies(tup);
+ address = makeDictionaryDependencies(tup);
/* Post creation hook for new text search dictionary */
InvokeObjectPostCreateHook(TSDictionaryRelationId, dictOid, 0);
heap_close(dictRel, RowExclusiveLock);
- return dictOid;
+ return address;
}
/*
/*
* ALTER TEXT SEARCH DICTIONARY
*/
-Oid
+ObjectAddress
AlterTSDictionary(AlterTSDictionaryStmt *stmt)
{
HeapTuple tup,
Datum repl_val[Natts_pg_ts_dict];
bool repl_null[Natts_pg_ts_dict];
bool repl_repl[Natts_pg_ts_dict];
+ ObjectAddress address;
dictId = get_ts_dict_oid(stmt->dictname, false);
InvokeObjectPostAlterHook(TSDictionaryRelationId, dictId, 0);
+ ObjectAddressSet(address, TSDictionaryRelationId, dictId);
+
/*
* NOTE: because we only support altering the options, not the template,
* there is no need to update dependencies. This might have to change if
heap_close(rel, RowExclusiveLock);
- return dictId;
+ return address;
}
/* ---------------------- TS Template commands -----------------------*/
/*
* make pg_depend entries for a new pg_ts_template entry
*/
-static void
+static ObjectAddress
makeTSTemplateDependencies(HeapTuple tuple)
{
Form_pg_ts_template tmpl = (Form_pg_ts_template) GETSTRUCT(tuple);
referenced.objectId = tmpl->tmplinit;
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
}
+
+ return myself;
}
/*
* CREATE TEXT SEARCH TEMPLATE
*/
-Oid
+ObjectAddress
DefineTSTemplate(List *names, List *parameters)
{
ListCell *pl;
Oid tmplOid;
Oid namespaceoid;
char *tmplname;
+ ObjectAddress address;
if (!superuser())
ereport(ERROR,
CatalogUpdateIndexes(tmplRel, tup);
- makeTSTemplateDependencies(tup);
+ address = makeTSTemplateDependencies(tup);
/* Post creation hook for new text search template */
InvokeObjectPostCreateHook(TSTemplateRelationId, tmplOid, 0);
heap_close(tmplRel, RowExclusiveLock);
- return tmplOid;
+ return address;
}
/*
* Pass opened pg_ts_config_map relation if there might be any config map
* entries for the config.
*/
-static void
+static ObjectAddress
makeConfigurationDependencies(HeapTuple tuple, bool removeOld,
Relation mapRel)
{
record_object_address_dependencies(&myself, addrs, DEPENDENCY_NORMAL);
free_object_addresses(addrs);
+
+ return myself;
}
/*
* CREATE TEXT SEARCH CONFIGURATION
*/
-Oid
+ObjectAddress
DefineTSConfiguration(List *names, List *parameters)
{
Relation cfgRel;
Oid prsOid = InvalidOid;
Oid cfgOid;
ListCell *pl;
+ ObjectAddress address;
/* Convert list of names to a name and namespace */
namespaceoid = QualifiedNameGetCreationNamespace(names, &cfgname);
systable_endscan(scan);
}
- makeConfigurationDependencies(tup, false, mapRel);
+ address = makeConfigurationDependencies(tup, false, mapRel);
/* Post creation hook for new text search configuration */
InvokeObjectPostCreateHook(TSConfigRelationId, cfgOid, 0);
heap_close(mapRel, RowExclusiveLock);
heap_close(cfgRel, RowExclusiveLock);
- return cfgOid;
+ return address;
}
/*
/*
* ALTER TEXT SEARCH CONFIGURATION - main entry point
*/
-Oid
+ObjectAddress
AlterTSConfiguration(AlterTSConfigurationStmt *stmt)
{
HeapTuple tup;
Oid cfgId;
Relation relMap;
+ ObjectAddress address;
/* Find the configuration */
tup = GetTSConfigTuple(stmt->cfgname);
InvokeObjectPostAlterHook(TSConfigMapRelationId,
HeapTupleGetOid(tup), 0);
+ ObjectAddressSet(address, TSConfigMapRelationId, cfgId);
+
heap_close(relMap, RowExclusiveLock);
ReleaseSysCache(tup);
- return cfgId;
+ return address;
}
/*
static char *domainAddConstraint(Oid domainOid, Oid domainNamespace,
Oid baseTypeOid,
int typMod, Constraint *constr,
- char *domainName);
+ char *domainName, ObjectAddress *constrAddr);
/*
* DefineType
* Registers a new base type.
*/
-Oid
+ObjectAddress
DefineType(List *names, List *parameters)
{
char *typeName;
Oid typoid;
Oid resulttype;
ListCell *pl;
+ ObjectAddress address;
/*
* As of Postgres 8.4, we require superuser privilege to create a base
*/
if (!OidIsValid(typoid))
{
- typoid = TypeShellMake(typeName, typeNamespace, GetUserId());
+ address = TypeShellMake(typeName, typeNamespace, GetUserId());
/* Make new shell type visible for modification below */
CommandCounterIncrement();
* creating the shell type was all we're supposed to do.
*/
if (parameters == NIL)
- return InvalidOid;
+ return address;
}
else
{
* types) in ArrayType and in composite types in DatumTupleFields. This
* oid must be preserved by binary upgrades.
*/
- typoid =
+ address =
TypeCreate(InvalidOid, /* no predetermined type OID */
typeName, /* type name */
typeNamespace, /* namespace */
pfree(array_type);
- return typoid;
+ return address;
}
/*
* DefineDomain
* Registers a new domain.
*/
-Oid
+ObjectAddress
DefineDomain(CreateDomainStmt *stmt)
{
char *domainName;
List *schema = stmt->constraints;
ListCell *listptr;
Oid basetypeoid;
- Oid domainoid;
Oid old_type_oid;
Oid domaincoll;
Form_pg_type baseType;
int32 basetypeMod;
Oid baseColl;
+ ObjectAddress address;
/* Convert list of names to a name and namespace */
domainNamespace = QualifiedNameGetCreationNamespace(stmt->domainname,
/*
* Have TypeCreate do all the real work.
*/
- domainoid =
+ address =
TypeCreate(InvalidOid, /* no predetermined type OID */
domainName, /* type name */
domainNamespace, /* namespace */
switch (constr->contype)
{
case CONSTR_CHECK:
- domainAddConstraint(domainoid, domainNamespace,
+ domainAddConstraint(address.objectId, domainNamespace,
basetypeoid, basetypeMod,
- constr, domainName);
+ constr, domainName, NULL);
break;
/* Other constraint types were fully processed above */
*/
ReleaseSysCache(typeTup);
- return domainoid;
+ return address;
}
* DefineEnum
* Registers a new enum.
*/
-Oid
+ObjectAddress
DefineEnum(CreateEnumStmt *stmt)
{
char *enumName;
char *enumArrayName;
Oid enumNamespace;
- Oid enumTypeOid;
AclResult aclresult;
Oid old_type_oid;
Oid enumArrayOid;
+ ObjectAddress enumTypeAddr;
/* Convert list of names to a name and namespace */
enumNamespace = QualifiedNameGetCreationNamespace(stmt->typeName,
enumArrayOid = AssignTypeArrayOid();
/* Create the pg_type entry */
- enumTypeOid =
+ enumTypeAddr =
TypeCreate(InvalidOid, /* no predetermined type OID */
enumName, /* type name */
enumNamespace, /* namespace */
InvalidOid); /* type's collation */
/* Enter the enum's values into pg_enum */
- EnumValuesCreate(enumTypeOid, stmt->vals);
+ EnumValuesCreate(enumTypeAddr.objectId, stmt->vals);
/*
* Create the array type that goes with it.
InvalidOid, /* typmodin procedure - none */
InvalidOid, /* typmodout procedure - none */
F_ARRAY_TYPANALYZE, /* analyze procedure */
- enumTypeOid, /* element type ID */
+ enumTypeAddr.objectId, /* element type ID */
true, /* yes this is an array type */
InvalidOid, /* no further array type */
InvalidOid, /* base type ID */
pfree(enumArrayName);
- return enumTypeOid;
+ return enumTypeAddr;
}
/*
* AlterEnum
* Adds a new label to an existing enum.
*/
-Oid
+ObjectAddress
AlterEnum(AlterEnumStmt *stmt, bool isTopLevel)
{
Oid enum_type_oid;
TypeName *typename;
HeapTuple tup;
+ ObjectAddress address;
/* Make a TypeName so we can use standard type lookup machinery */
typename = makeTypeNameFromNameList(stmt->typeName);
InvokeObjectPostAlterHook(TypeRelationId, enum_type_oid, 0);
+ ObjectAddressSet(address, TypeRelationId, enum_type_oid);
+
ReleaseSysCache(tup);
- return enum_type_oid;
+ return address;
}
* DefineRange
* Registers a new range type.
*/
-Oid
+ObjectAddress
DefineRange(CreateRangeStmt *stmt)
{
char *typeName;
char alignment;
AclResult aclresult;
ListCell *lc;
+ ObjectAddress address;
/* Convert list of names to a name and namespace */
typeNamespace = QualifiedNameGetCreationNamespace(stmt->typeName,
*/
if (!OidIsValid(typoid))
{
- typoid = TypeShellMake(typeName, typeNamespace, GetUserId());
+ address = TypeShellMake(typeName, typeNamespace, GetUserId());
+ typoid = address.objectId;
/* Make new shell type visible for modification below */
CommandCounterIncrement();
}
rangeArrayOid = AssignTypeArrayOid();
/* Create the pg_type entry */
- typoid =
+ address =
TypeCreate(InvalidOid, /* no predetermined type OID */
typeName, /* type name */
typeNamespace, /* namespace */
0, /* Array dimensions of typbasetype */
false, /* Type NOT NULL */
InvalidOid); /* type's collation (ranges never have one) */
+ typoid = address.objectId;
/* Create the entry in pg_range */
RangeCreate(typoid, rangeSubtype, rangeCollation, rangeSubOpclass,
/* And create the constructor functions for this range type */
makeRangeConstructors(typeName, typeNamespace, typoid, rangeSubtype);
- return typoid;
+ return address;
}
/*
for (i = 0; i < lengthof(prosrc); i++)
{
oidvector *constructorArgTypesVector;
- Oid procOid;
constructorArgTypesVector = buildoidvector(constructorArgTypes,
pronargs[i]);
- procOid = ProcedureCreate(name, /* name: same as range type */
- namespace, /* namespace */
- false, /* replace */
- false, /* returns set */
- rangeOid, /* return type */
- BOOTSTRAP_SUPERUSERID, /* proowner */
- INTERNALlanguageId, /* language */
- F_FMGR_INTERNAL_VALIDATOR, /* language validator */
- prosrc[i], /* prosrc */
- NULL, /* probin */
- false, /* isAgg */
- false, /* isWindowFunc */
- false, /* security_definer */
- false, /* leakproof */
- false, /* isStrict */
- PROVOLATILE_IMMUTABLE, /* volatility */
- constructorArgTypesVector, /* parameterTypes */
- PointerGetDatum(NULL), /* allParameterTypes */
- PointerGetDatum(NULL), /* parameterModes */
- PointerGetDatum(NULL), /* parameterNames */
- NIL, /* parameterDefaults */
- PointerGetDatum(NULL), /* proconfig */
- 1.0, /* procost */
- 0.0); /* prorows */
+ myself = ProcedureCreate(name, /* name: same as range type */
+ namespace, /* namespace */
+ false, /* replace */
+ false, /* returns set */
+ rangeOid, /* return type */
+ BOOTSTRAP_SUPERUSERID, /* proowner */
+ INTERNALlanguageId, /* language */
+ F_FMGR_INTERNAL_VALIDATOR, /* language validator */
+ prosrc[i], /* prosrc */
+ NULL, /* probin */
+ false, /* isAgg */
+ false, /* isWindowFunc */
+ false, /* security_definer */
+ false, /* leakproof */
+ false, /* isStrict */
+ PROVOLATILE_IMMUTABLE, /* volatility */
+ constructorArgTypesVector, /* parameterTypes */
+ PointerGetDatum(NULL), /* allParameterTypes */
+ PointerGetDatum(NULL), /* parameterModes */
+ PointerGetDatum(NULL), /* parameterNames */
+ NIL, /* parameterDefaults */
+ PointerGetDatum(NULL), /* proconfig */
+ 1.0, /* procost */
+ 0.0); /* prorows */
/*
* Make the constructors internally-dependent on the range type so
* that they go away silently when the type is dropped. Note that
* pg_dump depends on this choice to avoid dumping the constructors.
*/
- myself.classId = ProcedureRelationId;
- myself.objectId = procOid;
- myself.objectSubId = 0;
-
recordDependencyOn(&myself, &referenced, DEPENDENCY_INTERNAL);
}
}
* If the relation already exists, then 'DefineRelation' will abort
* the xact...
*
- * DefineCompositeType returns relid for use when creating
- * an implicit composite type during function creation
+ * Return type is the new type's object address.
*-------------------------------------------------------------------
*/
-Oid
+ObjectAddress
DefineCompositeType(RangeVar *typevar, List *coldeflist)
{
CreateStmt *createStmt = makeNode(CreateStmt);
Oid old_type_oid;
Oid typeNamespace;
- Oid relid;
+ ObjectAddress address;
/*
* now set the parameters for keys/inheritance etc. All of these are
/*
* Finally create the relation. This also creates the type.
*/
- relid = DefineRelation(createStmt, RELKIND_COMPOSITE_TYPE, InvalidOid);
- Assert(relid != InvalidOid);
- return relid;
+ DefineRelation(createStmt, RELKIND_COMPOSITE_TYPE, InvalidOid, &address);
+
+ return address;
}
/*
* AlterDomainDefault
*
* Routine implementing ALTER DOMAIN SET/DROP DEFAULT statements.
+ *
+ * Returns ObjectAddress of the modified domain.
*/
-Oid
+ObjectAddress
AlterDomainDefault(List *names, Node *defaultRaw)
{
TypeName *typename;
bool new_record_repl[Natts_pg_type];
HeapTuple newtuple;
Form_pg_type typTup;
+ ObjectAddress address;
/* Make a TypeName so we can use standard type lookup machinery */
typename = makeTypeNameFromNameList(names);
InvokeObjectPostAlterHook(TypeRelationId, domainoid, 0);
+ ObjectAddressSet(address, TypeRelationId, domainoid);
+
/* Clean up */
heap_close(rel, NoLock);
heap_freetuple(newtuple);
- return domainoid;
+ return address;
}
/*
* AlterDomainNotNull
*
* Routine implementing ALTER DOMAIN SET/DROP NOT NULL statements.
+ *
+ * Returns ObjectAddress of the modified domain.
*/
-Oid
+ObjectAddress
AlterDomainNotNull(List *names, bool notNull)
{
TypeName *typename;
Relation typrel;
HeapTuple tup;
Form_pg_type typTup;
+ ObjectAddress address = InvalidObjectAddress;
/* Make a TypeName so we can use standard type lookup machinery */
typename = makeTypeNameFromNameList(names);
if (typTup->typnotnull == notNull)
{
heap_close(typrel, RowExclusiveLock);
- return InvalidOid;
+ return address;
}
/* Adding a NOT NULL constraint requires checking existing columns */
InvokeObjectPostAlterHook(TypeRelationId, domainoid, 0);
+ ObjectAddressSet(address, TypeRelationId, domainoid);
+
/* Clean up */
heap_freetuple(tup);
heap_close(typrel, RowExclusiveLock);
- return domainoid;
+ return address;
}
/*
*
* Implements the ALTER DOMAIN DROP CONSTRAINT statement
*/
-Oid
+ObjectAddress
AlterDomainDropConstraint(List *names, const char *constrName,
DropBehavior behavior, bool missing_ok)
{
ScanKeyData key[1];
HeapTuple contup;
bool found = false;
+ ObjectAddress address = InvalidObjectAddress;
/* Make a TypeName so we can use standard type lookup machinery */
typename = makeTypeNameFromNameList(names);
found = true;
}
}
+
+ ObjectAddressSet(address, TypeRelationId, domainoid);
+
/* Clean up after the scan */
systable_endscan(conscan);
heap_close(conrel, RowExclusiveLock);
constrName, TypeNameToString(typename))));
}
- return domainoid;
+ return address;
}
/*
*
* Implements the ALTER DOMAIN .. ADD CONSTRAINT statement.
*/
-Oid
-AlterDomainAddConstraint(List *names, Node *newConstraint)
+ObjectAddress
+AlterDomainAddConstraint(List *names, Node *newConstraint,
+ ObjectAddress *constrAddr)
{
TypeName *typename;
Oid domainoid;
Form_pg_type typTup;
Constraint *constr;
char *ccbin;
+ ObjectAddress address;
/* Make a TypeName so we can use standard type lookup machinery */
typename = makeTypeNameFromNameList(names);
ccbin = domainAddConstraint(domainoid, typTup->typnamespace,
typTup->typbasetype, typTup->typtypmod,
- constr, NameStr(typTup->typname));
+ constr, NameStr(typTup->typname), constrAddr);
/*
* If requested to validate the constraint, test all values stored in the
if (!constr->skip_validation)
validateDomainConstraint(domainoid, ccbin);
+ ObjectAddressSet(address, TypeRelationId, domainoid);
+
/* Clean up */
heap_close(typrel, RowExclusiveLock);
- return domainoid;
+ return address;
}
/*
*
* Implements the ALTER DOMAIN .. VALIDATE CONSTRAINT statement.
*/
-Oid
+ObjectAddress
AlterDomainValidateConstraint(List *names, char *constrName)
{
TypeName *typename;
HeapTuple tuple;
HeapTuple copyTuple;
ScanKeyData key;
+ ObjectAddress address;
/* Make a TypeName so we can use standard type lookup machinery */
typename = makeTypeNameFromNameList(names);
InvokeObjectPostAlterHook(ConstraintRelationId,
HeapTupleGetOid(copyTuple), 0);
+ ObjectAddressSet(address, TypeRelationId, domainoid);
+
heap_freetuple(copyTuple);
systable_endscan(scan);
ReleaseSysCache(tup);
- return domainoid;
+ return address;
}
static void
static char *
domainAddConstraint(Oid domainOid, Oid domainNamespace, Oid baseTypeOid,
int typMod, Constraint *constr,
- char *domainName)
+ char *domainName, ObjectAddress *constrAddr)
{
Node *expr;
char *ccsrc;
char *ccbin;
ParseState *pstate;
CoerceToDomainValue *domVal;
+ Oid ccoid;
/*
* Assign or validate constraint name
/*
* Store the constraint in pg_constraint
*/
- CreateConstraintEntry(constr->conname, /* Constraint Name */
- domainNamespace, /* namespace */
- CONSTRAINT_CHECK, /* Constraint Type */
- false, /* Is Deferrable */
- false, /* Is Deferred */
- !constr->skip_validation, /* Is Validated */
- InvalidOid, /* not a relation constraint */
- NULL,
- 0,
- domainOid, /* domain constraint */
- InvalidOid, /* no associated index */
- InvalidOid, /* Foreign key fields */
- NULL,
- NULL,
- NULL,
- NULL,
- 0,
- ' ',
- ' ',
- ' ',
- NULL, /* not an exclusion constraint */
- expr, /* Tree form of check constraint */
- ccbin, /* Binary form of check constraint */
- ccsrc, /* Source form of check constraint */
- true, /* is local */
- 0, /* inhcount */
- false, /* connoinherit */
- false); /* is_internal */
+ ccoid =
+ CreateConstraintEntry(constr->conname, /* Constraint Name */
+ domainNamespace, /* namespace */
+ CONSTRAINT_CHECK, /* Constraint Type */
+ false, /* Is Deferrable */
+ false, /* Is Deferred */
+ !constr->skip_validation, /* Is Validated */
+ InvalidOid, /* not a relation constraint */
+ NULL,
+ 0,
+ domainOid, /* domain constraint */
+ InvalidOid, /* no associated index */
+ InvalidOid, /* Foreign key fields */
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ 0,
+ ' ',
+ ' ',
+ ' ',
+ NULL, /* not an exclusion constraint */
+ expr, /* Tree form of check constraint */
+ ccbin, /* Binary form of check constraint */
+ ccsrc, /* Source form of check constraint */
+ true, /* is local */
+ 0, /* inhcount */
+ false, /* connoinherit */
+ false); /* is_internal */
+ if (constrAddr)
+ ObjectAddressSet(*constrAddr, ConstraintRelationId, ccoid);
/*
* Return the compiled constraint expression so the calling routine can
/*
* Execute ALTER TYPE RENAME
*/
-Oid
+ObjectAddress
RenameType(RenameStmt *stmt)
{
List *names = stmt->object;
Relation rel;
HeapTuple tup;
Form_pg_type typTup;
+ ObjectAddress address;
/* Make a TypeName so we can use standard type lookup machinery */
typename = makeTypeNameFromNameList(names);
RenameTypeInternal(typeOid, newTypeName,
typTup->typnamespace);
+ ObjectAddressSet(address, TypeRelationId, typeOid);
/* Clean up */
heap_close(rel, RowExclusiveLock);
- return typeOid;
+ return address;
}
/*
* Change the owner of a type.
*/
-Oid
+ObjectAddress
AlterTypeOwner(List *names, Oid newOwnerId, ObjectType objecttype)
{
TypeName *typename;
HeapTuple newtup;
Form_pg_type typTup;
AclResult aclresult;
+ ObjectAddress address;
rel = heap_open(TypeRelationId, RowExclusiveLock);
}
}
+ ObjectAddressSet(address, TypeRelationId, typeOid);
+
/* Clean up */
heap_close(rel, RowExclusiveLock);
- return typeOid;
+ return address;
}
/*
/*
* Execute ALTER TYPE SET SCHEMA
*/
-Oid
-AlterTypeNamespace(List *names, const char *newschema, ObjectType objecttype)
+ObjectAddress
+AlterTypeNamespace(List *names, const char *newschema, ObjectType objecttype,
+ Oid *oldschema)
{
TypeName *typename;
Oid typeOid;
Oid nspOid;
+ Oid oldNspOid;
ObjectAddresses *objsMoved;
+ ObjectAddress myself;
/* Make a TypeName so we can use standard type lookup machinery */
typename = makeTypeNameFromNameList(names);
nspOid = LookupCreationNamespace(newschema);
objsMoved = new_object_addresses();
- AlterTypeNamespace_oid(typeOid, nspOid, objsMoved);
+ oldNspOid = AlterTypeNamespace_oid(typeOid, nspOid, objsMoved);
free_object_addresses(objsMoved);
- return typeOid;
+ if (oldschema)
+ *oldschema = oldNspOid;
+
+ ObjectAddressSet(myself, TypeRelationId, typeOid);
+
+ return myself;
}
Oid
/*
* Rename role
*/
-Oid
+ObjectAddress
RenameRole(const char *oldname, const char *newname)
{
HeapTuple oldtuple,
bool repl_repl[Natts_pg_authid];
int i;
Oid roleid;
+ ObjectAddress address;
rel = heap_open(AuthIdRelationId, RowExclusiveLock);
dsc = RelationGetDescr(rel);
InvokeObjectPostAlterHook(AuthIdRelationId, roleid, 0);
+ ObjectAddressSet(address, AuthIdRelationId, roleid);
+
ReleaseSysCache(oldtuple);
/*
*/
heap_close(rel, NoLock);
- return roleid;
+ return address;
}
/*
* work harder.
*---------------------------------------------------------------------
*/
-static Oid
+static ObjectAddress
DefineVirtualRelation(RangeVar *relation, List *tlist, bool replace,
List *options)
{
TupleDesc descriptor;
List *atcmds = NIL;
AlterTableCmd *atcmd;
+ ObjectAddress address;
/* Relation is already locked, but we must build a relcache entry. */
rel = relation_open(viewOid, NoLock);
/* OK, let's do it. */
AlterTableInternal(viewOid, atcmds, true);
+ ObjectAddressSet(address, RelationRelationId, viewOid);
+
/*
* Seems okay, so return the OID of the pre-existing view.
*/
relation_close(rel, NoLock); /* keep the lock! */
- return viewOid;
+ return address;
}
else
{
- Oid relid;
+ ObjectAddress address;
/*
* now set the parameters for keys/inheritance etc. All of these are
* existing view, so we don't need more code to complain if "replace"
* is false).
*/
- relid = DefineRelation(createStmt, RELKIND_VIEW, InvalidOid);
- Assert(relid != InvalidOid);
- return relid;
+ address = DefineRelation(createStmt, RELKIND_VIEW, InvalidOid, NULL);
+ Assert(address.objectId != InvalidOid);
+ return address;
}
}
* DefineView
* Execute a CREATE VIEW command.
*/
-Oid
+ObjectAddress
DefineView(ViewStmt *stmt, const char *queryString)
{
Query *viewParse;
- Oid viewOid;
RangeVar *view;
ListCell *cell;
bool check_option;
+ ObjectAddress address;
/*
* Run parse analysis to convert the raw parse tree to a Query. Note this
* NOTE: if it already exists and replace is false, the xact will be
* aborted.
*/
- viewOid = DefineVirtualRelation(view, viewParse->targetList,
+ address = DefineVirtualRelation(view, viewParse->targetList,
stmt->replace, stmt->options);
/*
*/
CommandCounterIncrement();
- StoreViewQuery(viewOid, viewParse, stmt->replace);
+ StoreViewQuery(address.objectId, viewParse, stmt->replace);
- return viewOid;
+ return address;
}
/*
* DefineRule
* Execute a CREATE RULE command.
*/
-Oid
+ObjectAddress
DefineRule(RuleStmt *stmt, const char *queryString)
{
List *actions;
* This is essentially the same as DefineRule() except that the rule's
* action and qual have already been passed through parse analysis.
*/
-Oid
+ObjectAddress
DefineQueryRewrite(char *rulename,
Oid event_relid,
Node *event_qual,
Query *query;
bool RelisBecomingView = false;
Oid ruleId = InvalidOid;
+ ObjectAddress address;
/*
* If we are installing an ON SELECT rule, we had better grab
heap_close(relationRelation, RowExclusiveLock);
}
+ ObjectAddressSet(address, RewriteRelationId, ruleId);
+
/* Close rel, but keep lock till commit... */
heap_close(event_relation, NoLock);
- return ruleId;
+ return address;
}
/*
/*
* Rename an existing rewrite rule.
*/
-Oid
+ObjectAddress
RenameRewriteRule(RangeVar *relation, const char *oldName,
const char *newName)
{
HeapTuple ruletup;
Form_pg_rewrite ruleform;
Oid ruleOid;
+ ObjectAddress address;
/*
* Look up name, check permissions, and acquire lock (which we will NOT
*/
CacheInvalidateRelcache(targetrel);
+ ObjectAddressSet(address, RewriteRelationId, ruleOid);
+
/*
* Close rel, but keep exclusive lock!
*/
relation_close(targetrel, NoLock);
- return ruleOid;
+ return address;
}
context, params,
dest, completionTag);
else
- ExecAlterObjectSchemaStmt(stmt);
+ ExecAlterObjectSchemaStmt(stmt, NULL);
}
break;
bool isTopLevel = (context == PROCESS_UTILITY_TOPLEVEL);
bool isCompleteQuery = (context <= PROCESS_UTILITY_QUERY);
bool needCleanup;
+ ObjectAddress address;
/* All event trigger calls are done only when isCompleteQuery is true */
needCleanup = isCompleteQuery && EventTriggerBeginCompleteQuery();
{
List *stmts;
ListCell *l;
- Oid relOid;
/* Run parse analysis ... */
stmts = transformCreateStmt((CreateStmt *) parsetree,
static char *validnsps[] = HEAP_RELOPT_NAMESPACES;
/* Create the table itself */
- relOid = DefineRelation((CreateStmt *) stmt,
- RELKIND_RELATION,
- InvalidOid);
+ address = DefineRelation((CreateStmt *) stmt,
+ RELKIND_RELATION,
+ InvalidOid, NULL);
/*
* Let NewRelationCreateToastTable decide if this
toast_options,
true);
- NewRelationCreateToastTable(relOid, toast_options);
+ NewRelationCreateToastTable(address.objectId,
+ toast_options);
}
else if (IsA(stmt, CreateForeignTableStmt))
{
/* Create the table itself */
- relOid = DefineRelation((CreateStmt *) stmt,
- RELKIND_FOREIGN_TABLE,
- InvalidOid);
+ address = DefineRelation((CreateStmt *) stmt,
+ RELKIND_FOREIGN_TABLE,
+ InvalidOid, NULL);
CreateForeignTable((CreateForeignTableStmt *) stmt,
- relOid);
+ address.objectId);
}
else
{
break;
case 'C': /* ADD CONSTRAINT */
AlterDomainAddConstraint(stmt->typeName,
- stmt->def);
+ stmt->def,
+ NULL);
break;
case 'X': /* DROP CONSTRAINT */
AlterDomainDropConstraint(stmt->typeName,
break;
case T_AlterExtensionContentsStmt:
- ExecAlterExtensionContentsStmt((AlterExtensionContentsStmt *) parsetree);
+ ExecAlterExtensionContentsStmt((AlterExtensionContentsStmt *) parsetree,
+ NULL);
break;
case T_CreateFdwStmt:
break;
case T_AlterObjectSchemaStmt:
- ExecAlterObjectSchemaStmt((AlterObjectSchemaStmt *) parsetree);
+ ExecAlterObjectSchemaStmt((AlterObjectSchemaStmt *) parsetree,
+ NULL);
break;
case T_AlterOwnerStmt:
#ifndef HEAP_H
#define HEAP_H
-#include "parser/parse_node.h"
#include "catalog/indexing.h"
+#include "catalog/objectaddress.h"
+#include "parser/parse_node.h"
typedef struct RawColumnDefault
Datum reloptions,
bool use_user_acl,
bool allow_system_table_mods,
- bool is_internal);
+ bool is_internal,
+ ObjectAddress *typaddress);
extern void heap_create_init_fork(Relation rel);
int32 objectSubId; /* Subitem within object (eg column), or 0 */
} ObjectAddress;
+extern const ObjectAddress InvalidObjectAddress;
+
+#define ObjectAddressSubSet(addr, class_id, object_id, object_sub_id) \
+ do { \
+ (addr).classId = (class_id); \
+ (addr).objectId = (object_id); \
+ (addr).objectSubId = (object_sub_id); \
+ } while (0)
+
+#define ObjectAddressSet(addr, class_id, object_id) \
+ ObjectAddressSubSet(addr, class_id, object_id, 0)
+
extern ObjectAddress get_object_address(ObjectType objtype, List *objname,
List *objargs, Relation *relp,
LOCKMODE lockmode, bool missing_ok);
#define PG_AGGREGATE_H
#include "catalog/genbki.h"
+#include "catalog/objectaddress.h"
#include "nodes/pg_list.h"
/* ----------------------------------------------------------------
/*
* prototypes for functions in pg_aggregate.c
*/
-extern Oid AggregateCreate(const char *aggName,
+extern ObjectAddress AggregateCreate(const char *aggName,
Oid aggNamespace,
char aggKind,
int numArgs,
#ifndef PG_CONVERSION_FN_H
#define PG_CONVERSION_FN_H
-extern Oid ConversionCreate(const char *conname, Oid connamespace,
+
+#include "catalog/objectaddress.h"
+
+extern ObjectAddress ConversionCreate(const char *conname, Oid connamespace,
Oid conowner,
int32 conforencoding, int32 contoencoding,
Oid conproc, bool def);
#define PG_OPERATOR_H
#include "catalog/genbki.h"
+#include "catalog/objectaddress.h"
#include "nodes/pg_list.h"
/* ----------------
/*
* function prototypes
*/
-extern Oid OperatorCreate(const char *operatorName,
+extern ObjectAddress OperatorCreate(const char *operatorName,
Oid operatorNamespace,
Oid leftTypeId,
Oid rightTypeId,
#ifndef PG_PROC_FN_H
#define PG_PROC_FN_H
+#include "catalog/objectaddress.h"
#include "nodes/pg_list.h"
-extern Oid ProcedureCreate(const char *procedureName,
+extern ObjectAddress ProcedureCreate(const char *procedureName,
Oid procNamespace,
bool replace,
bool returnsSet,
#ifndef PG_TYPE_FN_H
#define PG_TYPE_FN_H
+#include "catalog/objectaddress.h"
#include "nodes/nodes.h"
-extern Oid TypeShellMake(const char *typeName,
+extern ObjectAddress TypeShellMake(const char *typeName,
Oid typeNamespace,
Oid ownerId);
-extern Oid TypeCreate(Oid newTypeOid,
+extern ObjectAddress TypeCreate(Oid newTypeOid,
const char *typeName,
Oid typeNamespace,
Oid relationOid,
#define ALTER_H
#include "catalog/dependency.h"
+#include "catalog/objectaddress.h"
#include "nodes/parsenodes.h"
#include "utils/relcache.h"
-extern Oid ExecRenameStmt(RenameStmt *stmt);
+extern ObjectAddress ExecRenameStmt(RenameStmt *stmt);
-extern Oid ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt);
+extern ObjectAddress ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt,
+ ObjectAddress *oldSchemaAddr);
extern Oid AlterObjectNamespace_oid(Oid classId, Oid objid, Oid nspOid,
ObjectAddresses *objsMoved);
-extern Oid ExecAlterOwnerStmt(AlterOwnerStmt *stmt);
+extern ObjectAddress ExecAlterOwnerStmt(AlterOwnerStmt *stmt);
extern void AlterObjectOwner_internal(Relation catalog, Oid objectId,
Oid new_ownerId);
#ifndef COLLATIONCMDS_H
#define COLLATIONCMDS_H
+#include "catalog/objectaddress.h"
#include "nodes/parsenodes.h"
-extern Oid DefineCollation(List *names, List *parameters);
+extern ObjectAddress DefineCollation(List *names, List *parameters);
extern void IsThereCollationInNamespace(const char *collname, Oid nspOid);
#endif /* COLLATIONCMDS_H */
#ifndef COMMENT_H
#define COMMENT_H
+#include "catalog/objectaddress.h"
#include "nodes/parsenodes.h"
/*------------------------------------------------------------------
*------------------------------------------------------------------
*/
-extern Oid CommentObject(CommentStmt *stmt);
+extern ObjectAddress CommentObject(CommentStmt *stmt);
extern void DeleteComments(Oid oid, Oid classoid, int32 subid);
#ifndef CONVERSIONCMDS_H
#define CONVERSIONCMDS_H
+#include "catalog/objectaddress.h"
#include "nodes/parsenodes.h"
-extern Oid CreateConversionCommand(CreateConversionStmt *parsetree);
+extern ObjectAddress CreateConversionCommand(CreateConversionStmt *parsetree);
#endif /* CONVERSIONCMDS_H */
#ifndef CREATEAS_H
#define CREATEAS_H
+#include "catalog/objectaddress.h"
#include "nodes/params.h"
#include "nodes/parsenodes.h"
#include "tcop/dest.h"
-extern Oid ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString,
+extern ObjectAddress ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString,
ParamListInfo params, char *completionTag);
extern int GetIntoRelEFlags(IntoClause *intoClause);
#define DBCOMMANDS_H
#include "access/xlogreader.h"
+#include "catalog/objectaddress.h"
#include "lib/stringinfo.h"
#include "nodes/parsenodes.h"
extern Oid createdb(const CreatedbStmt *stmt);
extern void dropdb(const char *dbname, bool missing_ok);
-extern Oid RenameDatabase(const char *oldname, const char *newname);
+extern ObjectAddress RenameDatabase(const char *oldname, const char *newname);
extern Oid AlterDatabase(AlterDatabaseStmt *stmt, bool isTopLevel);
extern Oid AlterDatabaseSet(AlterDatabaseSetStmt *stmt);
-extern Oid AlterDatabaseOwner(const char *dbname, Oid newOwnerId);
+extern ObjectAddress AlterDatabaseOwner(const char *dbname, Oid newOwnerId);
extern Oid get_database_oid(const char *dbname, bool missingok);
extern char *get_database_name(Oid dbid);
#ifndef DEFREM_H
#define DEFREM_H
+#include "catalog/objectaddress.h"
#include "nodes/parsenodes.h"
#include "utils/array.h"
extern void RemoveObjects(DropStmt *stmt);
/* commands/indexcmds.c */
-extern Oid DefineIndex(Oid relationId,
+extern ObjectAddress DefineIndex(Oid relationId,
IndexStmt *stmt,
Oid indexRelationId,
bool is_alter_table,
extern Oid GetDefaultOpClass(Oid type_id, Oid am_id);
/* commands/functioncmds.c */
-extern Oid CreateFunction(CreateFunctionStmt *stmt, const char *queryString);
+extern ObjectAddress CreateFunction(CreateFunctionStmt *stmt, const char *queryString);
extern void RemoveFunctionById(Oid funcOid);
extern void SetFunctionReturnType(Oid funcOid, Oid newRetType);
extern void SetFunctionArgType(Oid funcOid, int argIndex, Oid newArgType);
-extern Oid AlterFunction(AlterFunctionStmt *stmt);
-extern Oid CreateCast(CreateCastStmt *stmt);
+extern ObjectAddress AlterFunction(AlterFunctionStmt *stmt);
+extern ObjectAddress CreateCast(CreateCastStmt *stmt);
extern void DropCastById(Oid castOid);
extern void IsThereFunctionInNamespace(const char *proname, int pronargs,
oidvector *proargtypes, Oid nspOid);
Oid *requiredResultType);
/* commands/operatorcmds.c */
-extern Oid DefineOperator(List *names, List *parameters);
+extern ObjectAddress DefineOperator(List *names, List *parameters);
extern void RemoveOperatorById(Oid operOid);
/* commands/aggregatecmds.c */
-extern Oid DefineAggregate(List *name, List *args, bool oldstyle,
+extern ObjectAddress DefineAggregate(List *name, List *args, bool oldstyle,
List *parameters, const char *queryString);
/* commands/opclasscmds.c */
-extern Oid DefineOpClass(CreateOpClassStmt *stmt);
-extern Oid DefineOpFamily(CreateOpFamilyStmt *stmt);
+extern ObjectAddress DefineOpClass(CreateOpClassStmt *stmt);
+extern ObjectAddress DefineOpFamily(CreateOpFamilyStmt *stmt);
extern Oid AlterOpFamily(AlterOpFamilyStmt *stmt);
extern void RemoveOpClassById(Oid opclassOid);
extern void RemoveOpFamilyById(Oid opfamilyOid);
extern Oid get_opfamily_oid(Oid amID, List *opfamilyname, bool missing_ok);
/* commands/tsearchcmds.c */
-extern Oid DefineTSParser(List *names, List *parameters);
+extern ObjectAddress DefineTSParser(List *names, List *parameters);
extern void RemoveTSParserById(Oid prsId);
-extern Oid DefineTSDictionary(List *names, List *parameters);
+extern ObjectAddress DefineTSDictionary(List *names, List *parameters);
extern void RemoveTSDictionaryById(Oid dictId);
-extern Oid AlterTSDictionary(AlterTSDictionaryStmt *stmt);
+extern ObjectAddress AlterTSDictionary(AlterTSDictionaryStmt *stmt);
-extern Oid DefineTSTemplate(List *names, List *parameters);
+extern ObjectAddress DefineTSTemplate(List *names, List *parameters);
extern void RemoveTSTemplateById(Oid tmplId);
-extern Oid DefineTSConfiguration(List *names, List *parameters);
+extern ObjectAddress DefineTSConfiguration(List *names, List *parameters);
extern void RemoveTSConfigurationById(Oid cfgId);
-extern Oid AlterTSConfiguration(AlterTSConfigurationStmt *stmt);
+extern ObjectAddress AlterTSConfiguration(AlterTSConfigurationStmt *stmt);
extern text *serialize_deflist(List *deflist);
extern List *deserialize_deflist(Datum txt);
/* commands/foreigncmds.c */
-extern Oid AlterForeignServerOwner(const char *name, Oid newOwnerId);
+extern ObjectAddress AlterForeignServerOwner(const char *name, Oid newOwnerId);
extern void AlterForeignServerOwner_oid(Oid, Oid newOwnerId);
-extern Oid AlterForeignDataWrapperOwner(const char *name, Oid newOwnerId);
+extern ObjectAddress AlterForeignDataWrapperOwner(const char *name, Oid newOwnerId);
extern void AlterForeignDataWrapperOwner_oid(Oid fwdId, Oid newOwnerId);
-extern Oid CreateForeignDataWrapper(CreateFdwStmt *stmt);
-extern Oid AlterForeignDataWrapper(AlterFdwStmt *stmt);
+extern ObjectAddress CreateForeignDataWrapper(CreateFdwStmt *stmt);
+extern ObjectAddress AlterForeignDataWrapper(AlterFdwStmt *stmt);
extern void RemoveForeignDataWrapperById(Oid fdwId);
-extern Oid CreateForeignServer(CreateForeignServerStmt *stmt);
-extern Oid AlterForeignServer(AlterForeignServerStmt *stmt);
+extern ObjectAddress CreateForeignServer(CreateForeignServerStmt *stmt);
+extern ObjectAddress AlterForeignServer(AlterForeignServerStmt *stmt);
extern void RemoveForeignServerById(Oid srvId);
-extern Oid CreateUserMapping(CreateUserMappingStmt *stmt);
-extern Oid AlterUserMapping(AlterUserMappingStmt *stmt);
+extern ObjectAddress CreateUserMapping(CreateUserMappingStmt *stmt);
+extern ObjectAddress AlterUserMapping(AlterUserMappingStmt *stmt);
extern Oid RemoveUserMapping(DropUserMappingStmt *stmt);
extern void RemoveUserMappingById(Oid umId);
extern void CreateForeignTable(CreateForeignTableStmt *stmt, Oid relid);
extern Oid get_event_trigger_oid(const char *trigname, bool missing_ok);
extern Oid AlterEventTrigger(AlterEventTrigStmt *stmt);
-extern Oid AlterEventTriggerOwner(const char *name, Oid newOwnerId);
+extern ObjectAddress AlterEventTriggerOwner(const char *name, Oid newOwnerId);
extern void AlterEventTriggerOwner_oid(Oid, Oid newOwnerId);
extern bool EventTriggerSupportsObjectType(ObjectType obtype);
#ifndef EXTENSION_H
#define EXTENSION_H
+#include "catalog/objectaddress.h"
#include "nodes/parsenodes.h"
extern Oid CurrentExtensionObject;
-extern Oid CreateExtension(CreateExtensionStmt *stmt);
+extern ObjectAddress CreateExtension(CreateExtensionStmt *stmt);
extern void RemoveExtensionById(Oid extId);
-extern Oid InsertExtensionTuple(const char *extName, Oid extOwner,
+extern ObjectAddress InsertExtensionTuple(const char *extName, Oid extOwner,
Oid schemaOid, bool relocatable, const char *extVersion,
Datum extConfig, Datum extCondition,
List *requiredExtensions);
-extern Oid ExecAlterExtensionStmt(AlterExtensionStmt *stmt);
+extern ObjectAddress ExecAlterExtensionStmt(AlterExtensionStmt *stmt);
-extern Oid ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt);
+extern ObjectAddress ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt,
+ ObjectAddress *objAddress);
extern Oid get_extension_oid(const char *extname, bool missing_ok);
extern char *get_extension_name(Oid ext_oid);
-extern Oid AlterExtensionNamespace(List *names, const char *newschema);
+extern ObjectAddress AlterExtensionNamespace(List *names, const char *newschema,
+ Oid *oldschema);
extern void AlterExtensionOwner_oid(Oid extensionOid, Oid newOwnerId);
#ifndef MATVIEW_H
#define MATVIEW_H
+#include "catalog/objectaddress.h"
#include "nodes/params.h"
#include "nodes/parsenodes.h"
#include "tcop/dest.h"
extern void SetMatViewPopulatedState(Relation relation, bool newstate);
-extern Oid ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString,
+extern ObjectAddress ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString,
ParamListInfo params, char *completionTag);
extern DestReceiver *CreateTransientRelDestReceiver(Oid oid);
#ifndef POLICY_H
#define POLICY_H
+#include "catalog/objectaddress.h"
#include "nodes/parsenodes.h"
#include "utils/relcache.h"
extern void RemovePolicyById(Oid policy_id);
-extern Oid CreatePolicy(CreatePolicyStmt *stmt);
-extern Oid AlterPolicy(AlterPolicyStmt *stmt);
+extern ObjectAddress CreatePolicy(CreatePolicyStmt *stmt);
+extern ObjectAddress AlterPolicy(AlterPolicyStmt *stmt);
extern Oid get_relation_policy_oid(Oid relid, const char *policy_name,
bool missing_ok);
-extern Oid rename_policy(RenameStmt *stmt);
+extern ObjectAddress rename_policy(RenameStmt *stmt);
#endif /* POLICY_H */
#ifndef PROCLANG_H
#define PROCLANG_H
+#include "catalog/objectaddress.h"
#include "nodes/parsenodes.h"
-extern Oid CreateProceduralLanguage(CreatePLangStmt *stmt);
+extern ObjectAddress CreateProceduralLanguage(CreatePLangStmt *stmt);
extern void DropProceduralLanguageById(Oid langOid);
extern bool PLTemplateExists(const char *languageName);
extern Oid get_language_oid(const char *langname, bool missing_ok);
#ifndef SCHEMACMDS_H
#define SCHEMACMDS_H
+#include "catalog/objectaddress.h"
#include "nodes/parsenodes.h"
extern Oid CreateSchemaCommand(CreateSchemaStmt *parsetree,
extern void RemoveSchemaById(Oid schemaOid);
-extern Oid RenameSchema(const char *oldname, const char *newname);
-extern Oid AlterSchemaOwner(const char *name, Oid newOwnerId);
+extern ObjectAddress RenameSchema(const char *oldname, const char *newname);
+extern ObjectAddress AlterSchemaOwner(const char *name, Oid newOwnerId);
extern void AlterSchemaOwner_oid(Oid schemaOid, Oid newOwnerId);
#endif /* SCHEMACMDS_H */
/*
* Statement and ESP hook support
*/
-extern Oid ExecSecLabelStmt(SecLabelStmt *stmt);
+extern ObjectAddress ExecSecLabelStmt(SecLabelStmt *stmt);
typedef void (*check_object_relabel_type) (const ObjectAddress *object,
const char *seclabel);
#define SEQUENCE_H
#include "access/xlogreader.h"
+#include "catalog/objectaddress.h"
#include "fmgr.h"
#include "lib/stringinfo.h"
#include "nodes/parsenodes.h"
extern Datum pg_sequence_parameters(PG_FUNCTION_ARGS);
-extern Oid DefineSequence(CreateSeqStmt *stmt);
-extern Oid AlterSequence(AlterSeqStmt *stmt);
+extern ObjectAddress DefineSequence(CreateSeqStmt *stmt);
+extern ObjectAddress AlterSequence(AlterSeqStmt *stmt);
extern void ResetSequence(Oid seq_relid);
extern void ResetSequenceCaches(void);
#include "access/htup.h"
#include "catalog/dependency.h"
+#include "catalog/objectaddress.h"
#include "nodes/parsenodes.h"
#include "storage/lock.h"
#include "utils/relcache.h"
-extern Oid DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId);
+extern ObjectAddress DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
+ ObjectAddress *typaddress);
extern void RemoveRelations(DropStmt *drop);
extern Oid AlterTableMoveAll(AlterTableMoveAllStmt *stmt);
-extern Oid AlterTableNamespace(AlterObjectSchemaStmt *stmt);
+extern ObjectAddress AlterTableNamespace(AlterObjectSchemaStmt *stmt,
+ Oid *oldschema);
extern void AlterTableNamespaceInternal(Relation rel, Oid oldNspOid,
Oid nspOid, ObjectAddresses *objsMoved);
extern void SetRelationHasSubclass(Oid relationId, bool relhassubclass);
-extern Oid renameatt(RenameStmt *stmt);
+extern ObjectAddress renameatt(RenameStmt *stmt);
-extern Oid RenameConstraint(RenameStmt *stmt);
+extern ObjectAddress renameatt_type(RenameStmt *stmt);
-extern Oid RenameRelation(RenameStmt *stmt);
+extern ObjectAddress RenameConstraint(RenameStmt *stmt);
+
+extern ObjectAddress RenameRelation(RenameStmt *stmt);
extern void RenameRelationInternal(Oid myrelid,
const char *newrelname, bool is_internal);
#define TABLESPACE_H
#include "access/xlogreader.h"
+#include "catalog/objectaddress.h"
#include "lib/stringinfo.h"
#include "nodes/parsenodes.h"
extern Oid CreateTableSpace(CreateTableSpaceStmt *stmt);
extern void DropTableSpace(DropTableSpaceStmt *stmt);
-extern Oid RenameTableSpace(const char *oldname, const char *newname);
+extern ObjectAddress RenameTableSpace(const char *oldname, const char *newname);
extern Oid AlterTableSpaceOptions(AlterTableSpaceOptionsStmt *stmt);
extern void TablespaceCreateDbspace(Oid spcNode, Oid dbNode, bool isRedo);
#ifndef TRIGGER_H
#define TRIGGER_H
+#include "catalog/objectaddress.h"
#include "nodes/execnodes.h"
#include "nodes/parsenodes.h"
#define TRIGGER_FIRES_ON_REPLICA 'R'
#define TRIGGER_DISABLED 'D'
-extern Oid CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
+extern ObjectAddress CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
Oid relOid, Oid refRelOid, Oid constraintOid, Oid indexOid,
bool isInternal);
extern void RemoveTriggerById(Oid trigOid);
extern Oid get_trigger_oid(Oid relid, const char *name, bool missing_ok);
-extern Oid renametrig(RenameStmt *stmt);
+extern ObjectAddress renametrig(RenameStmt *stmt);
extern void EnableDisableTrigger(Relation rel, const char *tgname,
char fires_when, bool skip_system);
#define DEFAULT_TYPDELIM ','
-extern Oid DefineType(List *names, List *parameters);
+extern ObjectAddress DefineType(List *names, List *parameters);
extern void RemoveTypeById(Oid typeOid);
-extern Oid DefineDomain(CreateDomainStmt *stmt);
-extern Oid DefineEnum(CreateEnumStmt *stmt);
-extern Oid DefineRange(CreateRangeStmt *stmt);
-extern Oid AlterEnum(AlterEnumStmt *stmt, bool isTopLevel);
-extern Oid DefineCompositeType(RangeVar *typevar, List *coldeflist);
+extern ObjectAddress DefineDomain(CreateDomainStmt *stmt);
+extern ObjectAddress DefineEnum(CreateEnumStmt *stmt);
+extern ObjectAddress DefineRange(CreateRangeStmt *stmt);
+extern ObjectAddress AlterEnum(AlterEnumStmt *stmt, bool isTopLevel);
+extern ObjectAddress DefineCompositeType(RangeVar *typevar, List *coldeflist);
extern Oid AssignTypeArrayOid(void);
-extern Oid AlterDomainDefault(List *names, Node *defaultRaw);
-extern Oid AlterDomainNotNull(List *names, bool notNull);
-extern Oid AlterDomainAddConstraint(List *names, Node *constr);
-extern Oid AlterDomainValidateConstraint(List *names, char *constrName);
-extern Oid AlterDomainDropConstraint(List *names, const char *constrName,
+extern ObjectAddress AlterDomainDefault(List *names, Node *defaultRaw);
+extern ObjectAddress AlterDomainNotNull(List *names, bool notNull);
+extern ObjectAddress AlterDomainAddConstraint(List *names, Node *constr,
+ ObjectAddress *constrAddr);
+extern ObjectAddress AlterDomainValidateConstraint(List *names, char *constrName);
+extern ObjectAddress AlterDomainDropConstraint(List *names, const char *constrName,
DropBehavior behavior, bool missing_ok);
extern void checkDomainOwner(HeapTuple tup);
-extern Oid RenameType(RenameStmt *stmt);
-extern Oid AlterTypeOwner(List *names, Oid newOwnerId, ObjectType objecttype);
+extern ObjectAddress RenameType(RenameStmt *stmt);
+extern ObjectAddress AlterTypeOwner(List *names, Oid newOwnerId, ObjectType objecttype);
extern void AlterTypeOwnerInternal(Oid typeOid, Oid newOwnerId,
bool hasDependEntry);
-extern Oid AlterTypeNamespace(List *names, const char *newschema, ObjectType objecttype);
+extern ObjectAddress AlterTypeNamespace(List *names, const char *newschema,
+ ObjectType objecttype, Oid *oldschema);
extern Oid AlterTypeNamespace_oid(Oid typeOid, Oid nspOid, ObjectAddresses *objsMoved);
extern Oid AlterTypeNamespaceInternal(Oid typeOid, Oid nspOid,
bool isImplicitArray,
#ifndef USER_H
#define USER_H
+#include "catalog/objectaddress.h"
#include "nodes/parsenodes.h"
extern Oid AlterRoleSet(AlterRoleSetStmt *stmt);
extern void DropRole(DropRoleStmt *stmt);
extern void GrantRole(GrantRoleStmt *stmt);
-extern Oid RenameRole(const char *oldname, const char *newname);
+extern ObjectAddress RenameRole(const char *oldname, const char *newname);
extern void DropOwnedObjects(DropOwnedStmt *stmt);
extern void ReassignOwnedObjects(ReassignOwnedStmt *stmt);
extern List *roleNamesToIds(List *memberNames);
#ifndef VIEW_H
#define VIEW_H
+#include "catalog/objectaddress.h"
#include "nodes/parsenodes.h"
extern void validateWithCheckOption(char *value);
-extern Oid DefineView(ViewStmt *stmt, const char *queryString);
+extern ObjectAddress DefineView(ViewStmt *stmt, const char *queryString);
extern void StoreViewQuery(Oid viewOid, Query *viewParse, bool replace);
#ifndef REWRITEDEFINE_H
#define REWRITEDEFINE_H
+#include "catalog/objectaddress.h"
#include "nodes/parsenodes.h"
#include "utils/relcache.h"
#define RULE_FIRES_ON_REPLICA 'R'
#define RULE_DISABLED 'D'
-extern Oid DefineRule(RuleStmt *stmt, const char *queryString);
+extern ObjectAddress DefineRule(RuleStmt *stmt, const char *queryString);
-extern Oid DefineQueryRewrite(char *rulename,
+extern ObjectAddress DefineQueryRewrite(char *rulename,
Oid event_relid,
Node *event_qual,
CmdType event_type,
bool replace,
List *action);
-extern Oid RenameRewriteRule(RangeVar *relation, const char *oldName,
+extern ObjectAddress RenameRewriteRule(RangeVar *relation, const char *oldName,
const char *newName);
extern void setRuleCheckAsUser(Node *node, Oid userid);