diff --git a/src/backend/bootstrap/bootparse.y b/src/backend/bootstrap/bootparse.y index fdb1f7faac..6e563b67e6 100644 --- a/src/backend/bootstrap/bootparse.y +++ b/src/backend/bootstrap/bootparse.y @@ -251,7 +251,8 @@ Boot_CreateStmt: (Datum) 0, false, true, - false); + false, + NULL); elog(DEBUG4, "relation created with OID %u", id); } do_end(); diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 1a64436d90..5ce43957d9 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -89,7 +89,7 @@ static void AddNewRelationTuple(Relation pg_class_desc, 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, @@ -935,7 +935,7 @@ AddNewRelationTuple(Relation pg_class_desc, * define a composite type corresponding to the new relation * -------------------------------- */ -static Oid +static ObjectAddress AddNewRelationType(const char *typeName, Oid typeNamespace, Oid new_rel_oid, @@ -1006,6 +1006,9 @@ AddNewRelationType(const char *typeName, * 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 * -------------------------------- */ @@ -1029,7 +1032,8 @@ heap_create_with_catalog(const char *relname, 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; @@ -1037,6 +1041,7 @@ heap_create_with_catalog(const char *relname, 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); @@ -1187,13 +1192,16 @@ heap_create_with_catalog(const char *relname, * 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. diff --git a/src/backend/catalog/objectaddress.c b/src/backend/catalog/objectaddress.c index d899dd73fe..70043fca4f 100644 --- a/src/backend/catalog/objectaddress.c +++ b/src/backend/catalog/objectaddress.c @@ -531,6 +531,12 @@ ObjectTypeMap[] = { "policy", OBJECT_POLICY } }; +const ObjectAddress InvalidObjectAddress = +{ + InvalidOid, + InvalidOid, + 0 +}; static ObjectAddress get_object_address_unqualified(ObjectType objtype, List *qualname, bool missing_ok); diff --git a/src/backend/catalog/pg_aggregate.c b/src/backend/catalog/pg_aggregate.c index b56cf287fc..df7bdfb03c 100644 --- a/src/backend/catalog/pg_aggregate.c +++ b/src/backend/catalog/pg_aggregate.c @@ -43,7 +43,7 @@ static Oid lookup_agg_function(List *fnName, int nargs, Oid *input_types, /* * AggregateCreate */ -Oid +ObjectAddress AggregateCreate(const char *aggName, Oid aggNamespace, char aggKind, @@ -522,32 +522,33 @@ AggregateCreate(const char *aggName, * 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. @@ -599,9 +600,6 @@ AggregateCreate(const char *aggName, * 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; @@ -654,7 +652,7 @@ AggregateCreate(const char *aggName, recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL); } - return procOid; + return myself; } /* diff --git a/src/backend/catalog/pg_conversion.c b/src/backend/catalog/pg_conversion.c index c3a403968d..7de738722b 100644 --- a/src/backend/catalog/pg_conversion.c +++ b/src/backend/catalog/pg_conversion.c @@ -37,7 +37,7 @@ * * Add a new tuple to pg_conversion. */ -Oid +ObjectAddress ConversionCreate(const char *conname, Oid connamespace, Oid conowner, int32 conforencoding, int32 contoencoding, @@ -141,7 +141,7 @@ ConversionCreate(const char *conname, Oid connamespace, heap_freetuple(tup); heap_close(rel, RowExclusiveLock); - return oid; + return myself; } /* diff --git a/src/backend/catalog/pg_operator.c b/src/backend/catalog/pg_operator.c index fbc173be30..072f530d98 100644 --- a/src/backend/catalog/pg_operator.c +++ b/src/backend/catalog/pg_operator.c @@ -61,7 +61,7 @@ static Oid get_other_operator(List *otherOp, Oid leftTypeId, Oid rightTypeId, bool isCommutator); -static void makeOperatorDependencies(HeapTuple tuple); +static ObjectAddress makeOperatorDependencies(HeapTuple tuple); /* @@ -325,7 +325,7 @@ OperatorShellMake(const char *operatorName, * 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, @@ -352,6 +352,7 @@ OperatorCreate(const char *operatorName, NameData oname; TupleDesc tupDesc; int i; + ObjectAddress address; /* * Sanity checks @@ -540,7 +541,7 @@ OperatorCreate(const char *operatorName, 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); @@ -564,7 +565,7 @@ OperatorCreate(const char *operatorName, if (OidIsValid(commutatorId) || OidIsValid(negatorId)) OperatorUpd(operatorObjectId, commutatorId, negatorId); - return operatorObjectId; + return address; } /* @@ -764,7 +765,7 @@ OperatorUpd(Oid baseId, Oid commId, Oid negId) * 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); @@ -860,4 +861,6 @@ makeOperatorDependencies(HeapTuple tuple) /* Dependency on extension */ recordDependencyOnCurrentExtension(&myself, true); + + return myself; } diff --git a/src/backend/catalog/pg_proc.c b/src/backend/catalog/pg_proc.c index 542539fbc3..fd5060aa7c 100644 --- a/src/backend/catalog/pg_proc.c +++ b/src/backend/catalog/pg_proc.c @@ -64,7 +64,7 @@ static bool match_prosrc_to_literal(const char *prosrc, const char *literal, * not "ArrayType *", to avoid importing array.h into pg_proc_fn.h. * ---------------------------------------------------------------- */ -Oid +ObjectAddress ProcedureCreate(const char *procedureName, Oid procNamespace, bool replace, @@ -703,7 +703,7 @@ ProcedureCreate(const char *procedureName, AtEOXact_GUC(true, save_nestlevel); } - return retval; + return myself; } diff --git a/src/backend/catalog/pg_type.c b/src/backend/catalog/pg_type.c index ed8259da55..d1ed53f5b4 100644 --- a/src/backend/catalog/pg_type.c +++ b/src/backend/catalog/pg_type.c @@ -52,7 +52,7 @@ Oid binary_upgrade_next_pg_type_oid = InvalidOid; * with correct ones, and "typisdefined" will be set to true. * ---------------------------------------------------------------- */ -Oid +ObjectAddress TypeShellMake(const char *typeName, Oid typeNamespace, Oid ownerId) { Relation pg_type_desc; @@ -63,6 +63,7 @@ TypeShellMake(const char *typeName, Oid typeNamespace, Oid ownerId) bool nulls[Natts_pg_type]; Oid typoid; NameData name; + ObjectAddress address; Assert(PointerIsValid(typeName)); @@ -171,13 +172,15 @@ TypeShellMake(const char *typeName, Oid typeNamespace, Oid ownerId) /* 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; } /* ---------------------------------------------------------------- @@ -185,12 +188,12 @@ TypeShellMake(const char *typeName, Oid typeNamespace, Oid ownerId) * * 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, @@ -233,6 +236,7 @@ TypeCreate(Oid newTypeOid, NameData name; int i; Acl *typacl = NULL; + ObjectAddress address; /* * We assume that the caller validated the arguments individually, but did @@ -488,12 +492,14 @@ TypeCreate(Oid newTypeOid, /* 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; } /* diff --git a/src/backend/catalog/toasting.c b/src/backend/catalog/toasting.c index a1efddb98f..d14c33ce02 100644 --- a/src/backend/catalog/toasting.c +++ b/src/backend/catalog/toasting.c @@ -289,7 +289,8 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid, reloptions, false, true, - true); + true, + NULL); Assert(toast_relid != InvalidOid); /* make the toast relation visible, else heap_open will fail */ diff --git a/src/backend/commands/aggregatecmds.c b/src/backend/commands/aggregatecmds.c index 70a5b8ad1b..894c89df94 100644 --- a/src/backend/commands/aggregatecmds.c +++ b/src/backend/commands/aggregatecmds.c @@ -51,7 +51,7 @@ * 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) { diff --git a/src/backend/commands/alter.c b/src/backend/commands/alter.c index 78b54b4a41..59aacef7ea 100644 --- a/src/backend/commands/alter.c +++ b/src/backend/commands/alter.c @@ -299,8 +299,10 @@ AlterObjectRename_internal(Relation rel, Oid objectId, const char *new_name) /* * 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) @@ -378,39 +380,54 @@ ExecRenameStmt(RenameStmt *stmt) 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: @@ -442,19 +459,22 @@ ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt) 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; } /* @@ -676,7 +696,7 @@ AlterObjectNamespace_internal(Relation rel, Oid objid, Oid nspOid) * 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); @@ -747,15 +767,14 @@ ExecAlterOwnerStmt(AlterOwnerStmt *stmt) 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 */ } } diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index dc1b37cb69..3febdd5cf4 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -677,7 +677,8 @@ make_new_heap(Oid OIDOldHeap, Oid NewTableSpace, char relpersistence, reloptions, false, true, - true); + true, + NULL); Assert(OIDNewHeap != InvalidOid); ReleaseSysCache(tuple); diff --git a/src/backend/commands/collationcmds.c b/src/backend/commands/collationcmds.c index 4334eb9683..df67e50942 100644 --- a/src/backend/commands/collationcmds.c +++ b/src/backend/commands/collationcmds.c @@ -37,7 +37,7 @@ /* * CREATE COLLATION */ -Oid +ObjectAddress DefineCollation(List *names, List *parameters) { char *collName; @@ -51,6 +51,7 @@ DefineCollation(List *names, List *parameters) char *collcollate = NULL; char *collctype = NULL; Oid newoid; + ObjectAddress address; collNamespace = QualifiedNameGetCreationNamespace(names, &collName); @@ -137,11 +138,13 @@ DefineCollation(List *names, List *parameters) collcollate, collctype); + ObjectAddressSet(address, CollationRelationId, newoid); + /* check that the locales can be loaded */ CommandCounterIncrement(); (void) pg_newlocale_from_collation(newoid); - return newoid; + return address; } /* diff --git a/src/backend/commands/comment.c b/src/backend/commands/comment.c index ed1e46e73c..6d8c0061bd 100644 --- a/src/backend/commands/comment.c +++ b/src/backend/commands/comment.c @@ -36,11 +36,11 @@ * 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 @@ -60,7 +60,7 @@ CommentObject(CommentStmt *stmt) ereport(WARNING, (errcode(ERRCODE_UNDEFINED_DATABASE), errmsg("database \"%s\" does not exist", database))); - return InvalidOid; + return address; } } @@ -126,7 +126,7 @@ CommentObject(CommentStmt *stmt) if (relation != NULL) relation_close(relation, NoLock); - return address.objectId; + return address; } /* diff --git a/src/backend/commands/conversioncmds.c b/src/backend/commands/conversioncmds.c index f58b0a9e9d..9cd5ced5c7 100644 --- a/src/backend/commands/conversioncmds.c +++ b/src/backend/commands/conversioncmds.c @@ -34,7 +34,7 @@ /* * CREATE CONVERSION */ -Oid +ObjectAddress CreateConversionCommand(CreateConversionStmt *stmt) { Oid namespaceId; diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index c961429a0f..54b2f382ea 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -58,8 +58,8 @@ typedef struct 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); @@ -70,7 +70,7 @@ static void intorel_destroy(DestReceiver *self); /* * ExecCreateTableAs -- execute a CREATE TABLE AS command */ -Oid +ObjectAddress ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString, ParamListInfo params, char *completionTag) { @@ -81,7 +81,7 @@ ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString, Oid save_userid = InvalidOid; int save_sec_context = 0; int save_nestlevel = 0; - Oid relOid; + ObjectAddress address; List *rewritten; PlannedStmt *plan; QueryDesc *queryDesc; @@ -99,7 +99,7 @@ ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString, (errcode(ERRCODE_DUPLICATE_TABLE), errmsg("relation \"%s\" already exists, skipping", stmt->into->rel->relname))); - return InvalidOid; + return InvalidObjectAddress; } } @@ -121,9 +121,9 @@ ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString, 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); @@ -216,10 +216,10 @@ ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString, SetUserIdAndSecContext(save_userid, save_sec_context); } - relOid = CreateAsRelid; - CreateAsRelid = InvalidOid; + address = CreateAsReladdr; + CreateAsReladdr = InvalidObjectAddress; - return relOid; + return address; } /* @@ -288,7 +288,7 @@ intorel_startup(DestReceiver *self, int operation, TupleDesc typeinfo) bool is_matview; char relkind; CreateStmt *create; - Oid intoRelationId; + ObjectAddress intoRelationAddr; Relation intoRelationDesc; RangeTblEntry *rte; Datum toast_options; @@ -385,7 +385,7 @@ intorel_startup(DestReceiver *self, int operation, TupleDesc typeinfo) /* * 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 @@ -403,7 +403,7 @@ intorel_startup(DestReceiver *self, int operation, TupleDesc typeinfo) (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) @@ -411,14 +411,14 @@ intorel_startup(DestReceiver *self, int operation, TupleDesc typeinfo) /* 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. @@ -428,7 +428,7 @@ intorel_startup(DestReceiver *self, int operation, TupleDesc typeinfo) */ rte = makeNode(RangeTblEntry); rte->rtekind = RTE_RELATION; - rte->relid = intoRelationId; + rte->relid = intoRelationAddr.objectId; rte->relkind = relkind; rte->requiredPerms = ACL_INSERT; @@ -446,7 +446,7 @@ intorel_startup(DestReceiver *self, int operation, TupleDesc typeinfo) * 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")))); @@ -464,8 +464,8 @@ intorel_startup(DestReceiver *self, int operation, TupleDesc typeinfo) 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 diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c index 5e669619ba..8579136420 100644 --- a/src/backend/commands/dbcommands.c +++ b/src/backend/commands/dbcommands.c @@ -938,7 +938,7 @@ dropdb(const char *dbname, bool missing_ok) /* * Rename database */ -Oid +ObjectAddress RenameDatabase(const char *oldname, const char *newname) { Oid db_id; @@ -946,6 +946,7 @@ RenameDatabase(const char *oldname, const char *newname) Relation rel; int notherbackends; int npreparedxacts; + ObjectAddress address; /* * Look up the target database's OID, and get exclusive lock on it. We @@ -1013,12 +1014,14 @@ RenameDatabase(const char *oldname, const char *newname) 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; } @@ -1560,7 +1563,7 @@ AlterDatabaseSet(AlterDatabaseSetStmt *stmt) /* * ALTER DATABASE name OWNER TO newowner */ -Oid +ObjectAddress AlterDatabaseOwner(const char *dbname, Oid newOwnerId) { Oid db_id; @@ -1569,6 +1572,7 @@ AlterDatabaseOwner(const char *dbname, Oid newOwnerId) 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, @@ -1663,12 +1667,14 @@ AlterDatabaseOwner(const char *dbname, Oid newOwnerId) 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; } diff --git a/src/backend/commands/event_trigger.c b/src/backend/commands/event_trigger.c index deeb8dcfaf..f573c9ce70 100644 --- a/src/backend/commands/event_trigger.c +++ b/src/backend/commands/event_trigger.c @@ -518,12 +518,13 @@ AlterEventTrigger(AlterEventTrigStmt *stmt) /* * 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); @@ -538,11 +539,13 @@ AlterEventTriggerOwner(const char *name, Oid newOwnerId) AlterEventTriggerOwner_internal(rel, tup, newOwnerId); + ObjectAddressSet(address, EventTriggerRelationId, evtOid); + heap_freetuple(tup); heap_close(rel, RowExclusiveLock); - return evtOid; + return address; } /* diff --git a/src/backend/commands/extension.c b/src/backend/commands/extension.c index 3b95552a60..aa733575e4 100644 --- a/src/backend/commands/extension.c +++ b/src/backend/commands/extension.c @@ -1170,7 +1170,7 @@ find_update_path(List *evi_list, /* * CREATE EXTENSION */ -Oid +ObjectAddress CreateExtension(CreateExtensionStmt *stmt) { DefElem *d_schema = NULL; @@ -1188,6 +1188,7 @@ CreateExtension(CreateExtensionStmt *stmt) List *requiredSchemas; Oid extensionOid; ListCell *lc; + ObjectAddress address; /* Check extension name validity before any filesystem access */ check_valid_extension_name(stmt->extname); @@ -1206,7 +1207,7 @@ CreateExtension(CreateExtensionStmt *stmt) (errcode(ERRCODE_DUPLICATE_OBJECT), errmsg("extension \"%s\" already exists, skipping", stmt->extname))); - return InvalidOid; + return InvalidObjectAddress; } else ereport(ERROR, @@ -1443,12 +1444,13 @@ CreateExtension(CreateExtensionStmt *stmt) /* * Insert new tuple into pg_extension, and create dependency entries. */ - extensionOid = InsertExtensionTuple(control->name, extowner, - schemaOid, control->relocatable, - versionName, - PointerGetDatum(NULL), - PointerGetDatum(NULL), - requiredExtensions); + address = InsertExtensionTuple(control->name, extowner, + schemaOid, control->relocatable, + versionName, + PointerGetDatum(NULL), + PointerGetDatum(NULL), + requiredExtensions); + extensionOid = address.objectId; /* * Apply any control-file comment on extension @@ -1471,7 +1473,7 @@ CreateExtension(CreateExtensionStmt *stmt) ApplyExtensionUpdates(extensionOid, pcontrol, versionName, updateVersions); - return extensionOid; + return address; } /* @@ -1487,7 +1489,7 @@ CreateExtension(CreateExtensionStmt *stmt) * extConfig and extCondition should be arrays or PointerGetDatum(NULL). * We declare them as plain Datum to avoid needing array.h in extension.h. */ -Oid +ObjectAddress InsertExtensionTuple(const char *extName, Oid extOwner, Oid schemaOid, bool relocatable, const char *extVersion, Datum extConfig, Datum extCondition, @@ -1564,7 +1566,7 @@ InsertExtensionTuple(const char *extName, Oid extOwner, /* Post creation hook for new extension */ InvokeObjectPostCreateHook(ExtensionRelationId, extensionOid, 0); - return extensionOid; + return myself; } /* @@ -2399,8 +2401,8 @@ extension_config_remove(Oid extensionoid, Oid tableoid) /* * Execute ALTER EXTENSION SET SCHEMA */ -Oid -AlterExtensionNamespace(List *names, const char *newschema) +ObjectAddress +AlterExtensionNamespace(List *names, const char *newschema, Oid *oldschema) { char *extensionName; Oid extensionOid; @@ -2416,6 +2418,7 @@ AlterExtensionNamespace(List *names, const char *newschema) SysScanDesc depScan; HeapTuple depTup; ObjectAddresses *objsMoved; + ObjectAddress extAddr; if (list_length(names) != 1) ereport(ERROR, @@ -2480,7 +2483,7 @@ AlterExtensionNamespace(List *names, const char *newschema) if (extForm->extnamespace == nspOid) { heap_close(extRel, RowExclusiveLock); - return InvalidOid; + return InvalidObjectAddress; } /* Check extension is supposed to be relocatable */ @@ -2557,6 +2560,10 @@ AlterExtensionNamespace(List *names, const char *newschema) get_namespace_name(oldNspOid)))); } + /* report old schema, if caller wants it */ + if (oldschema) + *oldschema = oldNspOid; + systable_endscan(depScan); relation_close(depRel, AccessShareLock); @@ -2575,13 +2582,15 @@ AlterExtensionNamespace(List *names, const char *newschema) InvokeObjectPostAlterHook(ExtensionRelationId, extensionOid, 0); - return extensionOid; + ObjectAddressSet(extAddr, ExtensionRelationId, extensionOid); + + return extAddr; } /* * Execute ALTER EXTENSION UPDATE */ -Oid +ObjectAddress ExecAlterExtensionStmt(AlterExtensionStmt *stmt) { DefElem *d_new_version = NULL; @@ -2597,6 +2606,7 @@ ExecAlterExtensionStmt(AlterExtensionStmt *stmt) Datum datum; bool isnull; ListCell *lc; + ObjectAddress address; /* * We use global variables to track the extension being created, so we can @@ -2698,7 +2708,7 @@ ExecAlterExtensionStmt(AlterExtensionStmt *stmt) ereport(NOTICE, (errmsg("version \"%s\" of extension \"%s\" is already installed", versionName, stmt->extname))); - return InvalidOid; + return InvalidObjectAddress; } /* @@ -2715,7 +2725,9 @@ ExecAlterExtensionStmt(AlterExtensionStmt *stmt) ApplyExtensionUpdates(extensionOid, control, oldVersionName, updateVersions); - return extensionOid; + ObjectAddressSet(address, ExtensionRelationId, extensionOid); + + return address; } /* @@ -2879,9 +2891,15 @@ ApplyExtensionUpdates(Oid extensionOid, /* * Execute ALTER EXTENSION ADD/DROP + * + * Return value is the address of the altered extension. + * + * objAddr is an output argument which, if not NULL, is set to the address of + * the added/dropped object. */ -Oid -ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt) +ObjectAddress +ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt, + ObjectAddress *objAddr) { ObjectAddress extension; ObjectAddress object; @@ -2906,6 +2924,10 @@ ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt) object = get_object_address(stmt->objtype, stmt->objname, stmt->objargs, &relation, ShareUpdateExclusiveLock, false); + Assert(object.objectSubId == 0); + if (objAddr) + *objAddr = object; + /* Permission check: must own target object, too */ check_object_ownership(GetUserId(), stmt->objtype, object, stmt->objname, stmt->objargs, relation); @@ -2984,5 +3006,5 @@ ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt) if (relation != NULL) relation_close(relation, NoLock); - return extension.objectId; + return extension; } diff --git a/src/backend/commands/foreigncmds.c b/src/backend/commands/foreigncmds.c index 537e31c34e..bd4839189e 100644 --- a/src/backend/commands/foreigncmds.c +++ b/src/backend/commands/foreigncmds.c @@ -292,12 +292,13 @@ AlterForeignDataWrapperOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerI * * 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); @@ -312,11 +313,13 @@ AlterForeignDataWrapperOwner(const char *name, Oid newOwnerId) AlterForeignDataWrapperOwner_internal(rel, tup, newOwnerId); + ObjectAddressSet(address, ForeignDataWrapperRelationId, fdwId); + heap_freetuple(tup); heap_close(rel, RowExclusiveLock); - return fdwId; + return address; } /* @@ -427,12 +430,13 @@ AlterForeignServerOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId) /* * 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); @@ -447,11 +451,13 @@ AlterForeignServerOwner(const char *name, Oid newOwnerId) AlterForeignServerOwner_internal(rel, tup, newOwnerId); + ObjectAddressSet(address, ForeignServerRelationId, servOid); + heap_freetuple(tup); heap_close(rel, RowExclusiveLock); - return servOid; + return address; } /* @@ -569,7 +575,7 @@ parse_func_options(List *func_options, /* * Create a foreign-data wrapper */ -Oid +ObjectAddress CreateForeignDataWrapper(CreateFdwStmt *stmt) { Relation rel; @@ -676,14 +682,14 @@ CreateForeignDataWrapper(CreateFdwStmt *stmt) heap_close(rel, RowExclusiveLock); - return fdwId; + return myself; } /* * Alter foreign-data wrapper */ -Oid +ObjectAddress AlterForeignDataWrapper(AlterFdwStmt *stmt) { Relation rel; @@ -699,6 +705,7 @@ AlterForeignDataWrapper(AlterFdwStmt *stmt) bool validator_given; Oid fdwhandler; Oid fdwvalidator; + ObjectAddress myself; rel = heap_open(ForeignDataWrapperRelationId, RowExclusiveLock); @@ -801,10 +808,11 @@ AlterForeignDataWrapper(AlterFdwStmt *stmt) heap_freetuple(tp); + ObjectAddressSet(myself, ForeignDataWrapperRelationId, fdwId); + /* Update function dependencies if we changed them */ if (handler_given || validator_given) { - ObjectAddress myself; ObjectAddress referenced; /* @@ -817,9 +825,6 @@ AlterForeignDataWrapper(AlterFdwStmt *stmt) DEPENDENCY_NORMAL); /* And build new ones. */ - myself.classId = ForeignDataWrapperRelationId; - myself.objectId = fdwId; - myself.objectSubId = 0; if (OidIsValid(fdwhandler)) { @@ -842,7 +847,7 @@ AlterForeignDataWrapper(AlterFdwStmt *stmt) heap_close(rel, RowExclusiveLock); - return fdwId; + return myself; } @@ -873,7 +878,7 @@ RemoveForeignDataWrapperById(Oid fdwId) /* * Create a foreign server */ -Oid +ObjectAddress CreateForeignServer(CreateForeignServerStmt *stmt) { Relation rel; @@ -979,14 +984,14 @@ CreateForeignServer(CreateForeignServerStmt *stmt) heap_close(rel, RowExclusiveLock); - return srvId; + return myself; } /* * Alter foreign server */ -Oid +ObjectAddress AlterForeignServer(AlterForeignServerStmt *stmt) { Relation rel; @@ -996,6 +1001,7 @@ AlterForeignServer(AlterForeignServerStmt *stmt) bool repl_repl[Natts_pg_foreign_server]; Oid srvId; Form_pg_foreign_server srvForm; + ObjectAddress address; rel = heap_open(ForeignServerRelationId, RowExclusiveLock); @@ -1072,11 +1078,13 @@ AlterForeignServer(AlterForeignServerStmt *stmt) InvokeObjectPostAlterHook(ForeignServerRelationId, srvId, 0); + ObjectAddressSet(address, ForeignServerRelationId, srvId); + heap_freetuple(tp); heap_close(rel, RowExclusiveLock); - return srvId; + return address; } @@ -1134,7 +1142,7 @@ user_mapping_ddl_aclcheck(Oid umuserid, Oid serverid, const char *servername) /* * Create user mapping */ -Oid +ObjectAddress CreateUserMapping(CreateUserMappingStmt *stmt) { Relation rel; @@ -1225,14 +1233,14 @@ CreateUserMapping(CreateUserMappingStmt *stmt) heap_close(rel, RowExclusiveLock); - return umId; + return myself; } /* * Alter user mapping */ -Oid +ObjectAddress AlterUserMapping(AlterUserMappingStmt *stmt) { Relation rel; @@ -1243,6 +1251,7 @@ AlterUserMapping(AlterUserMappingStmt *stmt) Oid useId; Oid umId; ForeignServer *srv; + ObjectAddress address; rel = heap_open(UserMappingRelationId, RowExclusiveLock); @@ -1309,11 +1318,13 @@ AlterUserMapping(AlterUserMappingStmt *stmt) 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; } diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c index b3a91fc681..f4725056da 100644 --- a/src/backend/commands/functioncmds.c +++ b/src/backend/commands/functioncmds.c @@ -112,6 +112,7 @@ compute_return_type(TypeName *returnType, Oid languageOid, Oid namespaceId; AclResult aclresult; char *typname; + ObjectAddress address; /* * Only C-coded functions can be I/O functions. We enforce this @@ -144,7 +145,8 @@ compute_return_type(TypeName *returnType, Oid languageOid, 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)); } @@ -810,7 +812,7 @@ interpret_AS_clause(Oid languageOid, const char *languageName, * CreateFunction * Execute a CREATE FUNCTION utility statement. */ -Oid +ObjectAddress CreateFunction(CreateFunctionStmt *stmt, const char *queryString) { char *probin_str; @@ -1071,7 +1073,7 @@ RemoveFunctionById(Oid funcOid) * RENAME and OWNER clauses, which are handled as part of the generic * ALTER framework). */ -Oid +ObjectAddress AlterFunction(AlterFunctionStmt *stmt) { HeapTuple tup; @@ -1086,6 +1088,7 @@ AlterFunction(AlterFunctionStmt *stmt) List *set_items = NIL; DefElem *cost_item = NULL; DefElem *rows_item = NULL; + ObjectAddress address; rel = heap_open(ProcedureRelationId, RowExclusiveLock); @@ -1201,10 +1204,12 @@ AlterFunction(AlterFunctionStmt *stmt) InvokeObjectPostAlterHook(ProcedureRelationId, funcOid, 0); + ObjectAddressSet(address, ProcedureRelationId, funcOid); + heap_close(rel, NoLock); heap_freetuple(tup); - return funcOid; + return address; } /* @@ -1282,7 +1287,7 @@ SetFunctionArgType(Oid funcOid, int argIndex, Oid newArgType) /* * CREATE CAST */ -Oid +ObjectAddress CreateCast(CreateCastStmt *stmt) { Oid sourcetypeid; @@ -1596,7 +1601,7 @@ CreateCast(CreateCastStmt *stmt) heap_close(relation, RowExclusiveLock); - return castid; + return myself; } /* diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index e859669897..6563f2bb5b 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -291,9 +291,9 @@ CheckIndexCompatible(Oid oldId, * 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, @@ -323,6 +323,7 @@ DefineIndex(Oid relationId, int numberOfAttributes; TransactionId limitXmin; VirtualTransactionId *old_snapshots; + ObjectAddress address; int n_old_snapshots; LockRelId heaprelid; LOCKTAG heaplocktag; @@ -613,10 +614,12 @@ DefineIndex(Oid relationId, 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 */ @@ -628,7 +631,7 @@ DefineIndex(Oid relationId, { /* 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 */ @@ -873,7 +876,7 @@ DefineIndex(Oid relationId, */ UnlockRelationIdForSession(&heaprelid, ShareUpdateExclusiveLock); - return indexRelationId; + return address; } diff --git a/src/backend/commands/matview.c b/src/backend/commands/matview.c index 92d9032328..eb16bb31ff 100644 --- a/src/backend/commands/matview.c +++ b/src/backend/commands/matview.c @@ -134,7 +134,7 @@ SetMatViewPopulatedState(Relation relation, bool newstate) * 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) { @@ -153,6 +153,7 @@ ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString, Oid save_userid; int save_sec_context; int save_nestlevel; + ObjectAddress address; /* Determine strength of lock needed. */ concurrent = stmt->concurrent; @@ -311,7 +312,9 @@ ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString, /* Restore userid and security context */ SetUserIdAndSecContext(save_userid, save_sec_context); - return matviewOid; + ObjectAddressSet(address, RelationRelationId, matviewOid); + + return address; } /* diff --git a/src/backend/commands/opclasscmds.c b/src/backend/commands/opclasscmds.c index 16f6f0503c..c327cc0473 100644 --- a/src/backend/commands/opclasscmds.c +++ b/src/backend/commands/opclasscmds.c @@ -246,7 +246,7 @@ get_opclass_oid(Oid amID, List *opclassname, bool missing_ok) * * Caller must have done permissions checks etc. already. */ -static Oid +static ObjectAddress CreateOpFamily(char *amname, char *opfname, Oid namespaceoid, Oid amoid) { Oid opfamilyoid; @@ -319,14 +319,14 @@ CreateOpFamily(char *amname, char *opfname, Oid namespaceoid, Oid amoid) 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 */ @@ -445,11 +445,14 @@ DefineOpClass(CreateOpClassStmt *stmt) } 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; } } @@ -719,7 +722,7 @@ DefineOpClass(CreateOpClassStmt *stmt) heap_close(rel, RowExclusiveLock); - return opclassoid; + return myself; } @@ -727,7 +730,7 @@ DefineOpClass(CreateOpClassStmt *stmt) * DefineOpFamily * Define a new index operator family. */ -Oid +ObjectAddress DefineOpFamily(CreateOpFamilyStmt *stmt) { char *opfname; /* name of opfamily we're creating */ diff --git a/src/backend/commands/operatorcmds.c b/src/backend/commands/operatorcmds.c index 29960191c0..1efaacfd5e 100644 --- a/src/backend/commands/operatorcmds.c +++ b/src/backend/commands/operatorcmds.c @@ -59,7 +59,7 @@ * * 'parameters' is a list of DefElem */ -Oid +ObjectAddress DefineOperator(List *names, List *parameters) { char *oprName; diff --git a/src/backend/commands/policy.c b/src/backend/commands/policy.c index d98da0dd50..e86299781f 100644 --- a/src/backend/commands/policy.c +++ b/src/backend/commands/policy.c @@ -460,7 +460,7 @@ RemovePolicyById(Oid policy_id) * * stmt - the CreatePolicyStmt that describes the policy to create. */ -Oid +ObjectAddress CreatePolicy(CreatePolicyStmt *stmt) { Relation pg_policy_rel; @@ -626,7 +626,7 @@ CreatePolicy(CreatePolicyStmt *stmt) relation_close(target_table, NoLock); heap_close(pg_policy_rel, RowExclusiveLock); - return policy_id; + return myself; } /* @@ -635,7 +635,7 @@ CreatePolicy(CreatePolicyStmt *stmt) * * stmt - the AlterPolicyStmt that describes the policy and how to alter it. */ -Oid +ObjectAddress AlterPolicy(AlterPolicyStmt *stmt) { Relation pg_policy_rel; @@ -830,14 +830,14 @@ AlterPolicy(AlterPolicyStmt *stmt) 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; @@ -847,6 +847,7 @@ rename_policy(RenameStmt *stmt) ScanKeyData skey[2]; SysScanDesc sscan; HeapTuple policy_tuple; + ObjectAddress address; /* Get id of table. Also handles permissions checks. */ table_id = RangeVarGetRelidExtended(stmt->relation, AccessExclusiveLock, @@ -925,6 +926,8 @@ rename_policy(RenameStmt *stmt) 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 @@ -937,7 +940,7 @@ rename_policy(RenameStmt *stmt) heap_close(pg_policy_rel, RowExclusiveLock); relation_close(target_table, NoLock); - return opoloid; + return address; } /* diff --git a/src/backend/commands/proclang.c b/src/backend/commands/proclang.c index 0722461614..11e6213e80 100644 --- a/src/backend/commands/proclang.c +++ b/src/backend/commands/proclang.c @@ -51,7 +51,7 @@ typedef struct 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); @@ -60,10 +60,11 @@ static PLTemplate *find_language_template(const char *languageName); * CREATE PROCEDURAL LANGUAGE * --------------------------------------------------------------------- */ -Oid +ObjectAddress CreateProceduralLanguage(CreatePLangStmt *stmt) { PLTemplate *pltemplate; + ObjectAddress tmpAddr; Oid handlerOid, inlineOid, valOid; @@ -118,30 +119,31 @@ CreateProceduralLanguage(CreatePLangStmt *stmt) } 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; } /* @@ -155,30 +157,31 @@ CreateProceduralLanguage(CreatePLangStmt *stmt) 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 @@ -195,30 +198,31 @@ CreateProceduralLanguage(CreatePLangStmt *stmt) 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 @@ -309,7 +313,7 @@ CreateProceduralLanguage(CreatePLangStmt *stmt) /* * 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) @@ -433,7 +437,7 @@ create_proc_lang(const char *languageName, bool replace, heap_close(rel, RowExclusiveLock); - return myself.objectId; + return myself; } /* diff --git a/src/backend/commands/schemacmds.c b/src/backend/commands/schemacmds.c index a44dbf453e..722142e16e 100644 --- a/src/backend/commands/schemacmds.c +++ b/src/backend/commands/schemacmds.c @@ -195,13 +195,14 @@ RemoveSchemaById(Oid schemaOid) /* * 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); @@ -243,10 +244,12 @@ RenameSchema(const char *oldname, const char *newname) InvokeObjectPostAlterHook(NamespaceRelationId, HeapTupleGetOid(tup), 0); + ObjectAddressSet(address, NamespaceRelationId, nspOid); + heap_close(rel, NoLock); heap_freetuple(tup); - return nspOid; + return address; } void @@ -272,12 +275,13 @@ AlterSchemaOwner_oid(Oid oid, Oid newOwnerId) /* * Change schema owner */ -Oid +ObjectAddress AlterSchemaOwner(const char *name, Oid newOwnerId) { Oid nspOid; HeapTuple tup; Relation rel; + ObjectAddress address; rel = heap_open(NamespaceRelationId, RowExclusiveLock); @@ -291,11 +295,13 @@ AlterSchemaOwner(const char *name, Oid newOwnerId) AlterSchemaOwner_internal(tup, rel, newOwnerId); + ObjectAddressSet(address, NamespaceRelationId, nspOid); + ReleaseSysCache(tup); heap_close(rel, RowExclusiveLock); - return nspOid; + return address; } static void diff --git a/src/backend/commands/seclabel.c b/src/backend/commands/seclabel.c index 6e15bc8de7..1ef98ce353 100644 --- a/src/backend/commands/seclabel.c +++ b/src/backend/commands/seclabel.c @@ -37,8 +37,10 @@ static List *label_provider_list = NIL; * 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; @@ -133,7 +135,7 @@ ExecSecLabelStmt(SecLabelStmt *stmt) if (relation != NULL) relation_close(relation, NoLock); - return address.objectId; + return address; } /* diff --git a/src/backend/commands/sequence.c b/src/backend/commands/sequence.c index 0070c4f34e..6d316d62b6 100644 --- a/src/backend/commands/sequence.c +++ b/src/backend/commands/sequence.c @@ -104,13 +104,14 @@ static void process_owned_by(Relation seqrel, List *owned_by); * 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; @@ -139,7 +140,7 @@ DefineSequence(CreateSeqStmt *seq) (errcode(ERRCODE_DUPLICATE_TABLE), errmsg("relation \"%s\" already exists, skipping", seq->sequence->relname))); - return InvalidOid; + return InvalidObjectAddress; } } @@ -233,7 +234,8 @@ DefineSequence(CreateSeqStmt *seq) 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); @@ -249,7 +251,7 @@ DefineSequence(CreateSeqStmt *seq) heap_close(rel, NoLock); - return seqoid; + return address; } /* @@ -401,7 +403,7 @@ fill_seq_with_data(Relation rel, HeapTuple tuple) * * Modify the definition of a sequence relation */ -Oid +ObjectAddress AlterSequence(AlterSeqStmt *stmt) { Oid relid; @@ -412,6 +414,7 @@ AlterSequence(AlterSeqStmt *stmt) 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); @@ -420,7 +423,7 @@ AlterSequence(AlterSeqStmt *stmt) ereport(NOTICE, (errmsg("relation \"%s\" does not exist, skipping", stmt->sequence->relname))); - return InvalidOid; + return InvalidObjectAddress; } init_sequence(relid, &elm, &seqrel); @@ -484,9 +487,11 @@ AlterSequence(AlterSeqStmt *stmt) InvokeObjectPostAlterHook(RelationRelationId, relid, 0); + ObjectAddressSet(address, RelationRelationId, relid); + relation_close(seqrel, NoLock); - return relid; + return address; } diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 745502072e..653677892d 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -435,17 +435,19 @@ static void RangeVarCallbackForAlterRelation(const RangeVar *rv, Oid relid, * 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; @@ -465,6 +467,7 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId) AttrNumber attnum; static char *validnsps[] = HEAP_RELOPT_NAMESPACES; Oid ofTypeId; + ObjectAddress address; /* * Truncate relname to appropriate length (probably a waste of time, as @@ -657,7 +660,8 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId) reloptions, true, allowSystemTableMods, - false); + false, + typaddress); /* Store inheritance information for new rel. */ StoreCatalogInheritance(relationId, inheritOids); @@ -689,13 +693,15 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId) 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; } /* @@ -2158,8 +2164,10 @@ renameatt_check(Oid myrelid, Form_pg_class classform, bool recursing) /* * 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, @@ -2172,7 +2180,7 @@ renameatt_internal(Oid myrelid, 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 @@ -2300,6 +2308,8 @@ renameatt_internal(Oid myrelid, heap_close(attrelation, RowExclusiveLock); relation_close(targetrelation, NoLock); /* close rel but keep lock */ + + return attnum; } /* @@ -2322,11 +2332,15 @@ RangeVarCallbackForRenameAttribute(const RangeVar *rv, Oid relid, Oid oldrelid, /* * 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, @@ -2339,26 +2353,27 @@ renameatt(RenameStmt *stmt) 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, @@ -2371,6 +2386,7 @@ rename_constraint_internal(Oid myrelid, Oid constraintOid; HeapTuple tuple; Form_pg_constraint con; + ObjectAddress address; AssertArg(!myrelid || !mytypid); @@ -2446,15 +2462,17 @@ rename_constraint_internal(Oid myrelid, 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; @@ -2497,10 +2515,11 @@ RenameConstraint(RenameStmt *stmt) * 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, @@ -2520,13 +2539,15 @@ RenameRelation(RenameStmt *stmt) 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; } /* @@ -5702,7 +5723,7 @@ ATExecAddIndex(AlteredTableInfo *tab, Relation rel, bool check_rights; bool skip_build; bool quiet; - Oid new_index; + ObjectAddress address; Assert(IsA(stmt, IndexStmt)); Assert(!stmt->concurrent); @@ -5717,13 +5738,13 @@ ATExecAddIndex(AlteredTableInfo *tab, Relation rel, /* 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 @@ -5733,7 +5754,7 @@ ATExecAddIndex(AlteredTableInfo *tab, Relation rel, */ 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); @@ -10919,8 +10940,8 @@ ATPrepChangePersistence(Relation rel, bool toLogged) /* * Execute ALTER TABLE SET SCHEMA */ -Oid -AlterTableNamespace(AlterObjectSchemaStmt *stmt) +ObjectAddress +AlterTableNamespace(AlterObjectSchemaStmt *stmt, Oid *oldschema) { Relation rel; Oid relid; @@ -10928,6 +10949,7 @@ AlterTableNamespace(AlterObjectSchemaStmt *stmt) Oid nspOid; RangeVar *newrv; ObjectAddresses *objsMoved; + ObjectAddress myself; relid = RangeVarGetRelidExtended(stmt->relation, AccessExclusiveLock, stmt->missing_ok, false, @@ -10939,7 +10961,7 @@ AlterTableNamespace(AlterObjectSchemaStmt *stmt) ereport(NOTICE, (errmsg("relation \"%s\" does not exist, skipping", stmt->relation->relname))); - return InvalidOid; + return InvalidObjectAddress; } rel = relation_open(relid, NoLock); @@ -10972,10 +10994,15 @@ AlterTableNamespace(AlterObjectSchemaStmt *stmt) 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; } /* diff --git a/src/backend/commands/tablespace.c b/src/backend/commands/tablespace.c index 03cc8fe8d8..68b6917df5 100644 --- a/src/backend/commands/tablespace.c +++ b/src/backend/commands/tablespace.c @@ -846,7 +846,7 @@ directory_is_empty(const char *path) /* * Rename a tablespace */ -Oid +ObjectAddress RenameTableSpace(const char *oldname, const char *newname) { Oid tspId; @@ -856,6 +856,7 @@ RenameTableSpace(const char *oldname, const char *newname) HeapTuple tup; HeapTuple newtuple; Form_pg_tablespace newform; + ObjectAddress address; /* Search pg_tablespace */ rel = heap_open(TableSpaceRelationId, RowExclusiveLock); @@ -912,9 +913,11 @@ RenameTableSpace(const char *oldname, const char *newname) InvokeObjectPostAlterHook(TableSpaceRelationId, tspId, 0); + ObjectAddressSet(address, TableSpaceRelationId, tspId); + heap_close(rel, NoLock); - return tspId; + return address; } /* diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c index a84e86ef80..e491c5ba77 100644 --- a/src/backend/commands/trigger.c +++ b/src/backend/commands/trigger.c @@ -100,7 +100,7 @@ static void AfterTriggerEnlargeQueryState(void); /* - * 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. @@ -129,10 +129,11 @@ static void AfterTriggerEnlargeQueryState(void); * 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) @@ -459,7 +460,7 @@ CreateTrigger(CreateTrigStmt *stmt, const char *queryString, ConvertTriggerToFK(stmt, funcoid); - return InvalidOid; + return InvalidObjectAddress; } /* @@ -799,7 +800,7 @@ CreateTrigger(CreateTrigStmt *stmt, const char *queryString, /* Keep lock on target rel until end of xact */ heap_close(rel, NoLock); - return trigoid; + return myself; } @@ -1249,7 +1250,7 @@ RangeVarCallbackForRenameTrigger(const RangeVar *rv, Oid relid, Oid oldrelid, * modify tgname in trigger tuple * update row in catalog */ -Oid +ObjectAddress renametrig(RenameStmt *stmt) { Oid tgoid; @@ -1259,6 +1260,7 @@ renametrig(RenameStmt *stmt) SysScanDesc tgscan; ScanKeyData key[2]; Oid relid; + ObjectAddress address; /* * Look up name, check permissions, and acquire lock (which we will NOT @@ -1351,6 +1353,8 @@ renametrig(RenameStmt *stmt) stmt->subname, RelationGetRelationName(targetrel)))); } + ObjectAddressSet(address, TriggerRelationId, tgoid); + systable_endscan(tgscan); heap_close(tgrel, RowExclusiveLock); @@ -1360,7 +1364,7 @@ renametrig(RenameStmt *stmt) */ relation_close(targetrel, NoLock); - return tgoid; + return address; } diff --git a/src/backend/commands/tsearchcmds.c b/src/backend/commands/tsearchcmds.c index c6f89941e8..45bafd3170 100644 --- a/src/backend/commands/tsearchcmds.c +++ b/src/backend/commands/tsearchcmds.c @@ -120,8 +120,10 @@ get_ts_parser_func(DefElem *defel, int attnum) /* * 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); @@ -162,12 +164,14 @@ makeParserDependencies(HeapTuple 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; @@ -179,6 +183,7 @@ DefineTSParser(List *names, List *parameters) NameData pname; Oid prsOid; Oid namespaceoid; + ObjectAddress address; if (!superuser()) ereport(ERROR, @@ -269,7 +274,7 @@ DefineTSParser(List *names, List *parameters) CatalogUpdateIndexes(prsRel, tup); - makeParserDependencies(tup); + address = makeParserDependencies(tup); /* Post creation hook for new text search parser */ InvokeObjectPostCreateHook(TSParserRelationId, prsOid, 0); @@ -278,7 +283,7 @@ DefineTSParser(List *names, List *parameters) heap_close(prsRel, RowExclusiveLock); - return prsOid; + return address; } /* @@ -308,8 +313,10 @@ RemoveTSParserById(Oid prsId) /* * 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); @@ -337,6 +344,8 @@ makeDictionaryDependencies(HeapTuple tuple) referenced.objectId = dict->dicttemplate; referenced.objectSubId = 0; recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL); + + return myself; } /* @@ -397,7 +406,7 @@ verify_dictoptions(Oid tmplId, List *dictoptions) /* * CREATE TEXT SEARCH DICTIONARY */ -Oid +ObjectAddress DefineTSDictionary(List *names, List *parameters) { ListCell *pl; @@ -412,6 +421,7 @@ DefineTSDictionary(List *names, List *parameters) Oid namespaceoid; AclResult aclresult; char *dictname; + ObjectAddress address; /* Convert list of names to a name and namespace */ namespaceoid = QualifiedNameGetCreationNamespace(names, &dictname); @@ -475,7 +485,7 @@ DefineTSDictionary(List *names, List *parameters) CatalogUpdateIndexes(dictRel, tup); - makeDictionaryDependencies(tup); + address = makeDictionaryDependencies(tup); /* Post creation hook for new text search dictionary */ InvokeObjectPostCreateHook(TSDictionaryRelationId, dictOid, 0); @@ -484,7 +494,7 @@ DefineTSDictionary(List *names, List *parameters) heap_close(dictRel, RowExclusiveLock); - return dictOid; + return address; } /* @@ -514,7 +524,7 @@ RemoveTSDictionaryById(Oid dictId) /* * ALTER TEXT SEARCH DICTIONARY */ -Oid +ObjectAddress AlterTSDictionary(AlterTSDictionaryStmt *stmt) { HeapTuple tup, @@ -528,6 +538,7 @@ AlterTSDictionary(AlterTSDictionaryStmt *stmt) 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); @@ -614,6 +625,8 @@ AlterTSDictionary(AlterTSDictionaryStmt *stmt) 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 @@ -625,7 +638,7 @@ AlterTSDictionary(AlterTSDictionaryStmt *stmt) heap_close(rel, RowExclusiveLock); - return dictId; + return address; } /* ---------------------- TS Template commands -----------------------*/ @@ -678,7 +691,7 @@ get_ts_template_func(DefElem *defel, int attnum) /* * 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); @@ -710,12 +723,14 @@ makeTSTemplateDependencies(HeapTuple 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; @@ -728,6 +743,7 @@ DefineTSTemplate(List *names, List *parameters) Oid tmplOid; Oid namespaceoid; char *tmplname; + ObjectAddress address; if (!superuser()) ereport(ERROR, @@ -793,7 +809,7 @@ DefineTSTemplate(List *names, List *parameters) CatalogUpdateIndexes(tmplRel, tup); - makeTSTemplateDependencies(tup); + address = makeTSTemplateDependencies(tup); /* Post creation hook for new text search template */ InvokeObjectPostCreateHook(TSTemplateRelationId, tmplOid, 0); @@ -802,7 +818,7 @@ DefineTSTemplate(List *names, List *parameters) heap_close(tmplRel, RowExclusiveLock); - return tmplOid; + return address; } /* @@ -860,7 +876,7 @@ GetTSConfigTuple(List *names) * 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) { @@ -940,12 +956,14 @@ makeConfigurationDependencies(HeapTuple tuple, bool removeOld, 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; @@ -961,6 +979,7 @@ DefineTSConfiguration(List *names, List *parameters) Oid prsOid = InvalidOid; Oid cfgOid; ListCell *pl; + ObjectAddress address; /* Convert list of names to a name and namespace */ namespaceoid = QualifiedNameGetCreationNamespace(names, &cfgname); @@ -1088,7 +1107,7 @@ DefineTSConfiguration(List *names, List *parameters) systable_endscan(scan); } - makeConfigurationDependencies(tup, false, mapRel); + address = makeConfigurationDependencies(tup, false, mapRel); /* Post creation hook for new text search configuration */ InvokeObjectPostCreateHook(TSConfigRelationId, cfgOid, 0); @@ -1099,7 +1118,7 @@ DefineTSConfiguration(List *names, List *parameters) heap_close(mapRel, RowExclusiveLock); heap_close(cfgRel, RowExclusiveLock); - return cfgOid; + return address; } /* @@ -1153,12 +1172,13 @@ RemoveTSConfigurationById(Oid cfgId) /* * 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); @@ -1189,11 +1209,13 @@ AlterTSConfiguration(AlterTSConfigurationStmt *stmt) InvokeObjectPostAlterHook(TSConfigMapRelationId, HeapTupleGetOid(tup), 0); + ObjectAddressSet(address, TSConfigMapRelationId, cfgId); + heap_close(relMap, RowExclusiveLock); ReleaseSysCache(tup); - return cfgId; + return address; } /* diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c index 60ab3aaf12..67e2ae22c6 100644 --- a/src/backend/commands/typecmds.c +++ b/src/backend/commands/typecmds.c @@ -101,14 +101,14 @@ static void checkEnumOwner(HeapTuple tup); 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; @@ -160,6 +160,7 @@ DefineType(List *names, List *parameters) Oid typoid; Oid resulttype; ListCell *pl; + ObjectAddress address; /* * As of Postgres 8.4, we require superuser privilege to create a base @@ -213,7 +214,7 @@ DefineType(List *names, List *parameters) */ if (!OidIsValid(typoid)) { - typoid = TypeShellMake(typeName, typeNamespace, GetUserId()); + address = TypeShellMake(typeName, typeNamespace, GetUserId()); /* Make new shell type visible for modification below */ CommandCounterIncrement(); @@ -222,7 +223,7 @@ DefineType(List *names, List *parameters) * creating the shell type was all we're supposed to do. */ if (parameters == NIL) - return InvalidOid; + return address; } else { @@ -595,7 +596,7 @@ DefineType(List *names, List *parameters) * 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 */ @@ -670,7 +671,7 @@ DefineType(List *names, List *parameters) pfree(array_type); - return typoid; + return address; } /* @@ -716,7 +717,7 @@ RemoveTypeById(Oid typeOid) * DefineDomain * Registers a new domain. */ -Oid +ObjectAddress DefineDomain(CreateDomainStmt *stmt) { char *domainName; @@ -746,12 +747,12 @@ DefineDomain(CreateDomainStmt *stmt) 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, @@ -1021,7 +1022,7 @@ DefineDomain(CreateDomainStmt *stmt) /* * Have TypeCreate do all the real work. */ - domainoid = + address = TypeCreate(InvalidOid, /* no predetermined type OID */ domainName, /* type name */ domainNamespace, /* namespace */ @@ -1066,9 +1067,9 @@ DefineDomain(CreateDomainStmt *stmt) 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 */ @@ -1086,7 +1087,7 @@ DefineDomain(CreateDomainStmt *stmt) */ ReleaseSysCache(typeTup); - return domainoid; + return address; } @@ -1094,16 +1095,16 @@ DefineDomain(CreateDomainStmt *stmt) * 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, @@ -1133,7 +1134,7 @@ DefineEnum(CreateEnumStmt *stmt) enumArrayOid = AssignTypeArrayOid(); /* Create the pg_type entry */ - enumTypeOid = + enumTypeAddr = TypeCreate(InvalidOid, /* no predetermined type OID */ enumName, /* type name */ enumNamespace, /* namespace */ @@ -1167,7 +1168,7 @@ DefineEnum(CreateEnumStmt *stmt) 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. @@ -1192,7 +1193,7 @@ DefineEnum(CreateEnumStmt *stmt) 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 */ @@ -1208,19 +1209,20 @@ DefineEnum(CreateEnumStmt *stmt) 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); @@ -1259,9 +1261,11 @@ AlterEnum(AlterEnumStmt *stmt, bool isTopLevel) InvokeObjectPostAlterHook(TypeRelationId, enum_type_oid, 0); + ObjectAddressSet(address, TypeRelationId, enum_type_oid); + ReleaseSysCache(tup); - return enum_type_oid; + return address; } @@ -1293,7 +1297,7 @@ checkEnumOwner(HeapTuple tup) * DefineRange * Registers a new range type. */ -Oid +ObjectAddress DefineRange(CreateRangeStmt *stmt) { char *typeName; @@ -1316,6 +1320,7 @@ DefineRange(CreateRangeStmt *stmt) char alignment; AclResult aclresult; ListCell *lc; + ObjectAddress address; /* Convert list of names to a name and namespace */ typeNamespace = QualifiedNameGetCreationNamespace(stmt->typeName, @@ -1354,7 +1359,8 @@ DefineRange(CreateRangeStmt *stmt) */ 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(); } @@ -1467,7 +1473,7 @@ DefineRange(CreateRangeStmt *stmt) rangeArrayOid = AssignTypeArrayOid(); /* Create the pg_type entry */ - typoid = + address = TypeCreate(InvalidOid, /* no predetermined type OID */ typeName, /* type name */ typeNamespace, /* namespace */ @@ -1499,6 +1505,7 @@ DefineRange(CreateRangeStmt *stmt) 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, @@ -1546,7 +1553,7 @@ DefineRange(CreateRangeStmt *stmt) /* And create the constructor functions for this range type */ makeRangeConstructors(typeName, typeNamespace, typoid, rangeSubtype); - return typoid; + return address; } /* @@ -1582,45 +1589,40 @@ makeRangeConstructors(const char *name, Oid namespace, 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); } } @@ -2059,17 +2061,16 @@ AssignTypeArrayOid(void) * 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 @@ -2108,17 +2109,19 @@ DefineCompositeType(RangeVar *typevar, List *coldeflist) /* * 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; @@ -2133,6 +2136,7 @@ AlterDomainDefault(List *names, Node *defaultRaw) 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); @@ -2242,19 +2246,23 @@ AlterDomainDefault(List *names, Node *defaultRaw) 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; @@ -2262,6 +2270,7 @@ AlterDomainNotNull(List *names, bool notNull) 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); @@ -2282,7 +2291,7 @@ AlterDomainNotNull(List *names, bool notNull) if (typTup->typnotnull == notNull) { heap_close(typrel, RowExclusiveLock); - return InvalidOid; + return address; } /* Adding a NOT NULL constraint requires checking existing columns */ @@ -2356,11 +2365,13 @@ AlterDomainNotNull(List *names, bool notNull) InvokeObjectPostAlterHook(TypeRelationId, domainoid, 0); + ObjectAddressSet(address, TypeRelationId, domainoid); + /* Clean up */ heap_freetuple(tup); heap_close(typrel, RowExclusiveLock); - return domainoid; + return address; } /* @@ -2368,7 +2379,7 @@ AlterDomainNotNull(List *names, bool notNull) * * Implements the ALTER DOMAIN DROP CONSTRAINT statement */ -Oid +ObjectAddress AlterDomainDropConstraint(List *names, const char *constrName, DropBehavior behavior, bool missing_ok) { @@ -2381,6 +2392,7 @@ AlterDomainDropConstraint(List *names, const char *constrName, 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); @@ -2427,6 +2439,9 @@ AlterDomainDropConstraint(List *names, const char *constrName, found = true; } } + + ObjectAddressSet(address, TypeRelationId, domainoid); + /* Clean up after the scan */ systable_endscan(conscan); heap_close(conrel, RowExclusiveLock); @@ -2446,7 +2461,7 @@ AlterDomainDropConstraint(List *names, const char *constrName, constrName, TypeNameToString(typename)))); } - return domainoid; + return address; } /* @@ -2454,8 +2469,9 @@ AlterDomainDropConstraint(List *names, const char *constrName, * * 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; @@ -2464,6 +2480,7 @@ AlterDomainAddConstraint(List *names, Node *newConstraint) Form_pg_type typTup; Constraint *constr; char *ccbin; + ObjectAddress address; /* Make a TypeName so we can use standard type lookup machinery */ typename = makeTypeNameFromNameList(names); @@ -2539,7 +2556,7 @@ AlterDomainAddConstraint(List *names, Node *newConstraint) 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 @@ -2548,10 +2565,12 @@ AlterDomainAddConstraint(List *names, Node *newConstraint) if (!constr->skip_validation) validateDomainConstraint(domainoid, ccbin); + ObjectAddressSet(address, TypeRelationId, domainoid); + /* Clean up */ heap_close(typrel, RowExclusiveLock); - return domainoid; + return address; } /* @@ -2559,7 +2578,7 @@ AlterDomainAddConstraint(List *names, Node *newConstraint) * * Implements the ALTER DOMAIN .. VALIDATE CONSTRAINT statement. */ -Oid +ObjectAddress AlterDomainValidateConstraint(List *names, char *constrName) { TypeName *typename; @@ -2577,6 +2596,7 @@ AlterDomainValidateConstraint(List *names, char *constrName) HeapTuple tuple; HeapTuple copyTuple; ScanKeyData key; + ObjectAddress address; /* Make a TypeName so we can use standard type lookup machinery */ typename = makeTypeNameFromNameList(names); @@ -2647,6 +2667,8 @@ AlterDomainValidateConstraint(List *names, char *constrName) InvokeObjectPostAlterHook(ConstraintRelationId, HeapTupleGetOid(copyTuple), 0); + ObjectAddressSet(address, TypeRelationId, domainoid); + heap_freetuple(copyTuple); systable_endscan(scan); @@ -2656,7 +2678,7 @@ AlterDomainValidateConstraint(List *names, char *constrName) ReleaseSysCache(tup); - return domainoid; + return address; } static void @@ -2953,13 +2975,14 @@ checkDomainOwner(HeapTuple tup) 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 @@ -3038,34 +3061,37 @@ domainAddConstraint(Oid domainOid, Oid domainNamespace, Oid baseTypeOid, /* * 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 @@ -3078,7 +3104,7 @@ domainAddConstraint(Oid domainOid, Oid domainNamespace, Oid baseTypeOid, /* * Execute ALTER TYPE RENAME */ -Oid +ObjectAddress RenameType(RenameStmt *stmt) { List *names = stmt->object; @@ -3088,6 +3114,7 @@ RenameType(RenameStmt *stmt) Relation rel; HeapTuple tup; Form_pg_type typTup; + ObjectAddress address; /* Make a TypeName so we can use standard type lookup machinery */ typename = makeTypeNameFromNameList(names); @@ -3145,16 +3172,17 @@ RenameType(RenameStmt *stmt) 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; @@ -3164,6 +3192,7 @@ AlterTypeOwner(List *names, Oid newOwnerId, ObjectType objecttype) HeapTuple newtup; Form_pg_type typTup; AclResult aclresult; + ObjectAddress address; rel = heap_open(TypeRelationId, RowExclusiveLock); @@ -3293,10 +3322,12 @@ AlterTypeOwner(List *names, Oid newOwnerId, ObjectType objecttype) } } + ObjectAddressSet(address, TypeRelationId, typeOid); + /* Clean up */ heap_close(rel, RowExclusiveLock); - return typeOid; + return address; } /* @@ -3376,13 +3407,16 @@ AlterTypeOwnerInternal(Oid typeOid, Oid newOwnerId, /* * 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); @@ -3399,10 +3433,15 @@ AlterTypeNamespace(List *names, const char *newschema, ObjectType objecttype) 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 diff --git a/src/backend/commands/user.c b/src/backend/commands/user.c index 2210eedb99..0d30838aee 100644 --- a/src/backend/commands/user.c +++ b/src/backend/commands/user.c @@ -1114,7 +1114,7 @@ DropRole(DropRoleStmt *stmt) /* * Rename role */ -Oid +ObjectAddress RenameRole(const char *oldname, const char *newname) { HeapTuple oldtuple, @@ -1128,6 +1128,7 @@ RenameRole(const char *oldname, const char *newname) bool repl_repl[Natts_pg_authid]; int i; Oid roleid; + ObjectAddress address; rel = heap_open(AuthIdRelationId, RowExclusiveLock); dsc = RelationGetDescr(rel); @@ -1216,6 +1217,8 @@ RenameRole(const char *oldname, const char *newname) InvokeObjectPostAlterHook(AuthIdRelationId, roleid, 0); + ObjectAddressSet(address, AuthIdRelationId, roleid); + ReleaseSysCache(oldtuple); /* @@ -1223,7 +1226,7 @@ RenameRole(const char *oldname, const char *newname) */ heap_close(rel, NoLock); - return roleid; + return address; } /* diff --git a/src/backend/commands/view.c b/src/backend/commands/view.c index 7358723bde..6f2a749756 100644 --- a/src/backend/commands/view.c +++ b/src/backend/commands/view.c @@ -65,7 +65,7 @@ validateWithCheckOption(char *value) * work harder. *--------------------------------------------------------------------- */ -static Oid +static ObjectAddress DefineVirtualRelation(RangeVar *relation, List *tlist, bool replace, List *options) { @@ -143,6 +143,7 @@ DefineVirtualRelation(RangeVar *relation, List *tlist, bool replace, 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); @@ -208,16 +209,18 @@ DefineVirtualRelation(RangeVar *relation, List *tlist, bool replace, /* 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 @@ -237,9 +240,9 @@ DefineVirtualRelation(RangeVar *relation, List *tlist, bool replace, * 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; } } @@ -388,14 +391,14 @@ UpdateRangeTableOfViewParse(Oid viewOid, Query *viewParse) * 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 @@ -533,7 +536,7 @@ DefineView(ViewStmt *stmt, const char *queryString) * 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); /* @@ -543,9 +546,9 @@ DefineView(ViewStmt *stmt, const char *queryString) */ CommandCounterIncrement(); - StoreViewQuery(viewOid, viewParse, stmt->replace); + StoreViewQuery(address.objectId, viewParse, stmt->replace); - return viewOid; + return address; } /* diff --git a/src/backend/rewrite/rewriteDefine.c b/src/backend/rewrite/rewriteDefine.c index eab4d7367c..f540432ccb 100644 --- a/src/backend/rewrite/rewriteDefine.c +++ b/src/backend/rewrite/rewriteDefine.c @@ -191,7 +191,7 @@ InsertRule(char *rulname, * DefineRule * Execute a CREATE RULE command. */ -Oid +ObjectAddress DefineRule(RuleStmt *stmt, const char *queryString) { List *actions; @@ -225,7 +225,7 @@ DefineRule(RuleStmt *stmt, const char *queryString) * 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, @@ -239,6 +239,7 @@ DefineQueryRewrite(char *rulename, Query *query; bool RelisBecomingView = false; Oid ruleId = InvalidOid; + ObjectAddress address; /* * If we are installing an ON SELECT rule, we had better grab @@ -604,10 +605,12 @@ DefineQueryRewrite(char *rulename, heap_close(relationRelation, RowExclusiveLock); } + ObjectAddressSet(address, RewriteRelationId, ruleId); + /* Close rel, but keep lock till commit... */ heap_close(event_relation, NoLock); - return ruleId; + return address; } /* @@ -897,7 +900,7 @@ RangeVarCallbackForRenameRule(const RangeVar *rv, Oid relid, Oid oldrelid, /* * Rename an existing rewrite rule. */ -Oid +ObjectAddress RenameRewriteRule(RangeVar *relation, const char *oldName, const char *newName) { @@ -907,6 +910,7 @@ RenameRewriteRule(RangeVar *relation, const char *oldName, HeapTuple ruletup; Form_pg_rewrite ruleform; Oid ruleOid; + ObjectAddress address; /* * Look up name, check permissions, and acquire lock (which we will NOT @@ -969,10 +973,12 @@ RenameRewriteRule(RangeVar *relation, const char *oldName, */ CacheInvalidateRelcache(targetrel); + ObjectAddressSet(address, RewriteRelationId, ruleOid); + /* * Close rel, but keep exclusive lock! */ relation_close(targetrel, NoLock); - return ruleOid; + return address; } diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index 6d269865e7..daf532693c 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -818,7 +818,7 @@ standard_ProcessUtility(Node *parsetree, context, params, dest, completionTag); else - ExecAlterObjectSchemaStmt(stmt); + ExecAlterObjectSchemaStmt(stmt, NULL); } break; @@ -886,6 +886,7 @@ ProcessUtilitySlow(Node *parsetree, 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(); @@ -911,7 +912,6 @@ ProcessUtilitySlow(Node *parsetree, { List *stmts; ListCell *l; - Oid relOid; /* Run parse analysis ... */ stmts = transformCreateStmt((CreateStmt *) parsetree, @@ -928,9 +928,9 @@ ProcessUtilitySlow(Node *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 @@ -952,16 +952,17 @@ ProcessUtilitySlow(Node *parsetree, 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 { @@ -1067,7 +1068,8 @@ ProcessUtilitySlow(Node *parsetree, break; case 'C': /* ADD CONSTRAINT */ AlterDomainAddConstraint(stmt->typeName, - stmt->def); + stmt->def, + NULL); break; case 'X': /* DROP CONSTRAINT */ AlterDomainDropConstraint(stmt->typeName, @@ -1190,7 +1192,8 @@ ProcessUtilitySlow(Node *parsetree, break; case T_AlterExtensionContentsStmt: - ExecAlterExtensionContentsStmt((AlterExtensionContentsStmt *) parsetree); + ExecAlterExtensionContentsStmt((AlterExtensionContentsStmt *) parsetree, + NULL); break; case T_CreateFdwStmt: @@ -1334,7 +1337,8 @@ ProcessUtilitySlow(Node *parsetree, break; case T_AlterObjectSchemaStmt: - ExecAlterObjectSchemaStmt((AlterObjectSchemaStmt *) parsetree); + ExecAlterObjectSchemaStmt((AlterObjectSchemaStmt *) parsetree, + NULL); break; case T_AlterOwnerStmt: diff --git a/src/include/catalog/heap.h b/src/include/catalog/heap.h index e5c204db65..573b2deb2d 100644 --- a/src/include/catalog/heap.h +++ b/src/include/catalog/heap.h @@ -14,8 +14,9 @@ #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 @@ -68,7 +69,8 @@ extern Oid heap_create_with_catalog(const char *relname, 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); diff --git a/src/include/catalog/objectaddress.h b/src/include/catalog/objectaddress.h index 6f4dbab3a8..619b2f58bc 100644 --- a/src/include/catalog/objectaddress.h +++ b/src/include/catalog/objectaddress.h @@ -28,6 +28,18 @@ typedef struct ObjectAddress 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); diff --git a/src/include/catalog/pg_aggregate.h b/src/include/catalog/pg_aggregate.h index 5e1196dc7a..3e28e2fe02 100644 --- a/src/include/catalog/pg_aggregate.h +++ b/src/include/catalog/pg_aggregate.h @@ -20,6 +20,7 @@ #define PG_AGGREGATE_H #include "catalog/genbki.h" +#include "catalog/objectaddress.h" #include "nodes/pg_list.h" /* ---------------------------------------------------------------- @@ -308,7 +309,7 @@ DATA(insert ( 3992 h 1 ordered_set_transition_multi dense_rank_final - - /* * 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, diff --git a/src/include/catalog/pg_conversion_fn.h b/src/include/catalog/pg_conversion_fn.h index 6185d218b6..7818272e8b 100644 --- a/src/include/catalog/pg_conversion_fn.h +++ b/src/include/catalog/pg_conversion_fn.h @@ -14,7 +14,10 @@ #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); diff --git a/src/include/catalog/pg_operator.h b/src/include/catalog/pg_operator.h index af991d34f7..e22eb27bd5 100644 --- a/src/include/catalog/pg_operator.h +++ b/src/include/catalog/pg_operator.h @@ -23,6 +23,7 @@ #define PG_OPERATOR_H #include "catalog/genbki.h" +#include "catalog/objectaddress.h" #include "nodes/pg_list.h" /* ---------------- @@ -1812,7 +1813,7 @@ DESCR("is contained by"); /* * function prototypes */ -extern Oid OperatorCreate(const char *operatorName, +extern ObjectAddress OperatorCreate(const char *operatorName, Oid operatorNamespace, Oid leftTypeId, Oid rightTypeId, diff --git a/src/include/catalog/pg_proc_fn.h b/src/include/catalog/pg_proc_fn.h index 791d9d62a4..e217188111 100644 --- a/src/include/catalog/pg_proc_fn.h +++ b/src/include/catalog/pg_proc_fn.h @@ -14,9 +14,10 @@ #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, diff --git a/src/include/catalog/pg_type_fn.h b/src/include/catalog/pg_type_fn.h index 28c43a142d..02015fcdd6 100644 --- a/src/include/catalog/pg_type_fn.h +++ b/src/include/catalog/pg_type_fn.h @@ -14,14 +14,15 @@ #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, diff --git a/src/include/commands/alter.h b/src/include/commands/alter.h index 14d24f124d..be68890943 100644 --- a/src/include/commands/alter.h +++ b/src/include/commands/alter.h @@ -15,16 +15,18 @@ #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); diff --git a/src/include/commands/collationcmds.h b/src/include/commands/collationcmds.h index dfc741bec1..fa99ed693a 100644 --- a/src/include/commands/collationcmds.h +++ b/src/include/commands/collationcmds.h @@ -15,9 +15,10 @@ #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 */ diff --git a/src/include/commands/comment.h b/src/include/commands/comment.h index 3d61b44528..990d36216a 100644 --- a/src/include/commands/comment.h +++ b/src/include/commands/comment.h @@ -15,6 +15,7 @@ #ifndef COMMENT_H #define COMMENT_H +#include "catalog/objectaddress.h" #include "nodes/parsenodes.h" /*------------------------------------------------------------------ @@ -29,7 +30,7 @@ *------------------------------------------------------------------ */ -extern Oid CommentObject(CommentStmt *stmt); +extern ObjectAddress CommentObject(CommentStmt *stmt); extern void DeleteComments(Oid oid, Oid classoid, int32 subid); diff --git a/src/include/commands/conversioncmds.h b/src/include/commands/conversioncmds.h index dd8f6dce6b..1f322691a4 100644 --- a/src/include/commands/conversioncmds.h +++ b/src/include/commands/conversioncmds.h @@ -15,8 +15,9 @@ #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 */ diff --git a/src/include/commands/createas.h b/src/include/commands/createas.h index 495298f575..8325d73359 100644 --- a/src/include/commands/createas.h +++ b/src/include/commands/createas.h @@ -14,12 +14,13 @@ #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); diff --git a/src/include/commands/dbcommands.h b/src/include/commands/dbcommands.h index 4b60cdbedc..9fec3344dc 100644 --- a/src/include/commands/dbcommands.h +++ b/src/include/commands/dbcommands.h @@ -15,6 +15,7 @@ #define DBCOMMANDS_H #include "access/xlogreader.h" +#include "catalog/objectaddress.h" #include "lib/stringinfo.h" #include "nodes/parsenodes.h" @@ -40,10 +41,10 @@ typedef struct xl_dbase_drop_rec 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); diff --git a/src/include/commands/defrem.h b/src/include/commands/defrem.h index cf586feac3..9e3e93b605 100644 --- a/src/include/commands/defrem.h +++ b/src/include/commands/defrem.h @@ -14,6 +14,7 @@ #ifndef DEFREM_H #define DEFREM_H +#include "catalog/objectaddress.h" #include "nodes/parsenodes.h" #include "utils/array.h" @@ -21,7 +22,7 @@ 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, @@ -42,12 +43,12 @@ extern bool CheckIndexCompatible(Oid oldId, 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); @@ -66,16 +67,16 @@ extern void interpret_function_parameter_list(List *parameters, 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); @@ -90,36 +91,36 @@ extern Oid get_opclass_oid(Oid amID, List *opclassname, bool missing_ok); 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); diff --git a/src/include/commands/event_trigger.h b/src/include/commands/event_trigger.h index 9ac9fc3735..7eb2156085 100644 --- a/src/include/commands/event_trigger.h +++ b/src/include/commands/event_trigger.h @@ -43,7 +43,7 @@ extern void RemoveEventTriggerById(Oid ctrigOid); 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); diff --git a/src/include/commands/extension.h b/src/include/commands/extension.h index a349d6a711..40ecea2fee 100644 --- a/src/include/commands/extension.h +++ b/src/include/commands/extension.h @@ -14,6 +14,7 @@ #ifndef EXTENSION_H #define EXTENSION_H +#include "catalog/objectaddress.h" #include "nodes/parsenodes.h" @@ -27,23 +28,25 @@ extern bool creating_extension; 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); diff --git a/src/include/commands/matview.h b/src/include/commands/matview.h index 91e2eb532a..37a81aa428 100644 --- a/src/include/commands/matview.h +++ b/src/include/commands/matview.h @@ -14,6 +14,7 @@ #ifndef MATVIEW_H #define MATVIEW_H +#include "catalog/objectaddress.h" #include "nodes/params.h" #include "nodes/parsenodes.h" #include "tcop/dest.h" @@ -22,7 +23,7 @@ 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); diff --git a/src/include/commands/policy.h b/src/include/commands/policy.h index e911fccf83..ac322e0db9 100644 --- a/src/include/commands/policy.h +++ b/src/include/commands/policy.h @@ -15,6 +15,7 @@ #ifndef POLICY_H #define POLICY_H +#include "catalog/objectaddress.h" #include "nodes/parsenodes.h" #include "utils/relcache.h" @@ -22,13 +23,13 @@ extern void RelationBuildRowSecurity(Relation relation); 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 */ diff --git a/src/include/commands/proclang.h b/src/include/commands/proclang.h index f43c321ce2..f056978805 100644 --- a/src/include/commands/proclang.h +++ b/src/include/commands/proclang.h @@ -12,9 +12,10 @@ #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); diff --git a/src/include/commands/schemacmds.h b/src/include/commands/schemacmds.h index d08fdd4f6c..55207a4816 100644 --- a/src/include/commands/schemacmds.h +++ b/src/include/commands/schemacmds.h @@ -15,6 +15,7 @@ #ifndef SCHEMACMDS_H #define SCHEMACMDS_H +#include "catalog/objectaddress.h" #include "nodes/parsenodes.h" extern Oid CreateSchemaCommand(CreateSchemaStmt *parsetree, @@ -22,8 +23,8 @@ 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 */ diff --git a/src/include/commands/seclabel.h b/src/include/commands/seclabel.h index 7e3dde4d3a..661da2b21b 100644 --- a/src/include/commands/seclabel.h +++ b/src/include/commands/seclabel.h @@ -24,7 +24,7 @@ extern void DeleteSharedSecurityLabel(Oid objectId, Oid classId); /* * 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); diff --git a/src/include/commands/sequence.h b/src/include/commands/sequence.h index 1baf43d3d3..44862bba81 100644 --- a/src/include/commands/sequence.h +++ b/src/include/commands/sequence.h @@ -14,6 +14,7 @@ #define SEQUENCE_H #include "access/xlogreader.h" +#include "catalog/objectaddress.h" #include "fmgr.h" #include "lib/stringinfo.h" #include "nodes/parsenodes.h" @@ -72,8 +73,8 @@ extern Datum lastval(PG_FUNCTION_ARGS); 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); diff --git a/src/include/commands/tablecmds.h b/src/include/commands/tablecmds.h index a55e8d42ee..f269c63558 100644 --- a/src/include/commands/tablecmds.h +++ b/src/include/commands/tablecmds.h @@ -16,12 +16,14 @@ #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); @@ -37,7 +39,8 @@ extern void AlterTableInternal(Oid relid, List *cmds, bool recurse); 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); @@ -53,11 +56,13 @@ extern void ExecuteTruncate(TruncateStmt *stmt); 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); diff --git a/src/include/commands/tablespace.h b/src/include/commands/tablespace.h index 70734d6030..86b0477335 100644 --- a/src/include/commands/tablespace.h +++ b/src/include/commands/tablespace.h @@ -15,6 +15,7 @@ #define TABLESPACE_H #include "access/xlogreader.h" +#include "catalog/objectaddress.h" #include "lib/stringinfo.h" #include "nodes/parsenodes.h" @@ -42,7 +43,7 @@ typedef struct TableSpaceOpts 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); diff --git a/src/include/commands/trigger.h b/src/include/commands/trigger.h index d0c0dccb1f..1a53f6cde5 100644 --- a/src/include/commands/trigger.h +++ b/src/include/commands/trigger.h @@ -13,6 +13,7 @@ #ifndef TRIGGER_H #define TRIGGER_H +#include "catalog/objectaddress.h" #include "nodes/execnodes.h" #include "nodes/parsenodes.h" @@ -108,14 +109,14 @@ extern PGDLLIMPORT int SessionReplicationRole; #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); diff --git a/src/include/commands/typecmds.h b/src/include/commands/typecmds.h index 0a638002c3..ef4b41b5a5 100644 --- a/src/include/commands/typecmds.h +++ b/src/include/commands/typecmds.h @@ -21,29 +21,31 @@ #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, diff --git a/src/include/commands/user.h b/src/include/commands/user.h index d76685182f..ccadb04b8c 100644 --- a/src/include/commands/user.h +++ b/src/include/commands/user.h @@ -11,6 +11,7 @@ #ifndef USER_H #define USER_H +#include "catalog/objectaddress.h" #include "nodes/parsenodes.h" @@ -27,7 +28,7 @@ extern Oid AlterRole(AlterRoleStmt *stmt); 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); diff --git a/src/include/commands/view.h b/src/include/commands/view.h index 595d2663f1..53db76e6c6 100644 --- a/src/include/commands/view.h +++ b/src/include/commands/view.h @@ -14,11 +14,12 @@ #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); diff --git a/src/include/rewrite/rewriteDefine.h b/src/include/rewrite/rewriteDefine.h index d384552ca2..5f0dc31bd3 100644 --- a/src/include/rewrite/rewriteDefine.h +++ b/src/include/rewrite/rewriteDefine.h @@ -14,6 +14,7 @@ #ifndef REWRITEDEFINE_H #define REWRITEDEFINE_H +#include "catalog/objectaddress.h" #include "nodes/parsenodes.h" #include "utils/relcache.h" @@ -22,9 +23,9 @@ #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, @@ -32,7 +33,7 @@ extern Oid DefineQueryRewrite(char *rulename, 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);