Change many routines to return ObjectAddress rather than OID

The changed routines are mostly those that can be directly called by
ProcessUtilitySlow; the intention is to make the affected object
information more precise, in support for future event trigger changes.
Originally it was envisioned that the OID of the affected object would
be enough, and in most cases that is correct, but upon actually
implementing the event trigger changes it turned out that ObjectAddress
is more widely useful.

Additionally, some command execution routines grew an output argument
that's an object address which provides further info about the executed
command.  To wit:

* for ALTER DOMAIN / ADD CONSTRAINT, it corresponds to the address of
  the new constraint

* for ALTER OBJECT / SET SCHEMA, it corresponds to the address of the
  schema that originally contained the object.

* for ALTER EXTENSION {ADD, DROP} OBJECT, it corresponds to the address
  of the object added to or dropped from the extension.

There's no user-visible change in this commit, and no functional change
either.

Discussion: 20150218213255.GC6717@tamriel.snowman.net
Reviewed-By: Stephen Frost, Andres Freund
This commit is contained in:
Alvaro Herrera 2015-03-03 14:10:50 -03:00
parent 6f9d799047
commit a2e35b53c3
68 changed files with 840 additions and 558 deletions

View File

@ -251,7 +251,8 @@ Boot_CreateStmt:
(Datum) 0, (Datum) 0,
false, false,
true, true,
false); false,
NULL);
elog(DEBUG4, "relation created with OID %u", id); elog(DEBUG4, "relation created with OID %u", id);
} }
do_end(); do_end();

View File

@ -89,7 +89,7 @@ static void AddNewRelationTuple(Relation pg_class_desc,
char relkind, char relkind,
Datum relacl, Datum relacl,
Datum reloptions); Datum reloptions);
static Oid AddNewRelationType(const char *typeName, static ObjectAddress AddNewRelationType(const char *typeName,
Oid typeNamespace, Oid typeNamespace,
Oid new_rel_oid, Oid new_rel_oid,
char new_rel_kind, char new_rel_kind,
@ -935,7 +935,7 @@ AddNewRelationTuple(Relation pg_class_desc,
* define a composite type corresponding to the new relation * define a composite type corresponding to the new relation
* -------------------------------- * --------------------------------
*/ */
static Oid static ObjectAddress
AddNewRelationType(const char *typeName, AddNewRelationType(const char *typeName,
Oid typeNamespace, Oid typeNamespace,
Oid new_rel_oid, Oid new_rel_oid,
@ -1006,6 +1006,9 @@ AddNewRelationType(const char *typeName,
* allow_system_table_mods: TRUE to allow creation in system namespaces * allow_system_table_mods: TRUE to allow creation in system namespaces
* is_internal: is this a system-generated catalog? * 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 * Returns the OID of the new relation
* -------------------------------- * --------------------------------
*/ */
@ -1029,7 +1032,8 @@ heap_create_with_catalog(const char *relname,
Datum reloptions, Datum reloptions,
bool use_user_acl, bool use_user_acl,
bool allow_system_table_mods, bool allow_system_table_mods,
bool is_internal) bool is_internal,
ObjectAddress *typaddress)
{ {
Relation pg_class_desc; Relation pg_class_desc;
Relation new_rel_desc; Relation new_rel_desc;
@ -1037,6 +1041,7 @@ heap_create_with_catalog(const char *relname,
Oid existing_relid; Oid existing_relid;
Oid old_type_oid; Oid old_type_oid;
Oid new_type_oid; Oid new_type_oid;
ObjectAddress new_type_addr;
Oid new_array_oid = InvalidOid; Oid new_array_oid = InvalidOid;
pg_class_desc = heap_open(RelationRelationId, RowExclusiveLock); 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 * creating the same type name in parallel but hadn't committed yet when
* we checked for a duplicate name above. * we checked for a duplicate name above.
*/ */
new_type_oid = AddNewRelationType(relname, new_type_addr = AddNewRelationType(relname,
relnamespace, relnamespace,
relid, relid,
relkind, relkind,
ownerid, ownerid,
reltypeid, reltypeid,
new_array_oid); new_array_oid);
new_type_oid = new_type_addr.objectId;
if (typaddress)
*typaddress = new_type_addr;
/* /*
* Now make the array type if wanted. * Now make the array type if wanted.

View File

@ -531,6 +531,12 @@ ObjectTypeMap[] =
{ "policy", OBJECT_POLICY } { "policy", OBJECT_POLICY }
}; };
const ObjectAddress InvalidObjectAddress =
{
InvalidOid,
InvalidOid,
0
};
static ObjectAddress get_object_address_unqualified(ObjectType objtype, static ObjectAddress get_object_address_unqualified(ObjectType objtype,
List *qualname, bool missing_ok); List *qualname, bool missing_ok);

View File

@ -43,7 +43,7 @@ static Oid lookup_agg_function(List *fnName, int nargs, Oid *input_types,
/* /*
* AggregateCreate * AggregateCreate
*/ */
Oid ObjectAddress
AggregateCreate(const char *aggName, AggregateCreate(const char *aggName,
Oid aggNamespace, Oid aggNamespace,
char aggKind, char aggKind,
@ -522,32 +522,33 @@ AggregateCreate(const char *aggName,
* aggregate. (This could fail if there's already a conflicting entry.) * aggregate. (This could fail if there's already a conflicting entry.)
*/ */
procOid = ProcedureCreate(aggName, myself = ProcedureCreate(aggName,
aggNamespace, aggNamespace,
false, /* no replacement */ false, /* no replacement */
false, /* doesn't return a set */ false, /* doesn't return a set */
finaltype, /* returnType */ finaltype, /* returnType */
GetUserId(), /* proowner */ GetUserId(), /* proowner */
INTERNALlanguageId, /* languageObjectId */ INTERNALlanguageId, /* languageObjectId */
InvalidOid, /* no validator */ InvalidOid, /* no validator */
"aggregate_dummy", /* placeholder proc */ "aggregate_dummy", /* placeholder proc */
NULL, /* probin */ NULL, /* probin */
true, /* isAgg */ true, /* isAgg */
false, /* isWindowFunc */ false, /* isWindowFunc */
false, /* security invoker (currently not false, /* security invoker (currently not
* definable for agg) */ * definable for agg) */
false, /* isLeakProof */ false, /* isLeakProof */
false, /* isStrict (not needed for agg) */ false, /* isStrict (not needed for agg) */
PROVOLATILE_IMMUTABLE, /* volatility (not PROVOLATILE_IMMUTABLE, /* volatility (not
* needed for agg) */ * needed for agg) */
parameterTypes, /* paramTypes */ parameterTypes, /* paramTypes */
allParameterTypes, /* allParamTypes */ allParameterTypes, /* allParamTypes */
parameterModes, /* parameterModes */ parameterModes, /* parameterModes */
parameterNames, /* parameterNames */ parameterNames, /* parameterNames */
parameterDefaults, /* parameterDefaults */ parameterDefaults, /* parameterDefaults */
PointerGetDatum(NULL), /* proconfig */ PointerGetDatum(NULL), /* proconfig */
1, /* procost */ 1, /* procost */
0); /* prorows */ 0); /* prorows */
procOid = myself.objectId;
/* /*
* Okay to create the pg_aggregate entry. * 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. * on aggTransType since we depend on it indirectly through transfn.
* Likewise for aggmTransType if any. * Likewise for aggmTransType if any.
*/ */
myself.classId = ProcedureRelationId;
myself.objectId = procOid;
myself.objectSubId = 0;
/* Depends on transition function */ /* Depends on transition function */
referenced.classId = ProcedureRelationId; referenced.classId = ProcedureRelationId;
@ -654,7 +652,7 @@ AggregateCreate(const char *aggName,
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL); recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
} }
return procOid; return myself;
} }
/* /*

View File

@ -37,7 +37,7 @@
* *
* Add a new tuple to pg_conversion. * Add a new tuple to pg_conversion.
*/ */
Oid ObjectAddress
ConversionCreate(const char *conname, Oid connamespace, ConversionCreate(const char *conname, Oid connamespace,
Oid conowner, Oid conowner,
int32 conforencoding, int32 contoencoding, int32 conforencoding, int32 contoencoding,
@ -141,7 +141,7 @@ ConversionCreate(const char *conname, Oid connamespace,
heap_freetuple(tup); heap_freetuple(tup);
heap_close(rel, RowExclusiveLock); heap_close(rel, RowExclusiveLock);
return oid; return myself;
} }
/* /*

View File

@ -61,7 +61,7 @@ static Oid get_other_operator(List *otherOp,
Oid leftTypeId, Oid rightTypeId, Oid leftTypeId, Oid rightTypeId,
bool isCommutator); 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 * Forward declaration is used only for this purpose, it is
* not available to the user as it is for type definition. * not available to the user as it is for type definition.
*/ */
Oid ObjectAddress
OperatorCreate(const char *operatorName, OperatorCreate(const char *operatorName,
Oid operatorNamespace, Oid operatorNamespace,
Oid leftTypeId, Oid leftTypeId,
@ -352,6 +352,7 @@ OperatorCreate(const char *operatorName,
NameData oname; NameData oname;
TupleDesc tupDesc; TupleDesc tupDesc;
int i; int i;
ObjectAddress address;
/* /*
* Sanity checks * Sanity checks
@ -540,7 +541,7 @@ OperatorCreate(const char *operatorName,
CatalogUpdateIndexes(pg_operator_desc, tup); CatalogUpdateIndexes(pg_operator_desc, tup);
/* Add dependencies for the entry */ /* Add dependencies for the entry */
makeOperatorDependencies(tup); address = makeOperatorDependencies(tup);
/* Post creation hook for new operator */ /* Post creation hook for new operator */
InvokeObjectPostCreateHook(OperatorRelationId, operatorObjectId, 0); InvokeObjectPostCreateHook(OperatorRelationId, operatorObjectId, 0);
@ -564,7 +565,7 @@ OperatorCreate(const char *operatorName,
if (OidIsValid(commutatorId) || OidIsValid(negatorId)) if (OidIsValid(commutatorId) || OidIsValid(negatorId))
OperatorUpd(operatorObjectId, commutatorId, 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 * NB: the OidIsValid tests in this routine are necessary, in case
* the given operator is a shell. * the given operator is a shell.
*/ */
static void static ObjectAddress
makeOperatorDependencies(HeapTuple tuple) makeOperatorDependencies(HeapTuple tuple)
{ {
Form_pg_operator oper = (Form_pg_operator) GETSTRUCT(tuple); Form_pg_operator oper = (Form_pg_operator) GETSTRUCT(tuple);
@ -860,4 +861,6 @@ makeOperatorDependencies(HeapTuple tuple)
/* Dependency on extension */ /* Dependency on extension */
recordDependencyOnCurrentExtension(&myself, true); recordDependencyOnCurrentExtension(&myself, true);
return myself;
} }

View File

@ -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. * not "ArrayType *", to avoid importing array.h into pg_proc_fn.h.
* ---------------------------------------------------------------- * ----------------------------------------------------------------
*/ */
Oid ObjectAddress
ProcedureCreate(const char *procedureName, ProcedureCreate(const char *procedureName,
Oid procNamespace, Oid procNamespace,
bool replace, bool replace,
@ -703,7 +703,7 @@ ProcedureCreate(const char *procedureName,
AtEOXact_GUC(true, save_nestlevel); AtEOXact_GUC(true, save_nestlevel);
} }
return retval; return myself;
} }

View File

@ -52,7 +52,7 @@ Oid binary_upgrade_next_pg_type_oid = InvalidOid;
* with correct ones, and "typisdefined" will be set to true. * with correct ones, and "typisdefined" will be set to true.
* ---------------------------------------------------------------- * ----------------------------------------------------------------
*/ */
Oid ObjectAddress
TypeShellMake(const char *typeName, Oid typeNamespace, Oid ownerId) TypeShellMake(const char *typeName, Oid typeNamespace, Oid ownerId)
{ {
Relation pg_type_desc; Relation pg_type_desc;
@ -63,6 +63,7 @@ TypeShellMake(const char *typeName, Oid typeNamespace, Oid ownerId)
bool nulls[Natts_pg_type]; bool nulls[Natts_pg_type];
Oid typoid; Oid typoid;
NameData name; NameData name;
ObjectAddress address;
Assert(PointerIsValid(typeName)); Assert(PointerIsValid(typeName));
@ -171,13 +172,15 @@ TypeShellMake(const char *typeName, Oid typeNamespace, Oid ownerId)
/* Post creation hook for new shell type */ /* Post creation hook for new shell type */
InvokeObjectPostCreateHook(TypeRelationId, typoid, 0); InvokeObjectPostCreateHook(TypeRelationId, typoid, 0);
ObjectAddressSet(address, TypeRelationId, typoid);
/* /*
* clean up and return the type-oid * clean up and return the type-oid
*/ */
heap_freetuple(tup); heap_freetuple(tup);
heap_close(pg_type_desc, RowExclusiveLock); 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. * This does all the necessary work needed to define a new type.
* *
* Returns the OID assigned to the new type. If newTypeOid is * Returns the ObjectAddress assigned to the new type.
* zero (the normal case), a new OID is created; otherwise we * If newTypeOid is zero (the normal case), a new OID is created;
* use exactly that OID. * otherwise we use exactly that OID.
* ---------------------------------------------------------------- * ----------------------------------------------------------------
*/ */
Oid ObjectAddress
TypeCreate(Oid newTypeOid, TypeCreate(Oid newTypeOid,
const char *typeName, const char *typeName,
Oid typeNamespace, Oid typeNamespace,
@ -233,6 +236,7 @@ TypeCreate(Oid newTypeOid,
NameData name; NameData name;
int i; int i;
Acl *typacl = NULL; Acl *typacl = NULL;
ObjectAddress address;
/* /*
* We assume that the caller validated the arguments individually, but did * We assume that the caller validated the arguments individually, but did
@ -488,12 +492,14 @@ TypeCreate(Oid newTypeOid,
/* Post creation hook for new type */ /* Post creation hook for new type */
InvokeObjectPostCreateHook(TypeRelationId, typeObjectId, 0); InvokeObjectPostCreateHook(TypeRelationId, typeObjectId, 0);
ObjectAddressSet(address, TypeRelationId, typeObjectId);
/* /*
* finish up * finish up
*/ */
heap_close(pg_type_desc, RowExclusiveLock); heap_close(pg_type_desc, RowExclusiveLock);
return typeObjectId; return address;
} }
/* /*

View File

@ -289,7 +289,8 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
reloptions, reloptions,
false, false,
true, true,
true); true,
NULL);
Assert(toast_relid != InvalidOid); Assert(toast_relid != InvalidOid);
/* make the toast relation visible, else heap_open will fail */ /* make the toast relation visible, else heap_open will fail */

View File

@ -51,7 +51,7 @@
* isn't an ordered-set aggregate. * isn't an ordered-set aggregate.
* "parameters" is a list of DefElem representing the agg's definition clauses. * "parameters" is a list of DefElem representing the agg's definition clauses.
*/ */
Oid ObjectAddress
DefineAggregate(List *name, List *args, bool oldstyle, List *parameters, DefineAggregate(List *name, List *args, bool oldstyle, List *parameters,
const char *queryString) const char *queryString)
{ {

View File

@ -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 * Executes an ALTER OBJECT / RENAME TO statement. Based on the object
* type, the function appropriate to that type is executed. * type, the function appropriate to that type is executed.
*
* Return value is the address of the renamed object.
*/ */
Oid ObjectAddress
ExecRenameStmt(RenameStmt *stmt) ExecRenameStmt(RenameStmt *stmt)
{ {
switch (stmt->renameType) switch (stmt->renameType)
@ -378,39 +380,54 @@ ExecRenameStmt(RenameStmt *stmt)
stmt->newname); stmt->newname);
heap_close(catalog, RowExclusiveLock); heap_close(catalog, RowExclusiveLock);
return address.objectId; return address;
} }
default: default:
elog(ERROR, "unrecognized rename stmt type: %d", elog(ERROR, "unrecognized rename stmt type: %d",
(int) stmt->renameType); (int) stmt->renameType);
return InvalidOid; /* keep compiler happy */ return InvalidObjectAddress; /* keep compiler happy */
} }
} }
/* /*
* Executes an ALTER OBJECT / SET SCHEMA statement. Based on the object * Executes an ALTER OBJECT / SET SCHEMA statement. Based on the object
* type, the function appropriate to that type is executed. * 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 ObjectAddress
ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt) ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt,
ObjectAddress *oldSchemaAddr)
{ {
ObjectAddress address;
Oid oldNspOid;
switch (stmt->objectType) switch (stmt->objectType)
{ {
case OBJECT_EXTENSION: 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_FOREIGN_TABLE:
case OBJECT_SEQUENCE: case OBJECT_SEQUENCE:
case OBJECT_TABLE: case OBJECT_TABLE:
case OBJECT_VIEW: case OBJECT_VIEW:
case OBJECT_MATVIEW: case OBJECT_MATVIEW:
return AlterTableNamespace(stmt); address = AlterTableNamespace(stmt,
oldSchemaAddr ? &oldNspOid : NULL);
break;
case OBJECT_DOMAIN: case OBJECT_DOMAIN:
case OBJECT_TYPE: case OBJECT_TYPE:
return AlterTypeNamespace(stmt->object, stmt->newschema, address = AlterTypeNamespace(stmt->object, stmt->newschema,
stmt->objectType); stmt->objectType,
oldSchemaAddr ? &oldNspOid : NULL);
break;
/* generic code path */ /* generic code path */
case OBJECT_AGGREGATE: case OBJECT_AGGREGATE:
@ -442,19 +459,22 @@ ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt)
catalog = heap_open(classId, RowExclusiveLock); catalog = heap_open(classId, RowExclusiveLock);
nspOid = LookupCreationNamespace(stmt->newschema); nspOid = LookupCreationNamespace(stmt->newschema);
AlterObjectNamespace_internal(catalog, address.objectId, oldNspOid = AlterObjectNamespace_internal(catalog, address.objectId,
nspOid); nspOid);
heap_close(catalog, RowExclusiveLock); heap_close(catalog, RowExclusiveLock);
return address.objectId;
} }
break; break;
default: default:
elog(ERROR, "unrecognized AlterObjectSchemaStmt type: %d", elog(ERROR, "unrecognized AlterObjectSchemaStmt type: %d",
(int) stmt->objectType); (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 * Executes an ALTER OBJECT / OWNER TO statement. Based on the object
* type, the function appropriate to that type is executed. * type, the function appropriate to that type is executed.
*/ */
Oid ObjectAddress
ExecAlterOwnerStmt(AlterOwnerStmt *stmt) ExecAlterOwnerStmt(AlterOwnerStmt *stmt)
{ {
Oid newowner = get_role_oid(stmt->newowner, false); Oid newowner = get_role_oid(stmt->newowner, false);
@ -747,15 +767,14 @@ ExecAlterOwnerStmt(AlterOwnerStmt *stmt)
AlterObjectOwner_internal(catalog, address.objectId, newowner); AlterObjectOwner_internal(catalog, address.objectId, newowner);
heap_close(catalog, RowExclusiveLock); heap_close(catalog, RowExclusiveLock);
return address.objectId; return address;
} }
break; break;
default: default:
elog(ERROR, "unrecognized AlterOwnerStmt type: %d", elog(ERROR, "unrecognized AlterOwnerStmt type: %d",
(int) stmt->objectType); (int) stmt->objectType);
return InvalidObjectAddress; /* keep compiler happy */
return InvalidOid; /* keep compiler happy */
} }
} }

View File

@ -677,7 +677,8 @@ make_new_heap(Oid OIDOldHeap, Oid NewTableSpace, char relpersistence,
reloptions, reloptions,
false, false,
true, true,
true); true,
NULL);
Assert(OIDNewHeap != InvalidOid); Assert(OIDNewHeap != InvalidOid);
ReleaseSysCache(tuple); ReleaseSysCache(tuple);

View File

@ -37,7 +37,7 @@
/* /*
* CREATE COLLATION * CREATE COLLATION
*/ */
Oid ObjectAddress
DefineCollation(List *names, List *parameters) DefineCollation(List *names, List *parameters)
{ {
char *collName; char *collName;
@ -51,6 +51,7 @@ DefineCollation(List *names, List *parameters)
char *collcollate = NULL; char *collcollate = NULL;
char *collctype = NULL; char *collctype = NULL;
Oid newoid; Oid newoid;
ObjectAddress address;
collNamespace = QualifiedNameGetCreationNamespace(names, &collName); collNamespace = QualifiedNameGetCreationNamespace(names, &collName);
@ -137,11 +138,13 @@ DefineCollation(List *names, List *parameters)
collcollate, collcollate,
collctype); collctype);
ObjectAddressSet(address, CollationRelationId, newoid);
/* check that the locales can be loaded */ /* check that the locales can be loaded */
CommandCounterIncrement(); CommandCounterIncrement();
(void) pg_newlocale_from_collation(newoid); (void) pg_newlocale_from_collation(newoid);
return newoid; return address;
} }
/* /*

View File

@ -36,11 +36,11 @@
* This routine is used to add the associated comment into * This routine is used to add the associated comment into
* pg_description for the object specified by the given SQL command. * pg_description for the object specified by the given SQL command.
*/ */
Oid ObjectAddress
CommentObject(CommentStmt *stmt) CommentObject(CommentStmt *stmt)
{ {
ObjectAddress address;
Relation relation; Relation relation;
ObjectAddress address = InvalidObjectAddress;
/* /*
* When loading a dump, we may see a COMMENT ON DATABASE for the old name * When loading a dump, we may see a COMMENT ON DATABASE for the old name
@ -60,7 +60,7 @@ CommentObject(CommentStmt *stmt)
ereport(WARNING, ereport(WARNING,
(errcode(ERRCODE_UNDEFINED_DATABASE), (errcode(ERRCODE_UNDEFINED_DATABASE),
errmsg("database \"%s\" does not exist", database))); errmsg("database \"%s\" does not exist", database)));
return InvalidOid; return address;
} }
} }
@ -126,7 +126,7 @@ CommentObject(CommentStmt *stmt)
if (relation != NULL) if (relation != NULL)
relation_close(relation, NoLock); relation_close(relation, NoLock);
return address.objectId; return address;
} }
/* /*

View File

@ -34,7 +34,7 @@
/* /*
* CREATE CONVERSION * CREATE CONVERSION
*/ */
Oid ObjectAddress
CreateConversionCommand(CreateConversionStmt *stmt) CreateConversionCommand(CreateConversionStmt *stmt)
{ {
Oid namespaceId; Oid namespaceId;

View File

@ -58,8 +58,8 @@ typedef struct
BulkInsertState bistate; /* bulk insert state */ BulkInsertState bistate; /* bulk insert state */
} DR_intorel; } DR_intorel;
/* the OID of the created table, for ExecCreateTableAs consumption */ /* the address of the created table, for ExecCreateTableAs consumption */
static Oid CreateAsRelid = InvalidOid; static ObjectAddress CreateAsReladdr = {InvalidOid, InvalidOid, 0};
static void intorel_startup(DestReceiver *self, int operation, TupleDesc typeinfo); static void intorel_startup(DestReceiver *self, int operation, TupleDesc typeinfo);
static void intorel_receive(TupleTableSlot *slot, DestReceiver *self); 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 * ExecCreateTableAs -- execute a CREATE TABLE AS command
*/ */
Oid ObjectAddress
ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString, ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString,
ParamListInfo params, char *completionTag) ParamListInfo params, char *completionTag)
{ {
@ -81,7 +81,7 @@ ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString,
Oid save_userid = InvalidOid; Oid save_userid = InvalidOid;
int save_sec_context = 0; int save_sec_context = 0;
int save_nestlevel = 0; int save_nestlevel = 0;
Oid relOid; ObjectAddress address;
List *rewritten; List *rewritten;
PlannedStmt *plan; PlannedStmt *plan;
QueryDesc *queryDesc; QueryDesc *queryDesc;
@ -99,7 +99,7 @@ ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString,
(errcode(ERRCODE_DUPLICATE_TABLE), (errcode(ERRCODE_DUPLICATE_TABLE),
errmsg("relation \"%s\" already exists, skipping", errmsg("relation \"%s\" already exists, skipping",
stmt->into->rel->relname))); stmt->into->rel->relname)));
return InvalidOid; return InvalidObjectAddress;
} }
} }
@ -121,9 +121,9 @@ ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString,
Assert(!is_matview); /* excluded by syntax */ Assert(!is_matview); /* excluded by syntax */
ExecuteQuery(estmt, into, queryString, params, dest, completionTag); ExecuteQuery(estmt, into, queryString, params, dest, completionTag);
relOid = CreateAsRelid; address = CreateAsReladdr;
CreateAsRelid = InvalidOid; CreateAsReladdr = InvalidObjectAddress;
return relOid; return address;
} }
Assert(query->commandType == CMD_SELECT); Assert(query->commandType == CMD_SELECT);
@ -216,10 +216,10 @@ ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString,
SetUserIdAndSecContext(save_userid, save_sec_context); SetUserIdAndSecContext(save_userid, save_sec_context);
} }
relOid = CreateAsRelid; address = CreateAsReladdr;
CreateAsRelid = InvalidOid; CreateAsReladdr = InvalidObjectAddress;
return relOid; return address;
} }
/* /*
@ -288,7 +288,7 @@ intorel_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
bool is_matview; bool is_matview;
char relkind; char relkind;
CreateStmt *create; CreateStmt *create;
Oid intoRelationId; ObjectAddress intoRelationAddr;
Relation intoRelationDesc; Relation intoRelationDesc;
RangeTblEntry *rte; RangeTblEntry *rte;
Datum toast_options; Datum toast_options;
@ -385,7 +385,7 @@ intorel_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
/* /*
* Actually create the target table * 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 * 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); (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. */ /* Create the "view" part of a materialized view. */
if (is_matview) if (is_matview)
@ -411,14 +411,14 @@ intorel_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
/* StoreViewQuery scribbles on tree, so make a copy */ /* StoreViewQuery scribbles on tree, so make a copy */
Query *query = (Query *) copyObject(into->viewQuery); Query *query = (Query *) copyObject(into->viewQuery);
StoreViewQuery(intoRelationId, query, false); StoreViewQuery(intoRelationAddr.objectId, query, false);
CommandCounterIncrement(); CommandCounterIncrement();
} }
/* /*
* Finally we can open the target table * 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. * Check INSERT permission on the constructed table.
@ -428,7 +428,7 @@ intorel_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
*/ */
rte = makeNode(RangeTblEntry); rte = makeNode(RangeTblEntry);
rte->rtekind = RTE_RELATION; rte->rtekind = RTE_RELATION;
rte->relid = intoRelationId; rte->relid = intoRelationAddr.objectId;
rte->relkind = relkind; rte->relkind = relkind;
rte->requiredPerms = ACL_INSERT; 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 * be enabled here. We don't actually support that currently, so throw
* our own ereport(ERROR) if that happens. * 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, ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
(errmsg("policies not yet implemented for this command")))); (errmsg("policies not yet implemented for this command"))));
@ -464,8 +464,8 @@ intorel_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
myState->rel = intoRelationDesc; myState->rel = intoRelationDesc;
myState->output_cid = GetCurrentCommandId(true); myState->output_cid = GetCurrentCommandId(true);
/* and remember the new relation's OID for ExecCreateTableAs */ /* and remember the new relation's address for ExecCreateTableAs */
CreateAsRelid = RelationGetRelid(myState->rel); CreateAsReladdr = intoRelationAddr;
/* /*
* We can skip WAL-logging the insertions, unless PITR or streaming * We can skip WAL-logging the insertions, unless PITR or streaming

View File

@ -938,7 +938,7 @@ dropdb(const char *dbname, bool missing_ok)
/* /*
* Rename database * Rename database
*/ */
Oid ObjectAddress
RenameDatabase(const char *oldname, const char *newname) RenameDatabase(const char *oldname, const char *newname)
{ {
Oid db_id; Oid db_id;
@ -946,6 +946,7 @@ RenameDatabase(const char *oldname, const char *newname)
Relation rel; Relation rel;
int notherbackends; int notherbackends;
int npreparedxacts; int npreparedxacts;
ObjectAddress address;
/* /*
* Look up the target database's OID, and get exclusive lock on it. We * 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); InvokeObjectPostAlterHook(DatabaseRelationId, db_id, 0);
ObjectAddressSet(address, DatabaseRelationId, db_id);
/* /*
* Close pg_database, but keep lock till commit. * Close pg_database, but keep lock till commit.
*/ */
heap_close(rel, NoLock); heap_close(rel, NoLock);
return db_id; return address;
} }
@ -1560,7 +1563,7 @@ AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
/* /*
* ALTER DATABASE name OWNER TO newowner * ALTER DATABASE name OWNER TO newowner
*/ */
Oid ObjectAddress
AlterDatabaseOwner(const char *dbname, Oid newOwnerId) AlterDatabaseOwner(const char *dbname, Oid newOwnerId)
{ {
Oid db_id; Oid db_id;
@ -1569,6 +1572,7 @@ AlterDatabaseOwner(const char *dbname, Oid newOwnerId)
ScanKeyData scankey; ScanKeyData scankey;
SysScanDesc scan; SysScanDesc scan;
Form_pg_database datForm; Form_pg_database datForm;
ObjectAddress address;
/* /*
* Get the old tuple. We don't need a lock on the database per se, * 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); InvokeObjectPostAlterHook(DatabaseRelationId, HeapTupleGetOid(tuple), 0);
ObjectAddressSet(address, DatabaseRelationId, db_id);
systable_endscan(scan); systable_endscan(scan);
/* Close pg_database, but keep lock till commit */ /* Close pg_database, but keep lock till commit */
heap_close(rel, NoLock); heap_close(rel, NoLock);
return db_id; return address;
} }

View File

@ -518,12 +518,13 @@ AlterEventTrigger(AlterEventTrigStmt *stmt)
/* /*
* Change event trigger's owner -- by name * Change event trigger's owner -- by name
*/ */
Oid ObjectAddress
AlterEventTriggerOwner(const char *name, Oid newOwnerId) AlterEventTriggerOwner(const char *name, Oid newOwnerId)
{ {
Oid evtOid; Oid evtOid;
HeapTuple tup; HeapTuple tup;
Relation rel; Relation rel;
ObjectAddress address;
rel = heap_open(EventTriggerRelationId, RowExclusiveLock); rel = heap_open(EventTriggerRelationId, RowExclusiveLock);
@ -538,11 +539,13 @@ AlterEventTriggerOwner(const char *name, Oid newOwnerId)
AlterEventTriggerOwner_internal(rel, tup, newOwnerId); AlterEventTriggerOwner_internal(rel, tup, newOwnerId);
ObjectAddressSet(address, EventTriggerRelationId, evtOid);
heap_freetuple(tup); heap_freetuple(tup);
heap_close(rel, RowExclusiveLock); heap_close(rel, RowExclusiveLock);
return evtOid; return address;
} }
/* /*

View File

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

View File

@ -292,12 +292,13 @@ AlterForeignDataWrapperOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerI
* *
* Note restrictions in the "_internal" function, above. * Note restrictions in the "_internal" function, above.
*/ */
Oid ObjectAddress
AlterForeignDataWrapperOwner(const char *name, Oid newOwnerId) AlterForeignDataWrapperOwner(const char *name, Oid newOwnerId)
{ {
Oid fdwId; Oid fdwId;
HeapTuple tup; HeapTuple tup;
Relation rel; Relation rel;
ObjectAddress address;
rel = heap_open(ForeignDataWrapperRelationId, RowExclusiveLock); rel = heap_open(ForeignDataWrapperRelationId, RowExclusiveLock);
@ -312,11 +313,13 @@ AlterForeignDataWrapperOwner(const char *name, Oid newOwnerId)
AlterForeignDataWrapperOwner_internal(rel, tup, newOwnerId); AlterForeignDataWrapperOwner_internal(rel, tup, newOwnerId);
ObjectAddressSet(address, ForeignDataWrapperRelationId, fdwId);
heap_freetuple(tup); heap_freetuple(tup);
heap_close(rel, RowExclusiveLock); 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 * Change foreign server owner -- by name
*/ */
Oid ObjectAddress
AlterForeignServerOwner(const char *name, Oid newOwnerId) AlterForeignServerOwner(const char *name, Oid newOwnerId)
{ {
Oid servOid; Oid servOid;
HeapTuple tup; HeapTuple tup;
Relation rel; Relation rel;
ObjectAddress address;
rel = heap_open(ForeignServerRelationId, RowExclusiveLock); rel = heap_open(ForeignServerRelationId, RowExclusiveLock);
@ -447,11 +451,13 @@ AlterForeignServerOwner(const char *name, Oid newOwnerId)
AlterForeignServerOwner_internal(rel, tup, newOwnerId); AlterForeignServerOwner_internal(rel, tup, newOwnerId);
ObjectAddressSet(address, ForeignServerRelationId, servOid);
heap_freetuple(tup); heap_freetuple(tup);
heap_close(rel, RowExclusiveLock); heap_close(rel, RowExclusiveLock);
return servOid; return address;
} }
/* /*
@ -569,7 +575,7 @@ parse_func_options(List *func_options,
/* /*
* Create a foreign-data wrapper * Create a foreign-data wrapper
*/ */
Oid ObjectAddress
CreateForeignDataWrapper(CreateFdwStmt *stmt) CreateForeignDataWrapper(CreateFdwStmt *stmt)
{ {
Relation rel; Relation rel;
@ -676,14 +682,14 @@ CreateForeignDataWrapper(CreateFdwStmt *stmt)
heap_close(rel, RowExclusiveLock); heap_close(rel, RowExclusiveLock);
return fdwId; return myself;
} }
/* /*
* Alter foreign-data wrapper * Alter foreign-data wrapper
*/ */
Oid ObjectAddress
AlterForeignDataWrapper(AlterFdwStmt *stmt) AlterForeignDataWrapper(AlterFdwStmt *stmt)
{ {
Relation rel; Relation rel;
@ -699,6 +705,7 @@ AlterForeignDataWrapper(AlterFdwStmt *stmt)
bool validator_given; bool validator_given;
Oid fdwhandler; Oid fdwhandler;
Oid fdwvalidator; Oid fdwvalidator;
ObjectAddress myself;
rel = heap_open(ForeignDataWrapperRelationId, RowExclusiveLock); rel = heap_open(ForeignDataWrapperRelationId, RowExclusiveLock);
@ -801,10 +808,11 @@ AlterForeignDataWrapper(AlterFdwStmt *stmt)
heap_freetuple(tp); heap_freetuple(tp);
ObjectAddressSet(myself, ForeignDataWrapperRelationId, fdwId);
/* Update function dependencies if we changed them */ /* Update function dependencies if we changed them */
if (handler_given || validator_given) if (handler_given || validator_given)
{ {
ObjectAddress myself;
ObjectAddress referenced; ObjectAddress referenced;
/* /*
@ -817,9 +825,6 @@ AlterForeignDataWrapper(AlterFdwStmt *stmt)
DEPENDENCY_NORMAL); DEPENDENCY_NORMAL);
/* And build new ones. */ /* And build new ones. */
myself.classId = ForeignDataWrapperRelationId;
myself.objectId = fdwId;
myself.objectSubId = 0;
if (OidIsValid(fdwhandler)) if (OidIsValid(fdwhandler))
{ {
@ -842,7 +847,7 @@ AlterForeignDataWrapper(AlterFdwStmt *stmt)
heap_close(rel, RowExclusiveLock); heap_close(rel, RowExclusiveLock);
return fdwId; return myself;
} }
@ -873,7 +878,7 @@ RemoveForeignDataWrapperById(Oid fdwId)
/* /*
* Create a foreign server * Create a foreign server
*/ */
Oid ObjectAddress
CreateForeignServer(CreateForeignServerStmt *stmt) CreateForeignServer(CreateForeignServerStmt *stmt)
{ {
Relation rel; Relation rel;
@ -979,14 +984,14 @@ CreateForeignServer(CreateForeignServerStmt *stmt)
heap_close(rel, RowExclusiveLock); heap_close(rel, RowExclusiveLock);
return srvId; return myself;
} }
/* /*
* Alter foreign server * Alter foreign server
*/ */
Oid ObjectAddress
AlterForeignServer(AlterForeignServerStmt *stmt) AlterForeignServer(AlterForeignServerStmt *stmt)
{ {
Relation rel; Relation rel;
@ -996,6 +1001,7 @@ AlterForeignServer(AlterForeignServerStmt *stmt)
bool repl_repl[Natts_pg_foreign_server]; bool repl_repl[Natts_pg_foreign_server];
Oid srvId; Oid srvId;
Form_pg_foreign_server srvForm; Form_pg_foreign_server srvForm;
ObjectAddress address;
rel = heap_open(ForeignServerRelationId, RowExclusiveLock); rel = heap_open(ForeignServerRelationId, RowExclusiveLock);
@ -1072,11 +1078,13 @@ AlterForeignServer(AlterForeignServerStmt *stmt)
InvokeObjectPostAlterHook(ForeignServerRelationId, srvId, 0); InvokeObjectPostAlterHook(ForeignServerRelationId, srvId, 0);
ObjectAddressSet(address, ForeignServerRelationId, srvId);
heap_freetuple(tp); heap_freetuple(tp);
heap_close(rel, RowExclusiveLock); 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 * Create user mapping
*/ */
Oid ObjectAddress
CreateUserMapping(CreateUserMappingStmt *stmt) CreateUserMapping(CreateUserMappingStmt *stmt)
{ {
Relation rel; Relation rel;
@ -1225,14 +1233,14 @@ CreateUserMapping(CreateUserMappingStmt *stmt)
heap_close(rel, RowExclusiveLock); heap_close(rel, RowExclusiveLock);
return umId; return myself;
} }
/* /*
* Alter user mapping * Alter user mapping
*/ */
Oid ObjectAddress
AlterUserMapping(AlterUserMappingStmt *stmt) AlterUserMapping(AlterUserMappingStmt *stmt)
{ {
Relation rel; Relation rel;
@ -1243,6 +1251,7 @@ AlterUserMapping(AlterUserMappingStmt *stmt)
Oid useId; Oid useId;
Oid umId; Oid umId;
ForeignServer *srv; ForeignServer *srv;
ObjectAddress address;
rel = heap_open(UserMappingRelationId, RowExclusiveLock); rel = heap_open(UserMappingRelationId, RowExclusiveLock);
@ -1309,11 +1318,13 @@ AlterUserMapping(AlterUserMappingStmt *stmt)
simple_heap_update(rel, &tp->t_self, tp); simple_heap_update(rel, &tp->t_self, tp);
CatalogUpdateIndexes(rel, tp); CatalogUpdateIndexes(rel, tp);
ObjectAddressSet(address, UserMappingRelationId, umId);
heap_freetuple(tp); heap_freetuple(tp);
heap_close(rel, RowExclusiveLock); heap_close(rel, RowExclusiveLock);
return umId; return address;
} }

View File

@ -112,6 +112,7 @@ compute_return_type(TypeName *returnType, Oid languageOid,
Oid namespaceId; Oid namespaceId;
AclResult aclresult; AclResult aclresult;
char *typname; char *typname;
ObjectAddress address;
/* /*
* Only C-coded functions can be I/O functions. We enforce this * 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) if (aclresult != ACLCHECK_OK)
aclcheck_error(aclresult, ACL_KIND_NAMESPACE, aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
get_namespace_name(namespaceId)); get_namespace_name(namespaceId));
rettype = TypeShellMake(typname, namespaceId, GetUserId()); address = TypeShellMake(typname, namespaceId, GetUserId());
rettype = address.objectId;
Assert(OidIsValid(rettype)); Assert(OidIsValid(rettype));
} }
@ -810,7 +812,7 @@ interpret_AS_clause(Oid languageOid, const char *languageName,
* CreateFunction * CreateFunction
* Execute a CREATE FUNCTION utility statement. * Execute a CREATE FUNCTION utility statement.
*/ */
Oid ObjectAddress
CreateFunction(CreateFunctionStmt *stmt, const char *queryString) CreateFunction(CreateFunctionStmt *stmt, const char *queryString)
{ {
char *probin_str; char *probin_str;
@ -1071,7 +1073,7 @@ RemoveFunctionById(Oid funcOid)
* RENAME and OWNER clauses, which are handled as part of the generic * RENAME and OWNER clauses, which are handled as part of the generic
* ALTER framework). * ALTER framework).
*/ */
Oid ObjectAddress
AlterFunction(AlterFunctionStmt *stmt) AlterFunction(AlterFunctionStmt *stmt)
{ {
HeapTuple tup; HeapTuple tup;
@ -1086,6 +1088,7 @@ AlterFunction(AlterFunctionStmt *stmt)
List *set_items = NIL; List *set_items = NIL;
DefElem *cost_item = NULL; DefElem *cost_item = NULL;
DefElem *rows_item = NULL; DefElem *rows_item = NULL;
ObjectAddress address;
rel = heap_open(ProcedureRelationId, RowExclusiveLock); rel = heap_open(ProcedureRelationId, RowExclusiveLock);
@ -1201,10 +1204,12 @@ AlterFunction(AlterFunctionStmt *stmt)
InvokeObjectPostAlterHook(ProcedureRelationId, funcOid, 0); InvokeObjectPostAlterHook(ProcedureRelationId, funcOid, 0);
ObjectAddressSet(address, ProcedureRelationId, funcOid);
heap_close(rel, NoLock); heap_close(rel, NoLock);
heap_freetuple(tup); heap_freetuple(tup);
return funcOid; return address;
} }
/* /*
@ -1282,7 +1287,7 @@ SetFunctionArgType(Oid funcOid, int argIndex, Oid newArgType)
/* /*
* CREATE CAST * CREATE CAST
*/ */
Oid ObjectAddress
CreateCast(CreateCastStmt *stmt) CreateCast(CreateCastStmt *stmt)
{ {
Oid sourcetypeid; Oid sourcetypeid;
@ -1596,7 +1601,7 @@ CreateCast(CreateCastStmt *stmt)
heap_close(relation, RowExclusiveLock); heap_close(relation, RowExclusiveLock);
return castid; return myself;
} }
/* /*

View File

@ -291,9 +291,9 @@ CheckIndexCompatible(Oid oldId,
* it will be filled later. * it will be filled later.
* 'quiet': suppress the NOTICE chatter ordinarily provided for constraints. * '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, DefineIndex(Oid relationId,
IndexStmt *stmt, IndexStmt *stmt,
Oid indexRelationId, Oid indexRelationId,
@ -323,6 +323,7 @@ DefineIndex(Oid relationId,
int numberOfAttributes; int numberOfAttributes;
TransactionId limitXmin; TransactionId limitXmin;
VirtualTransactionId *old_snapshots; VirtualTransactionId *old_snapshots;
ObjectAddress address;
int n_old_snapshots; int n_old_snapshots;
LockRelId heaprelid; LockRelId heaprelid;
LOCKTAG heaplocktag; LOCKTAG heaplocktag;
@ -613,10 +614,12 @@ DefineIndex(Oid relationId,
stmt->concurrent, !check_rights, stmt->concurrent, !check_rights,
stmt->if_not_exists); stmt->if_not_exists);
ObjectAddressSet(address, RelationRelationId, indexRelationId);
if (!OidIsValid(indexRelationId)) if (!OidIsValid(indexRelationId))
{ {
heap_close(rel, NoLock); heap_close(rel, NoLock);
return indexRelationId; return address;
} }
/* Add any requested comment */ /* Add any requested comment */
@ -628,7 +631,7 @@ DefineIndex(Oid relationId,
{ {
/* Close the heap and we're done, in the non-concurrent case */ /* Close the heap and we're done, in the non-concurrent case */
heap_close(rel, NoLock); heap_close(rel, NoLock);
return indexRelationId; return address;
} }
/* save lockrelid and locktag for below, then close rel */ /* save lockrelid and locktag for below, then close rel */
@ -873,7 +876,7 @@ DefineIndex(Oid relationId,
*/ */
UnlockRelationIdForSession(&heaprelid, ShareUpdateExclusiveLock); UnlockRelationIdForSession(&heaprelid, ShareUpdateExclusiveLock);
return indexRelationId; return address;
} }

View File

@ -134,7 +134,7 @@ SetMatViewPopulatedState(Relation relation, bool newstate)
* The matview's "populated" state is changed based on whether the contents * The matview's "populated" state is changed based on whether the contents
* reflect the result set of the materialized view's query. * reflect the result set of the materialized view's query.
*/ */
Oid ObjectAddress
ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString, ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString,
ParamListInfo params, char *completionTag) ParamListInfo params, char *completionTag)
{ {
@ -153,6 +153,7 @@ ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString,
Oid save_userid; Oid save_userid;
int save_sec_context; int save_sec_context;
int save_nestlevel; int save_nestlevel;
ObjectAddress address;
/* Determine strength of lock needed. */ /* Determine strength of lock needed. */
concurrent = stmt->concurrent; concurrent = stmt->concurrent;
@ -311,7 +312,9 @@ ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString,
/* Restore userid and security context */ /* Restore userid and security context */
SetUserIdAndSecContext(save_userid, save_sec_context); SetUserIdAndSecContext(save_userid, save_sec_context);
return matviewOid; ObjectAddressSet(address, RelationRelationId, matviewOid);
return address;
} }
/* /*

View File

@ -246,7 +246,7 @@ get_opclass_oid(Oid amID, List *opclassname, bool missing_ok)
* *
* Caller must have done permissions checks etc. already. * Caller must have done permissions checks etc. already.
*/ */
static Oid static ObjectAddress
CreateOpFamily(char *amname, char *opfname, Oid namespaceoid, Oid amoid) CreateOpFamily(char *amname, char *opfname, Oid namespaceoid, Oid amoid)
{ {
Oid opfamilyoid; Oid opfamilyoid;
@ -319,14 +319,14 @@ CreateOpFamily(char *amname, char *opfname, Oid namespaceoid, Oid amoid)
heap_close(rel, RowExclusiveLock); heap_close(rel, RowExclusiveLock);
return opfamilyoid; return myself;
} }
/* /*
* DefineOpClass * DefineOpClass
* Define a new index operator class. * Define a new index operator class.
*/ */
Oid ObjectAddress
DefineOpClass(CreateOpClassStmt *stmt) DefineOpClass(CreateOpClassStmt *stmt)
{ {
char *opcname; /* name of opclass we're creating */ char *opcname; /* name of opclass we're creating */
@ -445,11 +445,14 @@ DefineOpClass(CreateOpClassStmt *stmt)
} }
else else
{ {
ObjectAddress tmpAddr;
/* /*
* Create it ... again no need for more permissions ... * Create it ... again no need for more permissions ...
*/ */
opfamilyoid = CreateOpFamily(stmt->amname, opcname, tmpAddr = CreateOpFamily(stmt->amname, opcname,
namespaceoid, amoid); namespaceoid, amoid);
opfamilyoid = tmpAddr.objectId;
} }
} }
@ -719,7 +722,7 @@ DefineOpClass(CreateOpClassStmt *stmt)
heap_close(rel, RowExclusiveLock); heap_close(rel, RowExclusiveLock);
return opclassoid; return myself;
} }
@ -727,7 +730,7 @@ DefineOpClass(CreateOpClassStmt *stmt)
* DefineOpFamily * DefineOpFamily
* Define a new index operator family. * Define a new index operator family.
*/ */
Oid ObjectAddress
DefineOpFamily(CreateOpFamilyStmt *stmt) DefineOpFamily(CreateOpFamilyStmt *stmt)
{ {
char *opfname; /* name of opfamily we're creating */ char *opfname; /* name of opfamily we're creating */

View File

@ -59,7 +59,7 @@
* *
* 'parameters' is a list of DefElem * 'parameters' is a list of DefElem
*/ */
Oid ObjectAddress
DefineOperator(List *names, List *parameters) DefineOperator(List *names, List *parameters)
{ {
char *oprName; char *oprName;

View File

@ -460,7 +460,7 @@ RemovePolicyById(Oid policy_id)
* *
* stmt - the CreatePolicyStmt that describes the policy to create. * stmt - the CreatePolicyStmt that describes the policy to create.
*/ */
Oid ObjectAddress
CreatePolicy(CreatePolicyStmt *stmt) CreatePolicy(CreatePolicyStmt *stmt)
{ {
Relation pg_policy_rel; Relation pg_policy_rel;
@ -626,7 +626,7 @@ CreatePolicy(CreatePolicyStmt *stmt)
relation_close(target_table, NoLock); relation_close(target_table, NoLock);
heap_close(pg_policy_rel, RowExclusiveLock); 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. * stmt - the AlterPolicyStmt that describes the policy and how to alter it.
*/ */
Oid ObjectAddress
AlterPolicy(AlterPolicyStmt *stmt) AlterPolicy(AlterPolicyStmt *stmt)
{ {
Relation pg_policy_rel; Relation pg_policy_rel;
@ -830,14 +830,14 @@ AlterPolicy(AlterPolicyStmt *stmt)
relation_close(target_table, NoLock); relation_close(target_table, NoLock);
heap_close(pg_policy_rel, RowExclusiveLock); heap_close(pg_policy_rel, RowExclusiveLock);
return policy_id; return myself;
} }
/* /*
* rename_policy - * rename_policy -
* change the name of a policy on a relation * change the name of a policy on a relation
*/ */
Oid ObjectAddress
rename_policy(RenameStmt *stmt) rename_policy(RenameStmt *stmt)
{ {
Relation pg_policy_rel; Relation pg_policy_rel;
@ -847,6 +847,7 @@ rename_policy(RenameStmt *stmt)
ScanKeyData skey[2]; ScanKeyData skey[2];
SysScanDesc sscan; SysScanDesc sscan;
HeapTuple policy_tuple; HeapTuple policy_tuple;
ObjectAddress address;
/* Get id of table. Also handles permissions checks. */ /* Get id of table. Also handles permissions checks. */
table_id = RangeVarGetRelidExtended(stmt->relation, AccessExclusiveLock, table_id = RangeVarGetRelidExtended(stmt->relation, AccessExclusiveLock,
@ -925,6 +926,8 @@ rename_policy(RenameStmt *stmt)
InvokeObjectPostAlterHook(PolicyRelationId, InvokeObjectPostAlterHook(PolicyRelationId,
HeapTupleGetOid(policy_tuple), 0); HeapTupleGetOid(policy_tuple), 0);
ObjectAddressSet(address, PolicyRelationId, opoloid);
/* /*
* Invalidate relation's relcache entry so that other backends (and * Invalidate relation's relcache entry so that other backends (and
* this one too!) are sent SI message to make them rebuild relcache * 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); heap_close(pg_policy_rel, RowExclusiveLock);
relation_close(target_table, NoLock); relation_close(target_table, NoLock);
return opoloid; return address;
} }
/* /*

View File

@ -51,7 +51,7 @@ typedef struct
char *tmpllibrary; /* path of shared library */ char *tmpllibrary; /* path of shared library */
} PLTemplate; } 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 languageOwner, Oid handlerOid, Oid inlineOid,
Oid valOid, bool trusted); Oid valOid, bool trusted);
static PLTemplate *find_language_template(const char *languageName); static PLTemplate *find_language_template(const char *languageName);
@ -60,10 +60,11 @@ static PLTemplate *find_language_template(const char *languageName);
* CREATE PROCEDURAL LANGUAGE * CREATE PROCEDURAL LANGUAGE
* --------------------------------------------------------------------- * ---------------------------------------------------------------------
*/ */
Oid ObjectAddress
CreateProceduralLanguage(CreatePLangStmt *stmt) CreateProceduralLanguage(CreatePLangStmt *stmt)
{ {
PLTemplate *pltemplate; PLTemplate *pltemplate;
ObjectAddress tmpAddr;
Oid handlerOid, Oid handlerOid,
inlineOid, inlineOid,
valOid; valOid;
@ -118,30 +119,31 @@ CreateProceduralLanguage(CreatePLangStmt *stmt)
} }
else else
{ {
handlerOid = ProcedureCreate(pltemplate->tmplhandler, tmpAddr = ProcedureCreate(pltemplate->tmplhandler,
PG_CATALOG_NAMESPACE, PG_CATALOG_NAMESPACE,
false, /* replace */ false, /* replace */
false, /* returnsSet */ false, /* returnsSet */
LANGUAGE_HANDLEROID, LANGUAGE_HANDLEROID,
BOOTSTRAP_SUPERUSERID, BOOTSTRAP_SUPERUSERID,
ClanguageId, ClanguageId,
F_FMGR_C_VALIDATOR, F_FMGR_C_VALIDATOR,
pltemplate->tmplhandler, pltemplate->tmplhandler,
pltemplate->tmpllibrary, pltemplate->tmpllibrary,
false, /* isAgg */ false, /* isAgg */
false, /* isWindowFunc */ false, /* isWindowFunc */
false, /* security_definer */ false, /* security_definer */
false, /* isLeakProof */ false, /* isLeakProof */
false, /* isStrict */ false, /* isStrict */
PROVOLATILE_VOLATILE, PROVOLATILE_VOLATILE,
buildoidvector(funcargtypes, 0), buildoidvector(funcargtypes, 0),
PointerGetDatum(NULL), PointerGetDatum(NULL),
PointerGetDatum(NULL), PointerGetDatum(NULL),
PointerGetDatum(NULL), PointerGetDatum(NULL),
NIL, NIL,
PointerGetDatum(NULL), PointerGetDatum(NULL),
1, 1,
0); 0);
handlerOid = tmpAddr.objectId;
} }
/* /*
@ -155,30 +157,31 @@ CreateProceduralLanguage(CreatePLangStmt *stmt)
inlineOid = LookupFuncName(funcname, 1, funcargtypes, true); inlineOid = LookupFuncName(funcname, 1, funcargtypes, true);
if (!OidIsValid(inlineOid)) if (!OidIsValid(inlineOid))
{ {
inlineOid = ProcedureCreate(pltemplate->tmplinline, tmpAddr = ProcedureCreate(pltemplate->tmplinline,
PG_CATALOG_NAMESPACE, PG_CATALOG_NAMESPACE,
false, /* replace */ false, /* replace */
false, /* returnsSet */ false, /* returnsSet */
VOIDOID, VOIDOID,
BOOTSTRAP_SUPERUSERID, BOOTSTRAP_SUPERUSERID,
ClanguageId, ClanguageId,
F_FMGR_C_VALIDATOR, F_FMGR_C_VALIDATOR,
pltemplate->tmplinline, pltemplate->tmplinline,
pltemplate->tmpllibrary, pltemplate->tmpllibrary,
false, /* isAgg */ false, /* isAgg */
false, /* isWindowFunc */ false, /* isWindowFunc */
false, /* security_definer */ false, /* security_definer */
false, /* isLeakProof */ false, /* isLeakProof */
true, /* isStrict */ true, /* isStrict */
PROVOLATILE_VOLATILE, PROVOLATILE_VOLATILE,
buildoidvector(funcargtypes, 1), buildoidvector(funcargtypes, 1),
PointerGetDatum(NULL), PointerGetDatum(NULL),
PointerGetDatum(NULL), PointerGetDatum(NULL),
PointerGetDatum(NULL), PointerGetDatum(NULL),
NIL, NIL,
PointerGetDatum(NULL), PointerGetDatum(NULL),
1, 1,
0); 0);
inlineOid = tmpAddr.objectId;
} }
} }
else else
@ -195,30 +198,31 @@ CreateProceduralLanguage(CreatePLangStmt *stmt)
valOid = LookupFuncName(funcname, 1, funcargtypes, true); valOid = LookupFuncName(funcname, 1, funcargtypes, true);
if (!OidIsValid(valOid)) if (!OidIsValid(valOid))
{ {
valOid = ProcedureCreate(pltemplate->tmplvalidator, tmpAddr = ProcedureCreate(pltemplate->tmplvalidator,
PG_CATALOG_NAMESPACE, PG_CATALOG_NAMESPACE,
false, /* replace */ false, /* replace */
false, /* returnsSet */ false, /* returnsSet */
VOIDOID, VOIDOID,
BOOTSTRAP_SUPERUSERID, BOOTSTRAP_SUPERUSERID,
ClanguageId, ClanguageId,
F_FMGR_C_VALIDATOR, F_FMGR_C_VALIDATOR,
pltemplate->tmplvalidator, pltemplate->tmplvalidator,
pltemplate->tmpllibrary, pltemplate->tmpllibrary,
false, /* isAgg */ false, /* isAgg */
false, /* isWindowFunc */ false, /* isWindowFunc */
false, /* security_definer */ false, /* security_definer */
false, /* isLeakProof */ false, /* isLeakProof */
true, /* isStrict */ true, /* isStrict */
PROVOLATILE_VOLATILE, PROVOLATILE_VOLATILE,
buildoidvector(funcargtypes, 1), buildoidvector(funcargtypes, 1),
PointerGetDatum(NULL), PointerGetDatum(NULL),
PointerGetDatum(NULL), PointerGetDatum(NULL),
PointerGetDatum(NULL), PointerGetDatum(NULL),
NIL, NIL,
PointerGetDatum(NULL), PointerGetDatum(NULL),
1, 1,
0); 0);
valOid = tmpAddr.objectId;
} }
} }
else else
@ -309,7 +313,7 @@ CreateProceduralLanguage(CreatePLangStmt *stmt)
/* /*
* Guts of language creation. * Guts of language creation.
*/ */
static Oid static ObjectAddress
create_proc_lang(const char *languageName, bool replace, create_proc_lang(const char *languageName, bool replace,
Oid languageOwner, Oid handlerOid, Oid inlineOid, Oid languageOwner, Oid handlerOid, Oid inlineOid,
Oid valOid, bool trusted) Oid valOid, bool trusted)
@ -433,7 +437,7 @@ create_proc_lang(const char *languageName, bool replace,
heap_close(rel, RowExclusiveLock); heap_close(rel, RowExclusiveLock);
return myself.objectId; return myself;
} }
/* /*

View File

@ -195,13 +195,14 @@ RemoveSchemaById(Oid schemaOid)
/* /*
* Rename schema * Rename schema
*/ */
Oid ObjectAddress
RenameSchema(const char *oldname, const char *newname) RenameSchema(const char *oldname, const char *newname)
{ {
Oid nspOid; Oid nspOid;
HeapTuple tup; HeapTuple tup;
Relation rel; Relation rel;
AclResult aclresult; AclResult aclresult;
ObjectAddress address;
rel = heap_open(NamespaceRelationId, RowExclusiveLock); rel = heap_open(NamespaceRelationId, RowExclusiveLock);
@ -243,10 +244,12 @@ RenameSchema(const char *oldname, const char *newname)
InvokeObjectPostAlterHook(NamespaceRelationId, HeapTupleGetOid(tup), 0); InvokeObjectPostAlterHook(NamespaceRelationId, HeapTupleGetOid(tup), 0);
ObjectAddressSet(address, NamespaceRelationId, nspOid);
heap_close(rel, NoLock); heap_close(rel, NoLock);
heap_freetuple(tup); heap_freetuple(tup);
return nspOid; return address;
} }
void void
@ -272,12 +275,13 @@ AlterSchemaOwner_oid(Oid oid, Oid newOwnerId)
/* /*
* Change schema owner * Change schema owner
*/ */
Oid ObjectAddress
AlterSchemaOwner(const char *name, Oid newOwnerId) AlterSchemaOwner(const char *name, Oid newOwnerId)
{ {
Oid nspOid; Oid nspOid;
HeapTuple tup; HeapTuple tup;
Relation rel; Relation rel;
ObjectAddress address;
rel = heap_open(NamespaceRelationId, RowExclusiveLock); rel = heap_open(NamespaceRelationId, RowExclusiveLock);
@ -291,11 +295,13 @@ AlterSchemaOwner(const char *name, Oid newOwnerId)
AlterSchemaOwner_internal(tup, rel, newOwnerId); AlterSchemaOwner_internal(tup, rel, newOwnerId);
ObjectAddressSet(address, NamespaceRelationId, nspOid);
ReleaseSysCache(tup); ReleaseSysCache(tup);
heap_close(rel, RowExclusiveLock); heap_close(rel, RowExclusiveLock);
return nspOid; return address;
} }
static void static void

View File

@ -37,8 +37,10 @@ static List *label_provider_list = NIL;
* ExecSecLabelStmt -- * ExecSecLabelStmt --
* *
* Apply a security label to a database object. * 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) ExecSecLabelStmt(SecLabelStmt *stmt)
{ {
LabelProvider *provider = NULL; LabelProvider *provider = NULL;
@ -133,7 +135,7 @@ ExecSecLabelStmt(SecLabelStmt *stmt)
if (relation != NULL) if (relation != NULL)
relation_close(relation, NoLock); relation_close(relation, NoLock);
return address.objectId; return address;
} }
/* /*

View File

@ -104,13 +104,14 @@ static void process_owned_by(Relation seqrel, List *owned_by);
* DefineSequence * DefineSequence
* Creates a new sequence relation * Creates a new sequence relation
*/ */
Oid ObjectAddress
DefineSequence(CreateSeqStmt *seq) DefineSequence(CreateSeqStmt *seq)
{ {
FormData_pg_sequence new; FormData_pg_sequence new;
List *owned_by; List *owned_by;
CreateStmt *stmt = makeNode(CreateStmt); CreateStmt *stmt = makeNode(CreateStmt);
Oid seqoid; Oid seqoid;
ObjectAddress address;
Relation rel; Relation rel;
HeapTuple tuple; HeapTuple tuple;
TupleDesc tupDesc; TupleDesc tupDesc;
@ -139,7 +140,7 @@ DefineSequence(CreateSeqStmt *seq)
(errcode(ERRCODE_DUPLICATE_TABLE), (errcode(ERRCODE_DUPLICATE_TABLE),
errmsg("relation \"%s\" already exists, skipping", errmsg("relation \"%s\" already exists, skipping",
seq->sequence->relname))); seq->sequence->relname)));
return InvalidOid; return InvalidObjectAddress;
} }
} }
@ -233,7 +234,8 @@ DefineSequence(CreateSeqStmt *seq)
stmt->tablespacename = NULL; stmt->tablespacename = NULL;
stmt->if_not_exists = seq->if_not_exists; 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); Assert(seqoid != InvalidOid);
rel = heap_open(seqoid, AccessExclusiveLock); rel = heap_open(seqoid, AccessExclusiveLock);
@ -249,7 +251,7 @@ DefineSequence(CreateSeqStmt *seq)
heap_close(rel, NoLock); 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 * Modify the definition of a sequence relation
*/ */
Oid ObjectAddress
AlterSequence(AlterSeqStmt *stmt) AlterSequence(AlterSeqStmt *stmt)
{ {
Oid relid; Oid relid;
@ -412,6 +414,7 @@ AlterSequence(AlterSeqStmt *stmt)
Form_pg_sequence seq; Form_pg_sequence seq;
FormData_pg_sequence new; FormData_pg_sequence new;
List *owned_by; List *owned_by;
ObjectAddress address;
/* Open and lock sequence. */ /* Open and lock sequence. */
relid = RangeVarGetRelid(stmt->sequence, AccessShareLock, stmt->missing_ok); relid = RangeVarGetRelid(stmt->sequence, AccessShareLock, stmt->missing_ok);
@ -420,7 +423,7 @@ AlterSequence(AlterSeqStmt *stmt)
ereport(NOTICE, ereport(NOTICE,
(errmsg("relation \"%s\" does not exist, skipping", (errmsg("relation \"%s\" does not exist, skipping",
stmt->sequence->relname))); stmt->sequence->relname)));
return InvalidOid; return InvalidObjectAddress;
} }
init_sequence(relid, &elm, &seqrel); init_sequence(relid, &elm, &seqrel);
@ -484,9 +487,11 @@ AlterSequence(AlterSeqStmt *stmt)
InvokeObjectPostAlterHook(RelationRelationId, relid, 0); InvokeObjectPostAlterHook(RelationRelationId, relid, 0);
ObjectAddressSet(address, RelationRelationId, relid);
relation_close(seqrel, NoLock); relation_close(seqrel, NoLock);
return relid; return address;
} }

View File

@ -435,17 +435,19 @@ static void RangeVarCallbackForAlterRelation(const RangeVar *rv, Oid relid,
* The other arguments are used to extend the behavior for other cases: * The other arguments are used to extend the behavior for other cases:
* relkind: relkind to assign to the new relation * relkind: relkind to assign to the new relation
* ownerId: if not InvalidOid, use this as the new relation's owner. * 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 * Note that permissions checks are done against current user regardless of
* ownerId. A nonzero ownerId is used when someone is creating a relation * 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 * "on behalf of" someone else, so we still want to see that the current user
* has permissions to do it. * has permissions to do it.
* *
* If successful, returns the OID of the new relation. * If successful, returns the address of the new relation.
* ---------------------------------------------------------------- * ----------------------------------------------------------------
*/ */
Oid ObjectAddress
DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId) DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
ObjectAddress *typaddress)
{ {
char relname[NAMEDATALEN]; char relname[NAMEDATALEN];
Oid namespaceId; Oid namespaceId;
@ -465,6 +467,7 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId)
AttrNumber attnum; AttrNumber attnum;
static char *validnsps[] = HEAP_RELOPT_NAMESPACES; static char *validnsps[] = HEAP_RELOPT_NAMESPACES;
Oid ofTypeId; Oid ofTypeId;
ObjectAddress address;
/* /*
* Truncate relname to appropriate length (probably a waste of time, as * Truncate relname to appropriate length (probably a waste of time, as
@ -657,7 +660,8 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId)
reloptions, reloptions,
true, true,
allowSystemTableMods, allowSystemTableMods,
false); false,
typaddress);
/* Store inheritance information for new rel. */ /* Store inheritance information for new rel. */
StoreCatalogInheritance(relationId, inheritOids); StoreCatalogInheritance(relationId, inheritOids);
@ -689,13 +693,15 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId)
AddRelationNewConstraints(rel, rawDefaults, stmt->constraints, AddRelationNewConstraints(rel, rawDefaults, stmt->constraints,
true, true, false); true, true, false);
ObjectAddressSet(address, RelationRelationId, relationId);
/* /*
* Clean up. We keep lock on new relation (although it shouldn't be * Clean up. We keep lock on new relation (although it shouldn't be
* visible to anyone else anyway, until commit). * visible to anyone else anyway, until commit).
*/ */
relation_close(rel, NoLock); 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 * renameatt_internal - workhorse for renameatt
*
* Return value is the attribute number in the 'myrelid' relation.
*/ */
static void static AttrNumber
renameatt_internal(Oid myrelid, renameatt_internal(Oid myrelid,
const char *oldattname, const char *oldattname,
const char *newattname, const char *newattname,
@ -2172,7 +2180,7 @@ renameatt_internal(Oid myrelid,
Relation attrelation; Relation attrelation;
HeapTuple atttup; HeapTuple atttup;
Form_pg_attribute attform; Form_pg_attribute attform;
int attnum; AttrNumber attnum;
/* /*
* Grab an exclusive lock on the target table, which we will NOT release * 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); heap_close(attrelation, RowExclusiveLock);
relation_close(targetrelation, NoLock); /* close rel but keep lock */ 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 * renameatt - changes the name of a attribute in a relation
*
* The returned ObjectAddress is that of the renamed column.
*/ */
Oid ObjectAddress
renameatt(RenameStmt *stmt) renameatt(RenameStmt *stmt)
{ {
Oid relid; Oid relid;
AttrNumber attnum;
ObjectAddress address;
/* lock level taken here should match renameatt_internal */ /* lock level taken here should match renameatt_internal */
relid = RangeVarGetRelidExtended(stmt->relation, AccessExclusiveLock, relid = RangeVarGetRelidExtended(stmt->relation, AccessExclusiveLock,
@ -2339,26 +2353,27 @@ renameatt(RenameStmt *stmt)
ereport(NOTICE, ereport(NOTICE,
(errmsg("relation \"%s\" does not exist, skipping", (errmsg("relation \"%s\" does not exist, skipping",
stmt->relation->relname))); stmt->relation->relname)));
return InvalidOid; return InvalidObjectAddress;
} }
renameatt_internal(relid, attnum =
stmt->subname, /* old att name */ renameatt_internal(relid,
stmt->newname, /* new att name */ stmt->subname, /* old att name */
interpretInhOption(stmt->relation->inhOpt), /* recursive? */ stmt->newname, /* new att name */
false, /* recursing? */ interpretInhOption(stmt->relation->inhOpt), /* recursive? */
0, /* expected inhcount */ false, /* recursing? */
stmt->behavior); 0, /* expected inhcount */
stmt->behavior);
/* This is an ALTER TABLE command so it's about the relid */ ObjectAddressSubSet(address, RelationRelationId, relid, attnum);
return relid;
return address;
} }
/* /*
* same logic as renameatt_internal * same logic as renameatt_internal
*/ */
static Oid static ObjectAddress
rename_constraint_internal(Oid myrelid, rename_constraint_internal(Oid myrelid,
Oid mytypid, Oid mytypid,
const char *oldconname, const char *oldconname,
@ -2371,6 +2386,7 @@ rename_constraint_internal(Oid myrelid,
Oid constraintOid; Oid constraintOid;
HeapTuple tuple; HeapTuple tuple;
Form_pg_constraint con; Form_pg_constraint con;
ObjectAddress address;
AssertArg(!myrelid || !mytypid); AssertArg(!myrelid || !mytypid);
@ -2446,15 +2462,17 @@ rename_constraint_internal(Oid myrelid,
else else
RenameConstraintById(constraintOid, newconname); RenameConstraintById(constraintOid, newconname);
ObjectAddressSet(address, ConstraintRelationId, constraintOid);
ReleaseSysCache(tuple); ReleaseSysCache(tuple);
if (targetrelation) if (targetrelation)
relation_close(targetrelation, NoLock); /* close rel but keep lock */ relation_close(targetrelation, NoLock); /* close rel but keep lock */
return constraintOid; return address;
} }
Oid ObjectAddress
RenameConstraint(RenameStmt *stmt) RenameConstraint(RenameStmt *stmt)
{ {
Oid relid = InvalidOid; Oid relid = InvalidOid;
@ -2497,10 +2515,11 @@ RenameConstraint(RenameStmt *stmt)
* Execute ALTER TABLE/INDEX/SEQUENCE/VIEW/MATERIALIZED VIEW/FOREIGN TABLE * Execute ALTER TABLE/INDEX/SEQUENCE/VIEW/MATERIALIZED VIEW/FOREIGN TABLE
* RENAME * RENAME
*/ */
Oid ObjectAddress
RenameRelation(RenameStmt *stmt) RenameRelation(RenameStmt *stmt)
{ {
Oid relid; Oid relid;
ObjectAddress address;
/* /*
* Grab an exclusive lock on the target table, index, sequence, view, * Grab an exclusive lock on the target table, index, sequence, view,
@ -2520,13 +2539,15 @@ RenameRelation(RenameStmt *stmt)
ereport(NOTICE, ereport(NOTICE,
(errmsg("relation \"%s\" does not exist, skipping", (errmsg("relation \"%s\" does not exist, skipping",
stmt->relation->relname))); stmt->relation->relname)));
return InvalidOid; return InvalidObjectAddress;
} }
/* Do the work */ /* Do the work */
RenameRelationInternal(relid, stmt->newname, false); 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 check_rights;
bool skip_build; bool skip_build;
bool quiet; bool quiet;
Oid new_index; ObjectAddress address;
Assert(IsA(stmt, IndexStmt)); Assert(IsA(stmt, IndexStmt));
Assert(!stmt->concurrent); Assert(!stmt->concurrent);
@ -5717,13 +5738,13 @@ ATExecAddIndex(AlteredTableInfo *tab, Relation rel,
/* suppress notices when rebuilding existing index */ /* suppress notices when rebuilding existing index */
quiet = is_rebuild; quiet = is_rebuild;
new_index = DefineIndex(RelationGetRelid(rel), address = DefineIndex(RelationGetRelid(rel),
stmt, stmt,
InvalidOid, /* no predefined OID */ InvalidOid, /* no predefined OID */
true, /* is_alter_table */ true, /* is_alter_table */
check_rights, check_rights,
skip_build, skip_build,
quiet); quiet);
/* /*
* If TryReuseIndex() stashed a relfilenode for us, we used it for the new * 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)) if (OidIsValid(stmt->oldNode))
{ {
Relation irel = index_open(new_index, NoLock); Relation irel = index_open(address.objectId, NoLock);
RelationPreserveStorage(irel->rd_node, true); RelationPreserveStorage(irel->rd_node, true);
index_close(irel, NoLock); index_close(irel, NoLock);
@ -10919,8 +10940,8 @@ ATPrepChangePersistence(Relation rel, bool toLogged)
/* /*
* Execute ALTER TABLE SET SCHEMA * Execute ALTER TABLE SET SCHEMA
*/ */
Oid ObjectAddress
AlterTableNamespace(AlterObjectSchemaStmt *stmt) AlterTableNamespace(AlterObjectSchemaStmt *stmt, Oid *oldschema)
{ {
Relation rel; Relation rel;
Oid relid; Oid relid;
@ -10928,6 +10949,7 @@ AlterTableNamespace(AlterObjectSchemaStmt *stmt)
Oid nspOid; Oid nspOid;
RangeVar *newrv; RangeVar *newrv;
ObjectAddresses *objsMoved; ObjectAddresses *objsMoved;
ObjectAddress myself;
relid = RangeVarGetRelidExtended(stmt->relation, AccessExclusiveLock, relid = RangeVarGetRelidExtended(stmt->relation, AccessExclusiveLock,
stmt->missing_ok, false, stmt->missing_ok, false,
@ -10939,7 +10961,7 @@ AlterTableNamespace(AlterObjectSchemaStmt *stmt)
ereport(NOTICE, ereport(NOTICE,
(errmsg("relation \"%s\" does not exist, skipping", (errmsg("relation \"%s\" does not exist, skipping",
stmt->relation->relname))); stmt->relation->relname)));
return InvalidOid; return InvalidObjectAddress;
} }
rel = relation_open(relid, NoLock); rel = relation_open(relid, NoLock);
@ -10972,10 +10994,15 @@ AlterTableNamespace(AlterObjectSchemaStmt *stmt)
AlterTableNamespaceInternal(rel, oldNspOid, nspOid, objsMoved); AlterTableNamespaceInternal(rel, oldNspOid, nspOid, objsMoved);
free_object_addresses(objsMoved); free_object_addresses(objsMoved);
ObjectAddressSet(myself, RelationRelationId, relid);
if (oldschema)
*oldschema = oldNspOid;
/* close rel, but keep lock until commit */ /* close rel, but keep lock until commit */
relation_close(rel, NoLock); relation_close(rel, NoLock);
return relid; return myself;
} }
/* /*

View File

@ -846,7 +846,7 @@ directory_is_empty(const char *path)
/* /*
* Rename a tablespace * Rename a tablespace
*/ */
Oid ObjectAddress
RenameTableSpace(const char *oldname, const char *newname) RenameTableSpace(const char *oldname, const char *newname)
{ {
Oid tspId; Oid tspId;
@ -856,6 +856,7 @@ RenameTableSpace(const char *oldname, const char *newname)
HeapTuple tup; HeapTuple tup;
HeapTuple newtuple; HeapTuple newtuple;
Form_pg_tablespace newform; Form_pg_tablespace newform;
ObjectAddress address;
/* Search pg_tablespace */ /* Search pg_tablespace */
rel = heap_open(TableSpaceRelationId, RowExclusiveLock); rel = heap_open(TableSpaceRelationId, RowExclusiveLock);
@ -912,9 +913,11 @@ RenameTableSpace(const char *oldname, const char *newname)
InvokeObjectPostAlterHook(TableSpaceRelationId, tspId, 0); InvokeObjectPostAlterHook(TableSpaceRelationId, tspId, 0);
ObjectAddressSet(address, TableSpaceRelationId, tspId);
heap_close(rel, NoLock); heap_close(rel, NoLock);
return tspId; return address;
} }
/* /*

View File

@ -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. * queryString is the source text of the CREATE TRIGGER command.
* This must be supplied if a whenClause is specified, else it can be NULL. * 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 * relation, as well as ACL_EXECUTE on the trigger function. For internal
* triggers the caller must apply any required permission checks. * triggers the caller must apply any required permission checks.
* *
* Note: can return InvalidOid if we decided to not create a trigger at all, * Note: can return InvalidObjectAddress if we decided to not create a trigger
* but a foreign-key constraint. This is a kluge for backwards compatibility. * at all, but a foreign-key constraint. This is a kluge for backwards
* compatibility.
*/ */
Oid ObjectAddress
CreateTrigger(CreateTrigStmt *stmt, const char *queryString, CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
Oid relOid, Oid refRelOid, Oid constraintOid, Oid indexOid, Oid relOid, Oid refRelOid, Oid constraintOid, Oid indexOid,
bool isInternal) bool isInternal)
@ -459,7 +460,7 @@ CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
ConvertTriggerToFK(stmt, funcoid); 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 */ /* Keep lock on target rel until end of xact */
heap_close(rel, NoLock); 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 * modify tgname in trigger tuple
* update row in catalog * update row in catalog
*/ */
Oid ObjectAddress
renametrig(RenameStmt *stmt) renametrig(RenameStmt *stmt)
{ {
Oid tgoid; Oid tgoid;
@ -1259,6 +1260,7 @@ renametrig(RenameStmt *stmt)
SysScanDesc tgscan; SysScanDesc tgscan;
ScanKeyData key[2]; ScanKeyData key[2];
Oid relid; Oid relid;
ObjectAddress address;
/* /*
* Look up name, check permissions, and acquire lock (which we will NOT * Look up name, check permissions, and acquire lock (which we will NOT
@ -1351,6 +1353,8 @@ renametrig(RenameStmt *stmt)
stmt->subname, RelationGetRelationName(targetrel)))); stmt->subname, RelationGetRelationName(targetrel))));
} }
ObjectAddressSet(address, TriggerRelationId, tgoid);
systable_endscan(tgscan); systable_endscan(tgscan);
heap_close(tgrel, RowExclusiveLock); heap_close(tgrel, RowExclusiveLock);
@ -1360,7 +1364,7 @@ renametrig(RenameStmt *stmt)
*/ */
relation_close(targetrel, NoLock); relation_close(targetrel, NoLock);
return tgoid; return address;
} }

View File

@ -120,8 +120,10 @@ get_ts_parser_func(DefElem *defel, int attnum)
/* /*
* make pg_depend entries for a new pg_ts_parser entry * 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) makeParserDependencies(HeapTuple tuple)
{ {
Form_pg_ts_parser prs = (Form_pg_ts_parser) GETSTRUCT(tuple); Form_pg_ts_parser prs = (Form_pg_ts_parser) GETSTRUCT(tuple);
@ -162,12 +164,14 @@ makeParserDependencies(HeapTuple tuple)
referenced.objectId = prs->prsheadline; referenced.objectId = prs->prsheadline;
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL); recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
} }
return myself;
} }
/* /*
* CREATE TEXT SEARCH PARSER * CREATE TEXT SEARCH PARSER
*/ */
Oid ObjectAddress
DefineTSParser(List *names, List *parameters) DefineTSParser(List *names, List *parameters)
{ {
char *prsname; char *prsname;
@ -179,6 +183,7 @@ DefineTSParser(List *names, List *parameters)
NameData pname; NameData pname;
Oid prsOid; Oid prsOid;
Oid namespaceoid; Oid namespaceoid;
ObjectAddress address;
if (!superuser()) if (!superuser())
ereport(ERROR, ereport(ERROR,
@ -269,7 +274,7 @@ DefineTSParser(List *names, List *parameters)
CatalogUpdateIndexes(prsRel, tup); CatalogUpdateIndexes(prsRel, tup);
makeParserDependencies(tup); address = makeParserDependencies(tup);
/* Post creation hook for new text search parser */ /* Post creation hook for new text search parser */
InvokeObjectPostCreateHook(TSParserRelationId, prsOid, 0); InvokeObjectPostCreateHook(TSParserRelationId, prsOid, 0);
@ -278,7 +283,7 @@ DefineTSParser(List *names, List *parameters)
heap_close(prsRel, RowExclusiveLock); 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 * 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) makeDictionaryDependencies(HeapTuple tuple)
{ {
Form_pg_ts_dict dict = (Form_pg_ts_dict) GETSTRUCT(tuple); Form_pg_ts_dict dict = (Form_pg_ts_dict) GETSTRUCT(tuple);
@ -337,6 +344,8 @@ makeDictionaryDependencies(HeapTuple tuple)
referenced.objectId = dict->dicttemplate; referenced.objectId = dict->dicttemplate;
referenced.objectSubId = 0; referenced.objectSubId = 0;
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL); recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
return myself;
} }
/* /*
@ -397,7 +406,7 @@ verify_dictoptions(Oid tmplId, List *dictoptions)
/* /*
* CREATE TEXT SEARCH DICTIONARY * CREATE TEXT SEARCH DICTIONARY
*/ */
Oid ObjectAddress
DefineTSDictionary(List *names, List *parameters) DefineTSDictionary(List *names, List *parameters)
{ {
ListCell *pl; ListCell *pl;
@ -412,6 +421,7 @@ DefineTSDictionary(List *names, List *parameters)
Oid namespaceoid; Oid namespaceoid;
AclResult aclresult; AclResult aclresult;
char *dictname; char *dictname;
ObjectAddress address;
/* Convert list of names to a name and namespace */ /* Convert list of names to a name and namespace */
namespaceoid = QualifiedNameGetCreationNamespace(names, &dictname); namespaceoid = QualifiedNameGetCreationNamespace(names, &dictname);
@ -475,7 +485,7 @@ DefineTSDictionary(List *names, List *parameters)
CatalogUpdateIndexes(dictRel, tup); CatalogUpdateIndexes(dictRel, tup);
makeDictionaryDependencies(tup); address = makeDictionaryDependencies(tup);
/* Post creation hook for new text search dictionary */ /* Post creation hook for new text search dictionary */
InvokeObjectPostCreateHook(TSDictionaryRelationId, dictOid, 0); InvokeObjectPostCreateHook(TSDictionaryRelationId, dictOid, 0);
@ -484,7 +494,7 @@ DefineTSDictionary(List *names, List *parameters)
heap_close(dictRel, RowExclusiveLock); heap_close(dictRel, RowExclusiveLock);
return dictOid; return address;
} }
/* /*
@ -514,7 +524,7 @@ RemoveTSDictionaryById(Oid dictId)
/* /*
* ALTER TEXT SEARCH DICTIONARY * ALTER TEXT SEARCH DICTIONARY
*/ */
Oid ObjectAddress
AlterTSDictionary(AlterTSDictionaryStmt *stmt) AlterTSDictionary(AlterTSDictionaryStmt *stmt)
{ {
HeapTuple tup, HeapTuple tup,
@ -528,6 +538,7 @@ AlterTSDictionary(AlterTSDictionaryStmt *stmt)
Datum repl_val[Natts_pg_ts_dict]; Datum repl_val[Natts_pg_ts_dict];
bool repl_null[Natts_pg_ts_dict]; bool repl_null[Natts_pg_ts_dict];
bool repl_repl[Natts_pg_ts_dict]; bool repl_repl[Natts_pg_ts_dict];
ObjectAddress address;
dictId = get_ts_dict_oid(stmt->dictname, false); dictId = get_ts_dict_oid(stmt->dictname, false);
@ -614,6 +625,8 @@ AlterTSDictionary(AlterTSDictionaryStmt *stmt)
InvokeObjectPostAlterHook(TSDictionaryRelationId, dictId, 0); InvokeObjectPostAlterHook(TSDictionaryRelationId, dictId, 0);
ObjectAddressSet(address, TSDictionaryRelationId, dictId);
/* /*
* NOTE: because we only support altering the options, not the template, * NOTE: because we only support altering the options, not the template,
* there is no need to update dependencies. This might have to change if * there is no need to update dependencies. This might have to change if
@ -625,7 +638,7 @@ AlterTSDictionary(AlterTSDictionaryStmt *stmt)
heap_close(rel, RowExclusiveLock); heap_close(rel, RowExclusiveLock);
return dictId; return address;
} }
/* ---------------------- TS Template commands -----------------------*/ /* ---------------------- 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 * make pg_depend entries for a new pg_ts_template entry
*/ */
static void static ObjectAddress
makeTSTemplateDependencies(HeapTuple tuple) makeTSTemplateDependencies(HeapTuple tuple)
{ {
Form_pg_ts_template tmpl = (Form_pg_ts_template) GETSTRUCT(tuple); Form_pg_ts_template tmpl = (Form_pg_ts_template) GETSTRUCT(tuple);
@ -710,12 +723,14 @@ makeTSTemplateDependencies(HeapTuple tuple)
referenced.objectId = tmpl->tmplinit; referenced.objectId = tmpl->tmplinit;
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL); recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
} }
return myself;
} }
/* /*
* CREATE TEXT SEARCH TEMPLATE * CREATE TEXT SEARCH TEMPLATE
*/ */
Oid ObjectAddress
DefineTSTemplate(List *names, List *parameters) DefineTSTemplate(List *names, List *parameters)
{ {
ListCell *pl; ListCell *pl;
@ -728,6 +743,7 @@ DefineTSTemplate(List *names, List *parameters)
Oid tmplOid; Oid tmplOid;
Oid namespaceoid; Oid namespaceoid;
char *tmplname; char *tmplname;
ObjectAddress address;
if (!superuser()) if (!superuser())
ereport(ERROR, ereport(ERROR,
@ -793,7 +809,7 @@ DefineTSTemplate(List *names, List *parameters)
CatalogUpdateIndexes(tmplRel, tup); CatalogUpdateIndexes(tmplRel, tup);
makeTSTemplateDependencies(tup); address = makeTSTemplateDependencies(tup);
/* Post creation hook for new text search template */ /* Post creation hook for new text search template */
InvokeObjectPostCreateHook(TSTemplateRelationId, tmplOid, 0); InvokeObjectPostCreateHook(TSTemplateRelationId, tmplOid, 0);
@ -802,7 +818,7 @@ DefineTSTemplate(List *names, List *parameters)
heap_close(tmplRel, RowExclusiveLock); 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 * Pass opened pg_ts_config_map relation if there might be any config map
* entries for the config. * entries for the config.
*/ */
static void static ObjectAddress
makeConfigurationDependencies(HeapTuple tuple, bool removeOld, makeConfigurationDependencies(HeapTuple tuple, bool removeOld,
Relation mapRel) Relation mapRel)
{ {
@ -940,12 +956,14 @@ makeConfigurationDependencies(HeapTuple tuple, bool removeOld,
record_object_address_dependencies(&myself, addrs, DEPENDENCY_NORMAL); record_object_address_dependencies(&myself, addrs, DEPENDENCY_NORMAL);
free_object_addresses(addrs); free_object_addresses(addrs);
return myself;
} }
/* /*
* CREATE TEXT SEARCH CONFIGURATION * CREATE TEXT SEARCH CONFIGURATION
*/ */
Oid ObjectAddress
DefineTSConfiguration(List *names, List *parameters) DefineTSConfiguration(List *names, List *parameters)
{ {
Relation cfgRel; Relation cfgRel;
@ -961,6 +979,7 @@ DefineTSConfiguration(List *names, List *parameters)
Oid prsOid = InvalidOid; Oid prsOid = InvalidOid;
Oid cfgOid; Oid cfgOid;
ListCell *pl; ListCell *pl;
ObjectAddress address;
/* Convert list of names to a name and namespace */ /* Convert list of names to a name and namespace */
namespaceoid = QualifiedNameGetCreationNamespace(names, &cfgname); namespaceoid = QualifiedNameGetCreationNamespace(names, &cfgname);
@ -1088,7 +1107,7 @@ DefineTSConfiguration(List *names, List *parameters)
systable_endscan(scan); systable_endscan(scan);
} }
makeConfigurationDependencies(tup, false, mapRel); address = makeConfigurationDependencies(tup, false, mapRel);
/* Post creation hook for new text search configuration */ /* Post creation hook for new text search configuration */
InvokeObjectPostCreateHook(TSConfigRelationId, cfgOid, 0); InvokeObjectPostCreateHook(TSConfigRelationId, cfgOid, 0);
@ -1099,7 +1118,7 @@ DefineTSConfiguration(List *names, List *parameters)
heap_close(mapRel, RowExclusiveLock); heap_close(mapRel, RowExclusiveLock);
heap_close(cfgRel, RowExclusiveLock); heap_close(cfgRel, RowExclusiveLock);
return cfgOid; return address;
} }
/* /*
@ -1153,12 +1172,13 @@ RemoveTSConfigurationById(Oid cfgId)
/* /*
* ALTER TEXT SEARCH CONFIGURATION - main entry point * ALTER TEXT SEARCH CONFIGURATION - main entry point
*/ */
Oid ObjectAddress
AlterTSConfiguration(AlterTSConfigurationStmt *stmt) AlterTSConfiguration(AlterTSConfigurationStmt *stmt)
{ {
HeapTuple tup; HeapTuple tup;
Oid cfgId; Oid cfgId;
Relation relMap; Relation relMap;
ObjectAddress address;
/* Find the configuration */ /* Find the configuration */
tup = GetTSConfigTuple(stmt->cfgname); tup = GetTSConfigTuple(stmt->cfgname);
@ -1189,11 +1209,13 @@ AlterTSConfiguration(AlterTSConfigurationStmt *stmt)
InvokeObjectPostAlterHook(TSConfigMapRelationId, InvokeObjectPostAlterHook(TSConfigMapRelationId,
HeapTupleGetOid(tup), 0); HeapTupleGetOid(tup), 0);
ObjectAddressSet(address, TSConfigMapRelationId, cfgId);
heap_close(relMap, RowExclusiveLock); heap_close(relMap, RowExclusiveLock);
ReleaseSysCache(tup); ReleaseSysCache(tup);
return cfgId; return address;
} }
/* /*

View File

@ -101,14 +101,14 @@ static void checkEnumOwner(HeapTuple tup);
static char *domainAddConstraint(Oid domainOid, Oid domainNamespace, static char *domainAddConstraint(Oid domainOid, Oid domainNamespace,
Oid baseTypeOid, Oid baseTypeOid,
int typMod, Constraint *constr, int typMod, Constraint *constr,
char *domainName); char *domainName, ObjectAddress *constrAddr);
/* /*
* DefineType * DefineType
* Registers a new base type. * Registers a new base type.
*/ */
Oid ObjectAddress
DefineType(List *names, List *parameters) DefineType(List *names, List *parameters)
{ {
char *typeName; char *typeName;
@ -160,6 +160,7 @@ DefineType(List *names, List *parameters)
Oid typoid; Oid typoid;
Oid resulttype; Oid resulttype;
ListCell *pl; ListCell *pl;
ObjectAddress address;
/* /*
* As of Postgres 8.4, we require superuser privilege to create a base * 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)) if (!OidIsValid(typoid))
{ {
typoid = TypeShellMake(typeName, typeNamespace, GetUserId()); address = TypeShellMake(typeName, typeNamespace, GetUserId());
/* Make new shell type visible for modification below */ /* Make new shell type visible for modification below */
CommandCounterIncrement(); CommandCounterIncrement();
@ -222,7 +223,7 @@ DefineType(List *names, List *parameters)
* creating the shell type was all we're supposed to do. * creating the shell type was all we're supposed to do.
*/ */
if (parameters == NIL) if (parameters == NIL)
return InvalidOid; return address;
} }
else else
{ {
@ -595,7 +596,7 @@ DefineType(List *names, List *parameters)
* types) in ArrayType and in composite types in DatumTupleFields. This * types) in ArrayType and in composite types in DatumTupleFields. This
* oid must be preserved by binary upgrades. * oid must be preserved by binary upgrades.
*/ */
typoid = address =
TypeCreate(InvalidOid, /* no predetermined type OID */ TypeCreate(InvalidOid, /* no predetermined type OID */
typeName, /* type name */ typeName, /* type name */
typeNamespace, /* namespace */ typeNamespace, /* namespace */
@ -670,7 +671,7 @@ DefineType(List *names, List *parameters)
pfree(array_type); pfree(array_type);
return typoid; return address;
} }
/* /*
@ -716,7 +717,7 @@ RemoveTypeById(Oid typeOid)
* DefineDomain * DefineDomain
* Registers a new domain. * Registers a new domain.
*/ */
Oid ObjectAddress
DefineDomain(CreateDomainStmt *stmt) DefineDomain(CreateDomainStmt *stmt)
{ {
char *domainName; char *domainName;
@ -746,12 +747,12 @@ DefineDomain(CreateDomainStmt *stmt)
List *schema = stmt->constraints; List *schema = stmt->constraints;
ListCell *listptr; ListCell *listptr;
Oid basetypeoid; Oid basetypeoid;
Oid domainoid;
Oid old_type_oid; Oid old_type_oid;
Oid domaincoll; Oid domaincoll;
Form_pg_type baseType; Form_pg_type baseType;
int32 basetypeMod; int32 basetypeMod;
Oid baseColl; Oid baseColl;
ObjectAddress address;
/* Convert list of names to a name and namespace */ /* Convert list of names to a name and namespace */
domainNamespace = QualifiedNameGetCreationNamespace(stmt->domainname, domainNamespace = QualifiedNameGetCreationNamespace(stmt->domainname,
@ -1021,7 +1022,7 @@ DefineDomain(CreateDomainStmt *stmt)
/* /*
* Have TypeCreate do all the real work. * Have TypeCreate do all the real work.
*/ */
domainoid = address =
TypeCreate(InvalidOid, /* no predetermined type OID */ TypeCreate(InvalidOid, /* no predetermined type OID */
domainName, /* type name */ domainName, /* type name */
domainNamespace, /* namespace */ domainNamespace, /* namespace */
@ -1066,9 +1067,9 @@ DefineDomain(CreateDomainStmt *stmt)
switch (constr->contype) switch (constr->contype)
{ {
case CONSTR_CHECK: case CONSTR_CHECK:
domainAddConstraint(domainoid, domainNamespace, domainAddConstraint(address.objectId, domainNamespace,
basetypeoid, basetypeMod, basetypeoid, basetypeMod,
constr, domainName); constr, domainName, NULL);
break; break;
/* Other constraint types were fully processed above */ /* Other constraint types were fully processed above */
@ -1086,7 +1087,7 @@ DefineDomain(CreateDomainStmt *stmt)
*/ */
ReleaseSysCache(typeTup); ReleaseSysCache(typeTup);
return domainoid; return address;
} }
@ -1094,16 +1095,16 @@ DefineDomain(CreateDomainStmt *stmt)
* DefineEnum * DefineEnum
* Registers a new enum. * Registers a new enum.
*/ */
Oid ObjectAddress
DefineEnum(CreateEnumStmt *stmt) DefineEnum(CreateEnumStmt *stmt)
{ {
char *enumName; char *enumName;
char *enumArrayName; char *enumArrayName;
Oid enumNamespace; Oid enumNamespace;
Oid enumTypeOid;
AclResult aclresult; AclResult aclresult;
Oid old_type_oid; Oid old_type_oid;
Oid enumArrayOid; Oid enumArrayOid;
ObjectAddress enumTypeAddr;
/* Convert list of names to a name and namespace */ /* Convert list of names to a name and namespace */
enumNamespace = QualifiedNameGetCreationNamespace(stmt->typeName, enumNamespace = QualifiedNameGetCreationNamespace(stmt->typeName,
@ -1133,7 +1134,7 @@ DefineEnum(CreateEnumStmt *stmt)
enumArrayOid = AssignTypeArrayOid(); enumArrayOid = AssignTypeArrayOid();
/* Create the pg_type entry */ /* Create the pg_type entry */
enumTypeOid = enumTypeAddr =
TypeCreate(InvalidOid, /* no predetermined type OID */ TypeCreate(InvalidOid, /* no predetermined type OID */
enumName, /* type name */ enumName, /* type name */
enumNamespace, /* namespace */ enumNamespace, /* namespace */
@ -1167,7 +1168,7 @@ DefineEnum(CreateEnumStmt *stmt)
InvalidOid); /* type's collation */ InvalidOid); /* type's collation */
/* Enter the enum's values into pg_enum */ /* 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. * Create the array type that goes with it.
@ -1192,7 +1193,7 @@ DefineEnum(CreateEnumStmt *stmt)
InvalidOid, /* typmodin procedure - none */ InvalidOid, /* typmodin procedure - none */
InvalidOid, /* typmodout procedure - none */ InvalidOid, /* typmodout procedure - none */
F_ARRAY_TYPANALYZE, /* analyze procedure */ F_ARRAY_TYPANALYZE, /* analyze procedure */
enumTypeOid, /* element type ID */ enumTypeAddr.objectId, /* element type ID */
true, /* yes this is an array type */ true, /* yes this is an array type */
InvalidOid, /* no further array type */ InvalidOid, /* no further array type */
InvalidOid, /* base type ID */ InvalidOid, /* base type ID */
@ -1208,19 +1209,20 @@ DefineEnum(CreateEnumStmt *stmt)
pfree(enumArrayName); pfree(enumArrayName);
return enumTypeOid; return enumTypeAddr;
} }
/* /*
* AlterEnum * AlterEnum
* Adds a new label to an existing enum. * Adds a new label to an existing enum.
*/ */
Oid ObjectAddress
AlterEnum(AlterEnumStmt *stmt, bool isTopLevel) AlterEnum(AlterEnumStmt *stmt, bool isTopLevel)
{ {
Oid enum_type_oid; Oid enum_type_oid;
TypeName *typename; TypeName *typename;
HeapTuple tup; HeapTuple tup;
ObjectAddress address;
/* Make a TypeName so we can use standard type lookup machinery */ /* Make a TypeName so we can use standard type lookup machinery */
typename = makeTypeNameFromNameList(stmt->typeName); typename = makeTypeNameFromNameList(stmt->typeName);
@ -1259,9 +1261,11 @@ AlterEnum(AlterEnumStmt *stmt, bool isTopLevel)
InvokeObjectPostAlterHook(TypeRelationId, enum_type_oid, 0); InvokeObjectPostAlterHook(TypeRelationId, enum_type_oid, 0);
ObjectAddressSet(address, TypeRelationId, enum_type_oid);
ReleaseSysCache(tup); ReleaseSysCache(tup);
return enum_type_oid; return address;
} }
@ -1293,7 +1297,7 @@ checkEnumOwner(HeapTuple tup)
* DefineRange * DefineRange
* Registers a new range type. * Registers a new range type.
*/ */
Oid ObjectAddress
DefineRange(CreateRangeStmt *stmt) DefineRange(CreateRangeStmt *stmt)
{ {
char *typeName; char *typeName;
@ -1316,6 +1320,7 @@ DefineRange(CreateRangeStmt *stmt)
char alignment; char alignment;
AclResult aclresult; AclResult aclresult;
ListCell *lc; ListCell *lc;
ObjectAddress address;
/* Convert list of names to a name and namespace */ /* Convert list of names to a name and namespace */
typeNamespace = QualifiedNameGetCreationNamespace(stmt->typeName, typeNamespace = QualifiedNameGetCreationNamespace(stmt->typeName,
@ -1354,7 +1359,8 @@ DefineRange(CreateRangeStmt *stmt)
*/ */
if (!OidIsValid(typoid)) if (!OidIsValid(typoid))
{ {
typoid = TypeShellMake(typeName, typeNamespace, GetUserId()); address = TypeShellMake(typeName, typeNamespace, GetUserId());
typoid = address.objectId;
/* Make new shell type visible for modification below */ /* Make new shell type visible for modification below */
CommandCounterIncrement(); CommandCounterIncrement();
} }
@ -1467,7 +1473,7 @@ DefineRange(CreateRangeStmt *stmt)
rangeArrayOid = AssignTypeArrayOid(); rangeArrayOid = AssignTypeArrayOid();
/* Create the pg_type entry */ /* Create the pg_type entry */
typoid = address =
TypeCreate(InvalidOid, /* no predetermined type OID */ TypeCreate(InvalidOid, /* no predetermined type OID */
typeName, /* type name */ typeName, /* type name */
typeNamespace, /* namespace */ typeNamespace, /* namespace */
@ -1499,6 +1505,7 @@ DefineRange(CreateRangeStmt *stmt)
0, /* Array dimensions of typbasetype */ 0, /* Array dimensions of typbasetype */
false, /* Type NOT NULL */ false, /* Type NOT NULL */
InvalidOid); /* type's collation (ranges never have one) */ InvalidOid); /* type's collation (ranges never have one) */
typoid = address.objectId;
/* Create the entry in pg_range */ /* Create the entry in pg_range */
RangeCreate(typoid, rangeSubtype, rangeCollation, rangeSubOpclass, RangeCreate(typoid, rangeSubtype, rangeCollation, rangeSubOpclass,
@ -1546,7 +1553,7 @@ DefineRange(CreateRangeStmt *stmt)
/* And create the constructor functions for this range type */ /* And create the constructor functions for this range type */
makeRangeConstructors(typeName, typeNamespace, typoid, rangeSubtype); 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++) for (i = 0; i < lengthof(prosrc); i++)
{ {
oidvector *constructorArgTypesVector; oidvector *constructorArgTypesVector;
Oid procOid;
constructorArgTypesVector = buildoidvector(constructorArgTypes, constructorArgTypesVector = buildoidvector(constructorArgTypes,
pronargs[i]); pronargs[i]);
procOid = ProcedureCreate(name, /* name: same as range type */ myself = ProcedureCreate(name, /* name: same as range type */
namespace, /* namespace */ namespace, /* namespace */
false, /* replace */ false, /* replace */
false, /* returns set */ false, /* returns set */
rangeOid, /* return type */ rangeOid, /* return type */
BOOTSTRAP_SUPERUSERID, /* proowner */ BOOTSTRAP_SUPERUSERID, /* proowner */
INTERNALlanguageId, /* language */ INTERNALlanguageId, /* language */
F_FMGR_INTERNAL_VALIDATOR, /* language validator */ F_FMGR_INTERNAL_VALIDATOR, /* language validator */
prosrc[i], /* prosrc */ prosrc[i], /* prosrc */
NULL, /* probin */ NULL, /* probin */
false, /* isAgg */ false, /* isAgg */
false, /* isWindowFunc */ false, /* isWindowFunc */
false, /* security_definer */ false, /* security_definer */
false, /* leakproof */ false, /* leakproof */
false, /* isStrict */ false, /* isStrict */
PROVOLATILE_IMMUTABLE, /* volatility */ PROVOLATILE_IMMUTABLE, /* volatility */
constructorArgTypesVector, /* parameterTypes */ constructorArgTypesVector, /* parameterTypes */
PointerGetDatum(NULL), /* allParameterTypes */ PointerGetDatum(NULL), /* allParameterTypes */
PointerGetDatum(NULL), /* parameterModes */ PointerGetDatum(NULL), /* parameterModes */
PointerGetDatum(NULL), /* parameterNames */ PointerGetDatum(NULL), /* parameterNames */
NIL, /* parameterDefaults */ NIL, /* parameterDefaults */
PointerGetDatum(NULL), /* proconfig */ PointerGetDatum(NULL), /* proconfig */
1.0, /* procost */ 1.0, /* procost */
0.0); /* prorows */ 0.0); /* prorows */
/* /*
* Make the constructors internally-dependent on the range type so * Make the constructors internally-dependent on the range type so
* that they go away silently when the type is dropped. Note that * that they go away silently when the type is dropped. Note that
* pg_dump depends on this choice to avoid dumping the constructors. * 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); recordDependencyOn(&myself, &referenced, DEPENDENCY_INTERNAL);
} }
} }
@ -2059,17 +2061,16 @@ AssignTypeArrayOid(void)
* If the relation already exists, then 'DefineRelation' will abort * If the relation already exists, then 'DefineRelation' will abort
* the xact... * the xact...
* *
* DefineCompositeType returns relid for use when creating * Return type is the new type's object address.
* an implicit composite type during function creation
*------------------------------------------------------------------- *-------------------------------------------------------------------
*/ */
Oid ObjectAddress
DefineCompositeType(RangeVar *typevar, List *coldeflist) DefineCompositeType(RangeVar *typevar, List *coldeflist)
{ {
CreateStmt *createStmt = makeNode(CreateStmt); CreateStmt *createStmt = makeNode(CreateStmt);
Oid old_type_oid; Oid old_type_oid;
Oid typeNamespace; Oid typeNamespace;
Oid relid; ObjectAddress address;
/* /*
* now set the parameters for keys/inheritance etc. All of these are * 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. * Finally create the relation. This also creates the type.
*/ */
relid = DefineRelation(createStmt, RELKIND_COMPOSITE_TYPE, InvalidOid); DefineRelation(createStmt, RELKIND_COMPOSITE_TYPE, InvalidOid, &address);
Assert(relid != InvalidOid);
return relid; return address;
} }
/* /*
* AlterDomainDefault * AlterDomainDefault
* *
* Routine implementing ALTER DOMAIN SET/DROP DEFAULT statements. * Routine implementing ALTER DOMAIN SET/DROP DEFAULT statements.
*
* Returns ObjectAddress of the modified domain.
*/ */
Oid ObjectAddress
AlterDomainDefault(List *names, Node *defaultRaw) AlterDomainDefault(List *names, Node *defaultRaw)
{ {
TypeName *typename; TypeName *typename;
@ -2133,6 +2136,7 @@ AlterDomainDefault(List *names, Node *defaultRaw)
bool new_record_repl[Natts_pg_type]; bool new_record_repl[Natts_pg_type];
HeapTuple newtuple; HeapTuple newtuple;
Form_pg_type typTup; Form_pg_type typTup;
ObjectAddress address;
/* Make a TypeName so we can use standard type lookup machinery */ /* Make a TypeName so we can use standard type lookup machinery */
typename = makeTypeNameFromNameList(names); typename = makeTypeNameFromNameList(names);
@ -2242,19 +2246,23 @@ AlterDomainDefault(List *names, Node *defaultRaw)
InvokeObjectPostAlterHook(TypeRelationId, domainoid, 0); InvokeObjectPostAlterHook(TypeRelationId, domainoid, 0);
ObjectAddressSet(address, TypeRelationId, domainoid);
/* Clean up */ /* Clean up */
heap_close(rel, NoLock); heap_close(rel, NoLock);
heap_freetuple(newtuple); heap_freetuple(newtuple);
return domainoid; return address;
} }
/* /*
* AlterDomainNotNull * AlterDomainNotNull
* *
* Routine implementing ALTER DOMAIN SET/DROP NOT NULL statements. * Routine implementing ALTER DOMAIN SET/DROP NOT NULL statements.
*
* Returns ObjectAddress of the modified domain.
*/ */
Oid ObjectAddress
AlterDomainNotNull(List *names, bool notNull) AlterDomainNotNull(List *names, bool notNull)
{ {
TypeName *typename; TypeName *typename;
@ -2262,6 +2270,7 @@ AlterDomainNotNull(List *names, bool notNull)
Relation typrel; Relation typrel;
HeapTuple tup; HeapTuple tup;
Form_pg_type typTup; Form_pg_type typTup;
ObjectAddress address = InvalidObjectAddress;
/* Make a TypeName so we can use standard type lookup machinery */ /* Make a TypeName so we can use standard type lookup machinery */
typename = makeTypeNameFromNameList(names); typename = makeTypeNameFromNameList(names);
@ -2282,7 +2291,7 @@ AlterDomainNotNull(List *names, bool notNull)
if (typTup->typnotnull == notNull) if (typTup->typnotnull == notNull)
{ {
heap_close(typrel, RowExclusiveLock); heap_close(typrel, RowExclusiveLock);
return InvalidOid; return address;
} }
/* Adding a NOT NULL constraint requires checking existing columns */ /* Adding a NOT NULL constraint requires checking existing columns */
@ -2356,11 +2365,13 @@ AlterDomainNotNull(List *names, bool notNull)
InvokeObjectPostAlterHook(TypeRelationId, domainoid, 0); InvokeObjectPostAlterHook(TypeRelationId, domainoid, 0);
ObjectAddressSet(address, TypeRelationId, domainoid);
/* Clean up */ /* Clean up */
heap_freetuple(tup); heap_freetuple(tup);
heap_close(typrel, RowExclusiveLock); heap_close(typrel, RowExclusiveLock);
return domainoid; return address;
} }
/* /*
@ -2368,7 +2379,7 @@ AlterDomainNotNull(List *names, bool notNull)
* *
* Implements the ALTER DOMAIN DROP CONSTRAINT statement * Implements the ALTER DOMAIN DROP CONSTRAINT statement
*/ */
Oid ObjectAddress
AlterDomainDropConstraint(List *names, const char *constrName, AlterDomainDropConstraint(List *names, const char *constrName,
DropBehavior behavior, bool missing_ok) DropBehavior behavior, bool missing_ok)
{ {
@ -2381,6 +2392,7 @@ AlterDomainDropConstraint(List *names, const char *constrName,
ScanKeyData key[1]; ScanKeyData key[1];
HeapTuple contup; HeapTuple contup;
bool found = false; bool found = false;
ObjectAddress address = InvalidObjectAddress;
/* Make a TypeName so we can use standard type lookup machinery */ /* Make a TypeName so we can use standard type lookup machinery */
typename = makeTypeNameFromNameList(names); typename = makeTypeNameFromNameList(names);
@ -2427,6 +2439,9 @@ AlterDomainDropConstraint(List *names, const char *constrName,
found = true; found = true;
} }
} }
ObjectAddressSet(address, TypeRelationId, domainoid);
/* Clean up after the scan */ /* Clean up after the scan */
systable_endscan(conscan); systable_endscan(conscan);
heap_close(conrel, RowExclusiveLock); heap_close(conrel, RowExclusiveLock);
@ -2446,7 +2461,7 @@ AlterDomainDropConstraint(List *names, const char *constrName,
constrName, TypeNameToString(typename)))); constrName, TypeNameToString(typename))));
} }
return domainoid; return address;
} }
/* /*
@ -2454,8 +2469,9 @@ AlterDomainDropConstraint(List *names, const char *constrName,
* *
* Implements the ALTER DOMAIN .. ADD CONSTRAINT statement. * Implements the ALTER DOMAIN .. ADD CONSTRAINT statement.
*/ */
Oid ObjectAddress
AlterDomainAddConstraint(List *names, Node *newConstraint) AlterDomainAddConstraint(List *names, Node *newConstraint,
ObjectAddress *constrAddr)
{ {
TypeName *typename; TypeName *typename;
Oid domainoid; Oid domainoid;
@ -2464,6 +2480,7 @@ AlterDomainAddConstraint(List *names, Node *newConstraint)
Form_pg_type typTup; Form_pg_type typTup;
Constraint *constr; Constraint *constr;
char *ccbin; char *ccbin;
ObjectAddress address;
/* Make a TypeName so we can use standard type lookup machinery */ /* Make a TypeName so we can use standard type lookup machinery */
typename = makeTypeNameFromNameList(names); typename = makeTypeNameFromNameList(names);
@ -2539,7 +2556,7 @@ AlterDomainAddConstraint(List *names, Node *newConstraint)
ccbin = domainAddConstraint(domainoid, typTup->typnamespace, ccbin = domainAddConstraint(domainoid, typTup->typnamespace,
typTup->typbasetype, typTup->typtypmod, typTup->typbasetype, typTup->typtypmod,
constr, NameStr(typTup->typname)); constr, NameStr(typTup->typname), constrAddr);
/* /*
* If requested to validate the constraint, test all values stored in the * If requested to validate the constraint, test all values stored in the
@ -2548,10 +2565,12 @@ AlterDomainAddConstraint(List *names, Node *newConstraint)
if (!constr->skip_validation) if (!constr->skip_validation)
validateDomainConstraint(domainoid, ccbin); validateDomainConstraint(domainoid, ccbin);
ObjectAddressSet(address, TypeRelationId, domainoid);
/* Clean up */ /* Clean up */
heap_close(typrel, RowExclusiveLock); heap_close(typrel, RowExclusiveLock);
return domainoid; return address;
} }
/* /*
@ -2559,7 +2578,7 @@ AlterDomainAddConstraint(List *names, Node *newConstraint)
* *
* Implements the ALTER DOMAIN .. VALIDATE CONSTRAINT statement. * Implements the ALTER DOMAIN .. VALIDATE CONSTRAINT statement.
*/ */
Oid ObjectAddress
AlterDomainValidateConstraint(List *names, char *constrName) AlterDomainValidateConstraint(List *names, char *constrName)
{ {
TypeName *typename; TypeName *typename;
@ -2577,6 +2596,7 @@ AlterDomainValidateConstraint(List *names, char *constrName)
HeapTuple tuple; HeapTuple tuple;
HeapTuple copyTuple; HeapTuple copyTuple;
ScanKeyData key; ScanKeyData key;
ObjectAddress address;
/* Make a TypeName so we can use standard type lookup machinery */ /* Make a TypeName so we can use standard type lookup machinery */
typename = makeTypeNameFromNameList(names); typename = makeTypeNameFromNameList(names);
@ -2647,6 +2667,8 @@ AlterDomainValidateConstraint(List *names, char *constrName)
InvokeObjectPostAlterHook(ConstraintRelationId, InvokeObjectPostAlterHook(ConstraintRelationId,
HeapTupleGetOid(copyTuple), 0); HeapTupleGetOid(copyTuple), 0);
ObjectAddressSet(address, TypeRelationId, domainoid);
heap_freetuple(copyTuple); heap_freetuple(copyTuple);
systable_endscan(scan); systable_endscan(scan);
@ -2656,7 +2678,7 @@ AlterDomainValidateConstraint(List *names, char *constrName)
ReleaseSysCache(tup); ReleaseSysCache(tup);
return domainoid; return address;
} }
static void static void
@ -2953,13 +2975,14 @@ checkDomainOwner(HeapTuple tup)
static char * static char *
domainAddConstraint(Oid domainOid, Oid domainNamespace, Oid baseTypeOid, domainAddConstraint(Oid domainOid, Oid domainNamespace, Oid baseTypeOid,
int typMod, Constraint *constr, int typMod, Constraint *constr,
char *domainName) char *domainName, ObjectAddress *constrAddr)
{ {
Node *expr; Node *expr;
char *ccsrc; char *ccsrc;
char *ccbin; char *ccbin;
ParseState *pstate; ParseState *pstate;
CoerceToDomainValue *domVal; CoerceToDomainValue *domVal;
Oid ccoid;
/* /*
* Assign or validate constraint name * Assign or validate constraint name
@ -3038,34 +3061,37 @@ domainAddConstraint(Oid domainOid, Oid domainNamespace, Oid baseTypeOid,
/* /*
* Store the constraint in pg_constraint * Store the constraint in pg_constraint
*/ */
CreateConstraintEntry(constr->conname, /* Constraint Name */ ccoid =
domainNamespace, /* namespace */ CreateConstraintEntry(constr->conname, /* Constraint Name */
CONSTRAINT_CHECK, /* Constraint Type */ domainNamespace, /* namespace */
false, /* Is Deferrable */ CONSTRAINT_CHECK, /* Constraint Type */
false, /* Is Deferred */ false, /* Is Deferrable */
!constr->skip_validation, /* Is Validated */ false, /* Is Deferred */
InvalidOid, /* not a relation constraint */ !constr->skip_validation, /* Is Validated */
NULL, InvalidOid, /* not a relation constraint */
0, NULL,
domainOid, /* domain constraint */ 0,
InvalidOid, /* no associated index */ domainOid, /* domain constraint */
InvalidOid, /* Foreign key fields */ InvalidOid, /* no associated index */
NULL, InvalidOid, /* Foreign key fields */
NULL, NULL,
NULL, NULL,
NULL, NULL,
0, NULL,
' ', 0,
' ', ' ',
' ', ' ',
NULL, /* not an exclusion constraint */ ' ',
expr, /* Tree form of check constraint */ NULL, /* not an exclusion constraint */
ccbin, /* Binary form of check constraint */ expr, /* Tree form of check constraint */
ccsrc, /* Source form of check constraint */ ccbin, /* Binary form of check constraint */
true, /* is local */ ccsrc, /* Source form of check constraint */
0, /* inhcount */ true, /* is local */
false, /* connoinherit */ 0, /* inhcount */
false); /* is_internal */ false, /* connoinherit */
false); /* is_internal */
if (constrAddr)
ObjectAddressSet(*constrAddr, ConstraintRelationId, ccoid);
/* /*
* Return the compiled constraint expression so the calling routine can * 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 * Execute ALTER TYPE RENAME
*/ */
Oid ObjectAddress
RenameType(RenameStmt *stmt) RenameType(RenameStmt *stmt)
{ {
List *names = stmt->object; List *names = stmt->object;
@ -3088,6 +3114,7 @@ RenameType(RenameStmt *stmt)
Relation rel; Relation rel;
HeapTuple tup; HeapTuple tup;
Form_pg_type typTup; Form_pg_type typTup;
ObjectAddress address;
/* Make a TypeName so we can use standard type lookup machinery */ /* Make a TypeName so we can use standard type lookup machinery */
typename = makeTypeNameFromNameList(names); typename = makeTypeNameFromNameList(names);
@ -3145,16 +3172,17 @@ RenameType(RenameStmt *stmt)
RenameTypeInternal(typeOid, newTypeName, RenameTypeInternal(typeOid, newTypeName,
typTup->typnamespace); typTup->typnamespace);
ObjectAddressSet(address, TypeRelationId, typeOid);
/* Clean up */ /* Clean up */
heap_close(rel, RowExclusiveLock); heap_close(rel, RowExclusiveLock);
return typeOid; return address;
} }
/* /*
* Change the owner of a type. * Change the owner of a type.
*/ */
Oid ObjectAddress
AlterTypeOwner(List *names, Oid newOwnerId, ObjectType objecttype) AlterTypeOwner(List *names, Oid newOwnerId, ObjectType objecttype)
{ {
TypeName *typename; TypeName *typename;
@ -3164,6 +3192,7 @@ AlterTypeOwner(List *names, Oid newOwnerId, ObjectType objecttype)
HeapTuple newtup; HeapTuple newtup;
Form_pg_type typTup; Form_pg_type typTup;
AclResult aclresult; AclResult aclresult;
ObjectAddress address;
rel = heap_open(TypeRelationId, RowExclusiveLock); rel = heap_open(TypeRelationId, RowExclusiveLock);
@ -3293,10 +3322,12 @@ AlterTypeOwner(List *names, Oid newOwnerId, ObjectType objecttype)
} }
} }
ObjectAddressSet(address, TypeRelationId, typeOid);
/* Clean up */ /* Clean up */
heap_close(rel, RowExclusiveLock); heap_close(rel, RowExclusiveLock);
return typeOid; return address;
} }
/* /*
@ -3376,13 +3407,16 @@ AlterTypeOwnerInternal(Oid typeOid, Oid newOwnerId,
/* /*
* Execute ALTER TYPE SET SCHEMA * Execute ALTER TYPE SET SCHEMA
*/ */
Oid ObjectAddress
AlterTypeNamespace(List *names, const char *newschema, ObjectType objecttype) AlterTypeNamespace(List *names, const char *newschema, ObjectType objecttype,
Oid *oldschema)
{ {
TypeName *typename; TypeName *typename;
Oid typeOid; Oid typeOid;
Oid nspOid; Oid nspOid;
Oid oldNspOid;
ObjectAddresses *objsMoved; ObjectAddresses *objsMoved;
ObjectAddress myself;
/* Make a TypeName so we can use standard type lookup machinery */ /* Make a TypeName so we can use standard type lookup machinery */
typename = makeTypeNameFromNameList(names); typename = makeTypeNameFromNameList(names);
@ -3399,10 +3433,15 @@ AlterTypeNamespace(List *names, const char *newschema, ObjectType objecttype)
nspOid = LookupCreationNamespace(newschema); nspOid = LookupCreationNamespace(newschema);
objsMoved = new_object_addresses(); objsMoved = new_object_addresses();
AlterTypeNamespace_oid(typeOid, nspOid, objsMoved); oldNspOid = AlterTypeNamespace_oid(typeOid, nspOid, objsMoved);
free_object_addresses(objsMoved); free_object_addresses(objsMoved);
return typeOid; if (oldschema)
*oldschema = oldNspOid;
ObjectAddressSet(myself, TypeRelationId, typeOid);
return myself;
} }
Oid Oid

View File

@ -1114,7 +1114,7 @@ DropRole(DropRoleStmt *stmt)
/* /*
* Rename role * Rename role
*/ */
Oid ObjectAddress
RenameRole(const char *oldname, const char *newname) RenameRole(const char *oldname, const char *newname)
{ {
HeapTuple oldtuple, HeapTuple oldtuple,
@ -1128,6 +1128,7 @@ RenameRole(const char *oldname, const char *newname)
bool repl_repl[Natts_pg_authid]; bool repl_repl[Natts_pg_authid];
int i; int i;
Oid roleid; Oid roleid;
ObjectAddress address;
rel = heap_open(AuthIdRelationId, RowExclusiveLock); rel = heap_open(AuthIdRelationId, RowExclusiveLock);
dsc = RelationGetDescr(rel); dsc = RelationGetDescr(rel);
@ -1216,6 +1217,8 @@ RenameRole(const char *oldname, const char *newname)
InvokeObjectPostAlterHook(AuthIdRelationId, roleid, 0); InvokeObjectPostAlterHook(AuthIdRelationId, roleid, 0);
ObjectAddressSet(address, AuthIdRelationId, roleid);
ReleaseSysCache(oldtuple); ReleaseSysCache(oldtuple);
/* /*
@ -1223,7 +1226,7 @@ RenameRole(const char *oldname, const char *newname)
*/ */
heap_close(rel, NoLock); heap_close(rel, NoLock);
return roleid; return address;
} }
/* /*

View File

@ -65,7 +65,7 @@ validateWithCheckOption(char *value)
* work harder. * work harder.
*--------------------------------------------------------------------- *---------------------------------------------------------------------
*/ */
static Oid static ObjectAddress
DefineVirtualRelation(RangeVar *relation, List *tlist, bool replace, DefineVirtualRelation(RangeVar *relation, List *tlist, bool replace,
List *options) List *options)
{ {
@ -143,6 +143,7 @@ DefineVirtualRelation(RangeVar *relation, List *tlist, bool replace,
TupleDesc descriptor; TupleDesc descriptor;
List *atcmds = NIL; List *atcmds = NIL;
AlterTableCmd *atcmd; AlterTableCmd *atcmd;
ObjectAddress address;
/* Relation is already locked, but we must build a relcache entry. */ /* Relation is already locked, but we must build a relcache entry. */
rel = relation_open(viewOid, NoLock); rel = relation_open(viewOid, NoLock);
@ -208,16 +209,18 @@ DefineVirtualRelation(RangeVar *relation, List *tlist, bool replace,
/* OK, let's do it. */ /* OK, let's do it. */
AlterTableInternal(viewOid, atcmds, true); AlterTableInternal(viewOid, atcmds, true);
ObjectAddressSet(address, RelationRelationId, viewOid);
/* /*
* Seems okay, so return the OID of the pre-existing view. * Seems okay, so return the OID of the pre-existing view.
*/ */
relation_close(rel, NoLock); /* keep the lock! */ relation_close(rel, NoLock); /* keep the lock! */
return viewOid; return address;
} }
else else
{ {
Oid relid; ObjectAddress address;
/* /*
* now set the parameters for keys/inheritance etc. All of these are * 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" * existing view, so we don't need more code to complain if "replace"
* is false). * is false).
*/ */
relid = DefineRelation(createStmt, RELKIND_VIEW, InvalidOid); address = DefineRelation(createStmt, RELKIND_VIEW, InvalidOid, NULL);
Assert(relid != InvalidOid); Assert(address.objectId != InvalidOid);
return relid; return address;
} }
} }
@ -388,14 +391,14 @@ UpdateRangeTableOfViewParse(Oid viewOid, Query *viewParse)
* DefineView * DefineView
* Execute a CREATE VIEW command. * Execute a CREATE VIEW command.
*/ */
Oid ObjectAddress
DefineView(ViewStmt *stmt, const char *queryString) DefineView(ViewStmt *stmt, const char *queryString)
{ {
Query *viewParse; Query *viewParse;
Oid viewOid;
RangeVar *view; RangeVar *view;
ListCell *cell; ListCell *cell;
bool check_option; bool check_option;
ObjectAddress address;
/* /*
* Run parse analysis to convert the raw parse tree to a Query. Note this * 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 * NOTE: if it already exists and replace is false, the xact will be
* aborted. * aborted.
*/ */
viewOid = DefineVirtualRelation(view, viewParse->targetList, address = DefineVirtualRelation(view, viewParse->targetList,
stmt->replace, stmt->options); stmt->replace, stmt->options);
/* /*
@ -543,9 +546,9 @@ DefineView(ViewStmt *stmt, const char *queryString)
*/ */
CommandCounterIncrement(); CommandCounterIncrement();
StoreViewQuery(viewOid, viewParse, stmt->replace); StoreViewQuery(address.objectId, viewParse, stmt->replace);
return viewOid; return address;
} }
/* /*

View File

@ -191,7 +191,7 @@ InsertRule(char *rulname,
* DefineRule * DefineRule
* Execute a CREATE RULE command. * Execute a CREATE RULE command.
*/ */
Oid ObjectAddress
DefineRule(RuleStmt *stmt, const char *queryString) DefineRule(RuleStmt *stmt, const char *queryString)
{ {
List *actions; List *actions;
@ -225,7 +225,7 @@ DefineRule(RuleStmt *stmt, const char *queryString)
* This is essentially the same as DefineRule() except that the rule's * This is essentially the same as DefineRule() except that the rule's
* action and qual have already been passed through parse analysis. * action and qual have already been passed through parse analysis.
*/ */
Oid ObjectAddress
DefineQueryRewrite(char *rulename, DefineQueryRewrite(char *rulename,
Oid event_relid, Oid event_relid,
Node *event_qual, Node *event_qual,
@ -239,6 +239,7 @@ DefineQueryRewrite(char *rulename,
Query *query; Query *query;
bool RelisBecomingView = false; bool RelisBecomingView = false;
Oid ruleId = InvalidOid; Oid ruleId = InvalidOid;
ObjectAddress address;
/* /*
* If we are installing an ON SELECT rule, we had better grab * If we are installing an ON SELECT rule, we had better grab
@ -604,10 +605,12 @@ DefineQueryRewrite(char *rulename,
heap_close(relationRelation, RowExclusiveLock); heap_close(relationRelation, RowExclusiveLock);
} }
ObjectAddressSet(address, RewriteRelationId, ruleId);
/* Close rel, but keep lock till commit... */ /* Close rel, but keep lock till commit... */
heap_close(event_relation, NoLock); 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. * Rename an existing rewrite rule.
*/ */
Oid ObjectAddress
RenameRewriteRule(RangeVar *relation, const char *oldName, RenameRewriteRule(RangeVar *relation, const char *oldName,
const char *newName) const char *newName)
{ {
@ -907,6 +910,7 @@ RenameRewriteRule(RangeVar *relation, const char *oldName,
HeapTuple ruletup; HeapTuple ruletup;
Form_pg_rewrite ruleform; Form_pg_rewrite ruleform;
Oid ruleOid; Oid ruleOid;
ObjectAddress address;
/* /*
* Look up name, check permissions, and acquire lock (which we will NOT * Look up name, check permissions, and acquire lock (which we will NOT
@ -969,10 +973,12 @@ RenameRewriteRule(RangeVar *relation, const char *oldName,
*/ */
CacheInvalidateRelcache(targetrel); CacheInvalidateRelcache(targetrel);
ObjectAddressSet(address, RewriteRelationId, ruleOid);
/* /*
* Close rel, but keep exclusive lock! * Close rel, but keep exclusive lock!
*/ */
relation_close(targetrel, NoLock); relation_close(targetrel, NoLock);
return ruleOid; return address;
} }

View File

@ -818,7 +818,7 @@ standard_ProcessUtility(Node *parsetree,
context, params, context, params,
dest, completionTag); dest, completionTag);
else else
ExecAlterObjectSchemaStmt(stmt); ExecAlterObjectSchemaStmt(stmt, NULL);
} }
break; break;
@ -886,6 +886,7 @@ ProcessUtilitySlow(Node *parsetree,
bool isTopLevel = (context == PROCESS_UTILITY_TOPLEVEL); bool isTopLevel = (context == PROCESS_UTILITY_TOPLEVEL);
bool isCompleteQuery = (context <= PROCESS_UTILITY_QUERY); bool isCompleteQuery = (context <= PROCESS_UTILITY_QUERY);
bool needCleanup; bool needCleanup;
ObjectAddress address;
/* All event trigger calls are done only when isCompleteQuery is true */ /* All event trigger calls are done only when isCompleteQuery is true */
needCleanup = isCompleteQuery && EventTriggerBeginCompleteQuery(); needCleanup = isCompleteQuery && EventTriggerBeginCompleteQuery();
@ -911,7 +912,6 @@ ProcessUtilitySlow(Node *parsetree,
{ {
List *stmts; List *stmts;
ListCell *l; ListCell *l;
Oid relOid;
/* Run parse analysis ... */ /* Run parse analysis ... */
stmts = transformCreateStmt((CreateStmt *) parsetree, stmts = transformCreateStmt((CreateStmt *) parsetree,
@ -928,9 +928,9 @@ ProcessUtilitySlow(Node *parsetree,
static char *validnsps[] = HEAP_RELOPT_NAMESPACES; static char *validnsps[] = HEAP_RELOPT_NAMESPACES;
/* Create the table itself */ /* Create the table itself */
relOid = DefineRelation((CreateStmt *) stmt, address = DefineRelation((CreateStmt *) stmt,
RELKIND_RELATION, RELKIND_RELATION,
InvalidOid); InvalidOid, NULL);
/* /*
* Let NewRelationCreateToastTable decide if this * Let NewRelationCreateToastTable decide if this
@ -952,16 +952,17 @@ ProcessUtilitySlow(Node *parsetree,
toast_options, toast_options,
true); true);
NewRelationCreateToastTable(relOid, toast_options); NewRelationCreateToastTable(address.objectId,
toast_options);
} }
else if (IsA(stmt, CreateForeignTableStmt)) else if (IsA(stmt, CreateForeignTableStmt))
{ {
/* Create the table itself */ /* Create the table itself */
relOid = DefineRelation((CreateStmt *) stmt, address = DefineRelation((CreateStmt *) stmt,
RELKIND_FOREIGN_TABLE, RELKIND_FOREIGN_TABLE,
InvalidOid); InvalidOid, NULL);
CreateForeignTable((CreateForeignTableStmt *) stmt, CreateForeignTable((CreateForeignTableStmt *) stmt,
relOid); address.objectId);
} }
else else
{ {
@ -1067,7 +1068,8 @@ ProcessUtilitySlow(Node *parsetree,
break; break;
case 'C': /* ADD CONSTRAINT */ case 'C': /* ADD CONSTRAINT */
AlterDomainAddConstraint(stmt->typeName, AlterDomainAddConstraint(stmt->typeName,
stmt->def); stmt->def,
NULL);
break; break;
case 'X': /* DROP CONSTRAINT */ case 'X': /* DROP CONSTRAINT */
AlterDomainDropConstraint(stmt->typeName, AlterDomainDropConstraint(stmt->typeName,
@ -1190,7 +1192,8 @@ ProcessUtilitySlow(Node *parsetree,
break; break;
case T_AlterExtensionContentsStmt: case T_AlterExtensionContentsStmt:
ExecAlterExtensionContentsStmt((AlterExtensionContentsStmt *) parsetree); ExecAlterExtensionContentsStmt((AlterExtensionContentsStmt *) parsetree,
NULL);
break; break;
case T_CreateFdwStmt: case T_CreateFdwStmt:
@ -1334,7 +1337,8 @@ ProcessUtilitySlow(Node *parsetree,
break; break;
case T_AlterObjectSchemaStmt: case T_AlterObjectSchemaStmt:
ExecAlterObjectSchemaStmt((AlterObjectSchemaStmt *) parsetree); ExecAlterObjectSchemaStmt((AlterObjectSchemaStmt *) parsetree,
NULL);
break; break;
case T_AlterOwnerStmt: case T_AlterOwnerStmt:

View File

@ -14,8 +14,9 @@
#ifndef HEAP_H #ifndef HEAP_H
#define HEAP_H #define HEAP_H
#include "parser/parse_node.h"
#include "catalog/indexing.h" #include "catalog/indexing.h"
#include "catalog/objectaddress.h"
#include "parser/parse_node.h"
typedef struct RawColumnDefault typedef struct RawColumnDefault
@ -68,7 +69,8 @@ extern Oid heap_create_with_catalog(const char *relname,
Datum reloptions, Datum reloptions,
bool use_user_acl, bool use_user_acl,
bool allow_system_table_mods, bool allow_system_table_mods,
bool is_internal); bool is_internal,
ObjectAddress *typaddress);
extern void heap_create_init_fork(Relation rel); extern void heap_create_init_fork(Relation rel);

View File

@ -28,6 +28,18 @@ typedef struct ObjectAddress
int32 objectSubId; /* Subitem within object (eg column), or 0 */ int32 objectSubId; /* Subitem within object (eg column), or 0 */
} ObjectAddress; } 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, extern ObjectAddress get_object_address(ObjectType objtype, List *objname,
List *objargs, Relation *relp, List *objargs, Relation *relp,
LOCKMODE lockmode, bool missing_ok); LOCKMODE lockmode, bool missing_ok);

View File

@ -20,6 +20,7 @@
#define PG_AGGREGATE_H #define PG_AGGREGATE_H
#include "catalog/genbki.h" #include "catalog/genbki.h"
#include "catalog/objectaddress.h"
#include "nodes/pg_list.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 * prototypes for functions in pg_aggregate.c
*/ */
extern Oid AggregateCreate(const char *aggName, extern ObjectAddress AggregateCreate(const char *aggName,
Oid aggNamespace, Oid aggNamespace,
char aggKind, char aggKind,
int numArgs, int numArgs,

View File

@ -14,7 +14,10 @@
#ifndef PG_CONVERSION_FN_H #ifndef PG_CONVERSION_FN_H
#define 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, Oid conowner,
int32 conforencoding, int32 contoencoding, int32 conforencoding, int32 contoencoding,
Oid conproc, bool def); Oid conproc, bool def);

View File

@ -23,6 +23,7 @@
#define PG_OPERATOR_H #define PG_OPERATOR_H
#include "catalog/genbki.h" #include "catalog/genbki.h"
#include "catalog/objectaddress.h"
#include "nodes/pg_list.h" #include "nodes/pg_list.h"
/* ---------------- /* ----------------
@ -1812,7 +1813,7 @@ DESCR("is contained by");
/* /*
* function prototypes * function prototypes
*/ */
extern Oid OperatorCreate(const char *operatorName, extern ObjectAddress OperatorCreate(const char *operatorName,
Oid operatorNamespace, Oid operatorNamespace,
Oid leftTypeId, Oid leftTypeId,
Oid rightTypeId, Oid rightTypeId,

View File

@ -14,9 +14,10 @@
#ifndef PG_PROC_FN_H #ifndef PG_PROC_FN_H
#define PG_PROC_FN_H #define PG_PROC_FN_H
#include "catalog/objectaddress.h"
#include "nodes/pg_list.h" #include "nodes/pg_list.h"
extern Oid ProcedureCreate(const char *procedureName, extern ObjectAddress ProcedureCreate(const char *procedureName,
Oid procNamespace, Oid procNamespace,
bool replace, bool replace,
bool returnsSet, bool returnsSet,

View File

@ -14,14 +14,15 @@
#ifndef PG_TYPE_FN_H #ifndef PG_TYPE_FN_H
#define PG_TYPE_FN_H #define PG_TYPE_FN_H
#include "catalog/objectaddress.h"
#include "nodes/nodes.h" #include "nodes/nodes.h"
extern Oid TypeShellMake(const char *typeName, extern ObjectAddress TypeShellMake(const char *typeName,
Oid typeNamespace, Oid typeNamespace,
Oid ownerId); Oid ownerId);
extern Oid TypeCreate(Oid newTypeOid, extern ObjectAddress TypeCreate(Oid newTypeOid,
const char *typeName, const char *typeName,
Oid typeNamespace, Oid typeNamespace,
Oid relationOid, Oid relationOid,

View File

@ -15,16 +15,18 @@
#define ALTER_H #define ALTER_H
#include "catalog/dependency.h" #include "catalog/dependency.h"
#include "catalog/objectaddress.h"
#include "nodes/parsenodes.h" #include "nodes/parsenodes.h"
#include "utils/relcache.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, extern Oid AlterObjectNamespace_oid(Oid classId, Oid objid, Oid nspOid,
ObjectAddresses *objsMoved); ObjectAddresses *objsMoved);
extern Oid ExecAlterOwnerStmt(AlterOwnerStmt *stmt); extern ObjectAddress ExecAlterOwnerStmt(AlterOwnerStmt *stmt);
extern void AlterObjectOwner_internal(Relation catalog, Oid objectId, extern void AlterObjectOwner_internal(Relation catalog, Oid objectId,
Oid new_ownerId); Oid new_ownerId);

View File

@ -15,9 +15,10 @@
#ifndef COLLATIONCMDS_H #ifndef COLLATIONCMDS_H
#define COLLATIONCMDS_H #define COLLATIONCMDS_H
#include "catalog/objectaddress.h"
#include "nodes/parsenodes.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); extern void IsThereCollationInNamespace(const char *collname, Oid nspOid);
#endif /* COLLATIONCMDS_H */ #endif /* COLLATIONCMDS_H */

View File

@ -15,6 +15,7 @@
#ifndef COMMENT_H #ifndef COMMENT_H
#define COMMENT_H #define COMMENT_H
#include "catalog/objectaddress.h"
#include "nodes/parsenodes.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); extern void DeleteComments(Oid oid, Oid classoid, int32 subid);

View File

@ -15,8 +15,9 @@
#ifndef CONVERSIONCMDS_H #ifndef CONVERSIONCMDS_H
#define CONVERSIONCMDS_H #define CONVERSIONCMDS_H
#include "catalog/objectaddress.h"
#include "nodes/parsenodes.h" #include "nodes/parsenodes.h"
extern Oid CreateConversionCommand(CreateConversionStmt *parsetree); extern ObjectAddress CreateConversionCommand(CreateConversionStmt *parsetree);
#endif /* CONVERSIONCMDS_H */ #endif /* CONVERSIONCMDS_H */

View File

@ -14,12 +14,13 @@
#ifndef CREATEAS_H #ifndef CREATEAS_H
#define CREATEAS_H #define CREATEAS_H
#include "catalog/objectaddress.h"
#include "nodes/params.h" #include "nodes/params.h"
#include "nodes/parsenodes.h" #include "nodes/parsenodes.h"
#include "tcop/dest.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); ParamListInfo params, char *completionTag);
extern int GetIntoRelEFlags(IntoClause *intoClause); extern int GetIntoRelEFlags(IntoClause *intoClause);

View File

@ -15,6 +15,7 @@
#define DBCOMMANDS_H #define DBCOMMANDS_H
#include "access/xlogreader.h" #include "access/xlogreader.h"
#include "catalog/objectaddress.h"
#include "lib/stringinfo.h" #include "lib/stringinfo.h"
#include "nodes/parsenodes.h" #include "nodes/parsenodes.h"
@ -40,10 +41,10 @@ typedef struct xl_dbase_drop_rec
extern Oid createdb(const CreatedbStmt *stmt); extern Oid createdb(const CreatedbStmt *stmt);
extern void dropdb(const char *dbname, bool missing_ok); 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 AlterDatabase(AlterDatabaseStmt *stmt, bool isTopLevel);
extern Oid AlterDatabaseSet(AlterDatabaseSetStmt *stmt); 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 Oid get_database_oid(const char *dbname, bool missingok);
extern char *get_database_name(Oid dbid); extern char *get_database_name(Oid dbid);

View File

@ -14,6 +14,7 @@
#ifndef DEFREM_H #ifndef DEFREM_H
#define DEFREM_H #define DEFREM_H
#include "catalog/objectaddress.h"
#include "nodes/parsenodes.h" #include "nodes/parsenodes.h"
#include "utils/array.h" #include "utils/array.h"
@ -21,7 +22,7 @@
extern void RemoveObjects(DropStmt *stmt); extern void RemoveObjects(DropStmt *stmt);
/* commands/indexcmds.c */ /* commands/indexcmds.c */
extern Oid DefineIndex(Oid relationId, extern ObjectAddress DefineIndex(Oid relationId,
IndexStmt *stmt, IndexStmt *stmt,
Oid indexRelationId, Oid indexRelationId,
bool is_alter_table, bool is_alter_table,
@ -42,12 +43,12 @@ extern bool CheckIndexCompatible(Oid oldId,
extern Oid GetDefaultOpClass(Oid type_id, Oid am_id); extern Oid GetDefaultOpClass(Oid type_id, Oid am_id);
/* commands/functioncmds.c */ /* 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 RemoveFunctionById(Oid funcOid);
extern void SetFunctionReturnType(Oid funcOid, Oid newRetType); extern void SetFunctionReturnType(Oid funcOid, Oid newRetType);
extern void SetFunctionArgType(Oid funcOid, int argIndex, Oid newArgType); extern void SetFunctionArgType(Oid funcOid, int argIndex, Oid newArgType);
extern Oid AlterFunction(AlterFunctionStmt *stmt); extern ObjectAddress AlterFunction(AlterFunctionStmt *stmt);
extern Oid CreateCast(CreateCastStmt *stmt); extern ObjectAddress CreateCast(CreateCastStmt *stmt);
extern void DropCastById(Oid castOid); extern void DropCastById(Oid castOid);
extern void IsThereFunctionInNamespace(const char *proname, int pronargs, extern void IsThereFunctionInNamespace(const char *proname, int pronargs,
oidvector *proargtypes, Oid nspOid); oidvector *proargtypes, Oid nspOid);
@ -66,16 +67,16 @@ extern void interpret_function_parameter_list(List *parameters,
Oid *requiredResultType); Oid *requiredResultType);
/* commands/operatorcmds.c */ /* commands/operatorcmds.c */
extern Oid DefineOperator(List *names, List *parameters); extern ObjectAddress DefineOperator(List *names, List *parameters);
extern void RemoveOperatorById(Oid operOid); extern void RemoveOperatorById(Oid operOid);
/* commands/aggregatecmds.c */ /* 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); List *parameters, const char *queryString);
/* commands/opclasscmds.c */ /* commands/opclasscmds.c */
extern Oid DefineOpClass(CreateOpClassStmt *stmt); extern ObjectAddress DefineOpClass(CreateOpClassStmt *stmt);
extern Oid DefineOpFamily(CreateOpFamilyStmt *stmt); extern ObjectAddress DefineOpFamily(CreateOpFamilyStmt *stmt);
extern Oid AlterOpFamily(AlterOpFamilyStmt *stmt); extern Oid AlterOpFamily(AlterOpFamilyStmt *stmt);
extern void RemoveOpClassById(Oid opclassOid); extern void RemoveOpClassById(Oid opclassOid);
extern void RemoveOpFamilyById(Oid opfamilyOid); 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); extern Oid get_opfamily_oid(Oid amID, List *opfamilyname, bool missing_ok);
/* commands/tsearchcmds.c */ /* commands/tsearchcmds.c */
extern Oid DefineTSParser(List *names, List *parameters); extern ObjectAddress DefineTSParser(List *names, List *parameters);
extern void RemoveTSParserById(Oid prsId); 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 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 void RemoveTSTemplateById(Oid tmplId);
extern Oid DefineTSConfiguration(List *names, List *parameters); extern ObjectAddress DefineTSConfiguration(List *names, List *parameters);
extern void RemoveTSConfigurationById(Oid cfgId); extern void RemoveTSConfigurationById(Oid cfgId);
extern Oid AlterTSConfiguration(AlterTSConfigurationStmt *stmt); extern ObjectAddress AlterTSConfiguration(AlterTSConfigurationStmt *stmt);
extern text *serialize_deflist(List *deflist); extern text *serialize_deflist(List *deflist);
extern List *deserialize_deflist(Datum txt); extern List *deserialize_deflist(Datum txt);
/* commands/foreigncmds.c */ /* 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 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 void AlterForeignDataWrapperOwner_oid(Oid fwdId, Oid newOwnerId);
extern Oid CreateForeignDataWrapper(CreateFdwStmt *stmt); extern ObjectAddress CreateForeignDataWrapper(CreateFdwStmt *stmt);
extern Oid AlterForeignDataWrapper(AlterFdwStmt *stmt); extern ObjectAddress AlterForeignDataWrapper(AlterFdwStmt *stmt);
extern void RemoveForeignDataWrapperById(Oid fdwId); extern void RemoveForeignDataWrapperById(Oid fdwId);
extern Oid CreateForeignServer(CreateForeignServerStmt *stmt); extern ObjectAddress CreateForeignServer(CreateForeignServerStmt *stmt);
extern Oid AlterForeignServer(AlterForeignServerStmt *stmt); extern ObjectAddress AlterForeignServer(AlterForeignServerStmt *stmt);
extern void RemoveForeignServerById(Oid srvId); extern void RemoveForeignServerById(Oid srvId);
extern Oid CreateUserMapping(CreateUserMappingStmt *stmt); extern ObjectAddress CreateUserMapping(CreateUserMappingStmt *stmt);
extern Oid AlterUserMapping(AlterUserMappingStmt *stmt); extern ObjectAddress AlterUserMapping(AlterUserMappingStmt *stmt);
extern Oid RemoveUserMapping(DropUserMappingStmt *stmt); extern Oid RemoveUserMapping(DropUserMappingStmt *stmt);
extern void RemoveUserMappingById(Oid umId); extern void RemoveUserMappingById(Oid umId);
extern void CreateForeignTable(CreateForeignTableStmt *stmt, Oid relid); extern void CreateForeignTable(CreateForeignTableStmt *stmt, Oid relid);

View File

@ -43,7 +43,7 @@ extern void RemoveEventTriggerById(Oid ctrigOid);
extern Oid get_event_trigger_oid(const char *trigname, bool missing_ok); extern Oid get_event_trigger_oid(const char *trigname, bool missing_ok);
extern Oid AlterEventTrigger(AlterEventTrigStmt *stmt); 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 void AlterEventTriggerOwner_oid(Oid, Oid newOwnerId);
extern bool EventTriggerSupportsObjectType(ObjectType obtype); extern bool EventTriggerSupportsObjectType(ObjectType obtype);

View File

@ -14,6 +14,7 @@
#ifndef EXTENSION_H #ifndef EXTENSION_H
#define EXTENSION_H #define EXTENSION_H
#include "catalog/objectaddress.h"
#include "nodes/parsenodes.h" #include "nodes/parsenodes.h"
@ -27,23 +28,25 @@ extern bool creating_extension;
extern Oid CurrentExtensionObject; extern Oid CurrentExtensionObject;
extern Oid CreateExtension(CreateExtensionStmt *stmt); extern ObjectAddress CreateExtension(CreateExtensionStmt *stmt);
extern void RemoveExtensionById(Oid extId); 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, Oid schemaOid, bool relocatable, const char *extVersion,
Datum extConfig, Datum extCondition, Datum extConfig, Datum extCondition,
List *requiredExtensions); 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 Oid get_extension_oid(const char *extname, bool missing_ok);
extern char *get_extension_name(Oid ext_oid); 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); extern void AlterExtensionOwner_oid(Oid extensionOid, Oid newOwnerId);

View File

@ -14,6 +14,7 @@
#ifndef MATVIEW_H #ifndef MATVIEW_H
#define MATVIEW_H #define MATVIEW_H
#include "catalog/objectaddress.h"
#include "nodes/params.h" #include "nodes/params.h"
#include "nodes/parsenodes.h" #include "nodes/parsenodes.h"
#include "tcop/dest.h" #include "tcop/dest.h"
@ -22,7 +23,7 @@
extern void SetMatViewPopulatedState(Relation relation, bool newstate); 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); ParamListInfo params, char *completionTag);
extern DestReceiver *CreateTransientRelDestReceiver(Oid oid); extern DestReceiver *CreateTransientRelDestReceiver(Oid oid);

View File

@ -15,6 +15,7 @@
#ifndef POLICY_H #ifndef POLICY_H
#define POLICY_H #define POLICY_H
#include "catalog/objectaddress.h"
#include "nodes/parsenodes.h" #include "nodes/parsenodes.h"
#include "utils/relcache.h" #include "utils/relcache.h"
@ -22,13 +23,13 @@ extern void RelationBuildRowSecurity(Relation relation);
extern void RemovePolicyById(Oid policy_id); extern void RemovePolicyById(Oid policy_id);
extern Oid CreatePolicy(CreatePolicyStmt *stmt); extern ObjectAddress CreatePolicy(CreatePolicyStmt *stmt);
extern Oid AlterPolicy(AlterPolicyStmt *stmt); extern ObjectAddress AlterPolicy(AlterPolicyStmt *stmt);
extern Oid get_relation_policy_oid(Oid relid, const char *policy_name, extern Oid get_relation_policy_oid(Oid relid, const char *policy_name,
bool missing_ok); bool missing_ok);
extern Oid rename_policy(RenameStmt *stmt); extern ObjectAddress rename_policy(RenameStmt *stmt);
#endif /* POLICY_H */ #endif /* POLICY_H */

View File

@ -12,9 +12,10 @@
#ifndef PROCLANG_H #ifndef PROCLANG_H
#define PROCLANG_H #define PROCLANG_H
#include "catalog/objectaddress.h"
#include "nodes/parsenodes.h" #include "nodes/parsenodes.h"
extern Oid CreateProceduralLanguage(CreatePLangStmt *stmt); extern ObjectAddress CreateProceduralLanguage(CreatePLangStmt *stmt);
extern void DropProceduralLanguageById(Oid langOid); extern void DropProceduralLanguageById(Oid langOid);
extern bool PLTemplateExists(const char *languageName); extern bool PLTemplateExists(const char *languageName);
extern Oid get_language_oid(const char *langname, bool missing_ok); extern Oid get_language_oid(const char *langname, bool missing_ok);

View File

@ -15,6 +15,7 @@
#ifndef SCHEMACMDS_H #ifndef SCHEMACMDS_H
#define SCHEMACMDS_H #define SCHEMACMDS_H
#include "catalog/objectaddress.h"
#include "nodes/parsenodes.h" #include "nodes/parsenodes.h"
extern Oid CreateSchemaCommand(CreateSchemaStmt *parsetree, extern Oid CreateSchemaCommand(CreateSchemaStmt *parsetree,
@ -22,8 +23,8 @@ extern Oid CreateSchemaCommand(CreateSchemaStmt *parsetree,
extern void RemoveSchemaById(Oid schemaOid); extern void RemoveSchemaById(Oid schemaOid);
extern Oid RenameSchema(const char *oldname, const char *newname); extern ObjectAddress RenameSchema(const char *oldname, const char *newname);
extern Oid AlterSchemaOwner(const char *name, Oid newOwnerId); extern ObjectAddress AlterSchemaOwner(const char *name, Oid newOwnerId);
extern void AlterSchemaOwner_oid(Oid schemaOid, Oid newOwnerId); extern void AlterSchemaOwner_oid(Oid schemaOid, Oid newOwnerId);
#endif /* SCHEMACMDS_H */ #endif /* SCHEMACMDS_H */

View File

@ -24,7 +24,7 @@ extern void DeleteSharedSecurityLabel(Oid objectId, Oid classId);
/* /*
* Statement and ESP hook support * Statement and ESP hook support
*/ */
extern Oid ExecSecLabelStmt(SecLabelStmt *stmt); extern ObjectAddress ExecSecLabelStmt(SecLabelStmt *stmt);
typedef void (*check_object_relabel_type) (const ObjectAddress *object, typedef void (*check_object_relabel_type) (const ObjectAddress *object,
const char *seclabel); const char *seclabel);

View File

@ -14,6 +14,7 @@
#define SEQUENCE_H #define SEQUENCE_H
#include "access/xlogreader.h" #include "access/xlogreader.h"
#include "catalog/objectaddress.h"
#include "fmgr.h" #include "fmgr.h"
#include "lib/stringinfo.h" #include "lib/stringinfo.h"
#include "nodes/parsenodes.h" #include "nodes/parsenodes.h"
@ -72,8 +73,8 @@ extern Datum lastval(PG_FUNCTION_ARGS);
extern Datum pg_sequence_parameters(PG_FUNCTION_ARGS); extern Datum pg_sequence_parameters(PG_FUNCTION_ARGS);
extern Oid DefineSequence(CreateSeqStmt *stmt); extern ObjectAddress DefineSequence(CreateSeqStmt *stmt);
extern Oid AlterSequence(AlterSeqStmt *stmt); extern ObjectAddress AlterSequence(AlterSeqStmt *stmt);
extern void ResetSequence(Oid seq_relid); extern void ResetSequence(Oid seq_relid);
extern void ResetSequenceCaches(void); extern void ResetSequenceCaches(void);

View File

@ -16,12 +16,14 @@
#include "access/htup.h" #include "access/htup.h"
#include "catalog/dependency.h" #include "catalog/dependency.h"
#include "catalog/objectaddress.h"
#include "nodes/parsenodes.h" #include "nodes/parsenodes.h"
#include "storage/lock.h" #include "storage/lock.h"
#include "utils/relcache.h" #include "utils/relcache.h"
extern Oid DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId); extern ObjectAddress DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
ObjectAddress *typaddress);
extern void RemoveRelations(DropStmt *drop); extern void RemoveRelations(DropStmt *drop);
@ -37,7 +39,8 @@ extern void AlterTableInternal(Oid relid, List *cmds, bool recurse);
extern Oid AlterTableMoveAll(AlterTableMoveAllStmt *stmt); extern Oid AlterTableMoveAll(AlterTableMoveAllStmt *stmt);
extern Oid AlterTableNamespace(AlterObjectSchemaStmt *stmt); extern ObjectAddress AlterTableNamespace(AlterObjectSchemaStmt *stmt,
Oid *oldschema);
extern void AlterTableNamespaceInternal(Relation rel, Oid oldNspOid, extern void AlterTableNamespaceInternal(Relation rel, Oid oldNspOid,
Oid nspOid, ObjectAddresses *objsMoved); Oid nspOid, ObjectAddresses *objsMoved);
@ -53,11 +56,13 @@ extern void ExecuteTruncate(TruncateStmt *stmt);
extern void SetRelationHasSubclass(Oid relationId, bool relhassubclass); 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, extern void RenameRelationInternal(Oid myrelid,
const char *newrelname, bool is_internal); const char *newrelname, bool is_internal);

View File

@ -15,6 +15,7 @@
#define TABLESPACE_H #define TABLESPACE_H
#include "access/xlogreader.h" #include "access/xlogreader.h"
#include "catalog/objectaddress.h"
#include "lib/stringinfo.h" #include "lib/stringinfo.h"
#include "nodes/parsenodes.h" #include "nodes/parsenodes.h"
@ -42,7 +43,7 @@ typedef struct TableSpaceOpts
extern Oid CreateTableSpace(CreateTableSpaceStmt *stmt); extern Oid CreateTableSpace(CreateTableSpaceStmt *stmt);
extern void DropTableSpace(DropTableSpaceStmt *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 Oid AlterTableSpaceOptions(AlterTableSpaceOptionsStmt *stmt);
extern void TablespaceCreateDbspace(Oid spcNode, Oid dbNode, bool isRedo); extern void TablespaceCreateDbspace(Oid spcNode, Oid dbNode, bool isRedo);

View File

@ -13,6 +13,7 @@
#ifndef TRIGGER_H #ifndef TRIGGER_H
#define TRIGGER_H #define TRIGGER_H
#include "catalog/objectaddress.h"
#include "nodes/execnodes.h" #include "nodes/execnodes.h"
#include "nodes/parsenodes.h" #include "nodes/parsenodes.h"
@ -108,14 +109,14 @@ extern PGDLLIMPORT int SessionReplicationRole;
#define TRIGGER_FIRES_ON_REPLICA 'R' #define TRIGGER_FIRES_ON_REPLICA 'R'
#define TRIGGER_DISABLED 'D' #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, Oid relOid, Oid refRelOid, Oid constraintOid, Oid indexOid,
bool isInternal); bool isInternal);
extern void RemoveTriggerById(Oid trigOid); extern void RemoveTriggerById(Oid trigOid);
extern Oid get_trigger_oid(Oid relid, const char *name, bool missing_ok); 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, extern void EnableDisableTrigger(Relation rel, const char *tgname,
char fires_when, bool skip_system); char fires_when, bool skip_system);

View File

@ -21,29 +21,31 @@
#define DEFAULT_TYPDELIM ',' #define DEFAULT_TYPDELIM ','
extern Oid DefineType(List *names, List *parameters); extern ObjectAddress DefineType(List *names, List *parameters);
extern void RemoveTypeById(Oid typeOid); extern void RemoveTypeById(Oid typeOid);
extern Oid DefineDomain(CreateDomainStmt *stmt); extern ObjectAddress DefineDomain(CreateDomainStmt *stmt);
extern Oid DefineEnum(CreateEnumStmt *stmt); extern ObjectAddress DefineEnum(CreateEnumStmt *stmt);
extern Oid DefineRange(CreateRangeStmt *stmt); extern ObjectAddress DefineRange(CreateRangeStmt *stmt);
extern Oid AlterEnum(AlterEnumStmt *stmt, bool isTopLevel); extern ObjectAddress AlterEnum(AlterEnumStmt *stmt, bool isTopLevel);
extern Oid DefineCompositeType(RangeVar *typevar, List *coldeflist); extern ObjectAddress DefineCompositeType(RangeVar *typevar, List *coldeflist);
extern Oid AssignTypeArrayOid(void); extern Oid AssignTypeArrayOid(void);
extern Oid AlterDomainDefault(List *names, Node *defaultRaw); extern ObjectAddress AlterDomainDefault(List *names, Node *defaultRaw);
extern Oid AlterDomainNotNull(List *names, bool notNull); extern ObjectAddress AlterDomainNotNull(List *names, bool notNull);
extern Oid AlterDomainAddConstraint(List *names, Node *constr); extern ObjectAddress AlterDomainAddConstraint(List *names, Node *constr,
extern Oid AlterDomainValidateConstraint(List *names, char *constrName); ObjectAddress *constrAddr);
extern Oid AlterDomainDropConstraint(List *names, const char *constrName, extern ObjectAddress AlterDomainValidateConstraint(List *names, char *constrName);
extern ObjectAddress AlterDomainDropConstraint(List *names, const char *constrName,
DropBehavior behavior, bool missing_ok); DropBehavior behavior, bool missing_ok);
extern void checkDomainOwner(HeapTuple tup); extern void checkDomainOwner(HeapTuple tup);
extern Oid RenameType(RenameStmt *stmt); extern ObjectAddress RenameType(RenameStmt *stmt);
extern Oid AlterTypeOwner(List *names, Oid newOwnerId, ObjectType objecttype); extern ObjectAddress AlterTypeOwner(List *names, Oid newOwnerId, ObjectType objecttype);
extern void AlterTypeOwnerInternal(Oid typeOid, Oid newOwnerId, extern void AlterTypeOwnerInternal(Oid typeOid, Oid newOwnerId,
bool hasDependEntry); 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 AlterTypeNamespace_oid(Oid typeOid, Oid nspOid, ObjectAddresses *objsMoved);
extern Oid AlterTypeNamespaceInternal(Oid typeOid, Oid nspOid, extern Oid AlterTypeNamespaceInternal(Oid typeOid, Oid nspOid,
bool isImplicitArray, bool isImplicitArray,

View File

@ -11,6 +11,7 @@
#ifndef USER_H #ifndef USER_H
#define USER_H #define USER_H
#include "catalog/objectaddress.h"
#include "nodes/parsenodes.h" #include "nodes/parsenodes.h"
@ -27,7 +28,7 @@ extern Oid AlterRole(AlterRoleStmt *stmt);
extern Oid AlterRoleSet(AlterRoleSetStmt *stmt); extern Oid AlterRoleSet(AlterRoleSetStmt *stmt);
extern void DropRole(DropRoleStmt *stmt); extern void DropRole(DropRoleStmt *stmt);
extern void GrantRole(GrantRoleStmt *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 DropOwnedObjects(DropOwnedStmt *stmt);
extern void ReassignOwnedObjects(ReassignOwnedStmt *stmt); extern void ReassignOwnedObjects(ReassignOwnedStmt *stmt);
extern List *roleNamesToIds(List *memberNames); extern List *roleNamesToIds(List *memberNames);

View File

@ -14,11 +14,12 @@
#ifndef VIEW_H #ifndef VIEW_H
#define VIEW_H #define VIEW_H
#include "catalog/objectaddress.h"
#include "nodes/parsenodes.h" #include "nodes/parsenodes.h"
extern void validateWithCheckOption(char *value); 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); extern void StoreViewQuery(Oid viewOid, Query *viewParse, bool replace);

View File

@ -14,6 +14,7 @@
#ifndef REWRITEDEFINE_H #ifndef REWRITEDEFINE_H
#define REWRITEDEFINE_H #define REWRITEDEFINE_H
#include "catalog/objectaddress.h"
#include "nodes/parsenodes.h" #include "nodes/parsenodes.h"
#include "utils/relcache.h" #include "utils/relcache.h"
@ -22,9 +23,9 @@
#define RULE_FIRES_ON_REPLICA 'R' #define RULE_FIRES_ON_REPLICA 'R'
#define RULE_DISABLED 'D' #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, Oid event_relid,
Node *event_qual, Node *event_qual,
CmdType event_type, CmdType event_type,
@ -32,7 +33,7 @@ extern Oid DefineQueryRewrite(char *rulename,
bool replace, bool replace,
List *action); List *action);
extern Oid RenameRewriteRule(RangeVar *relation, const char *oldName, extern ObjectAddress RenameRewriteRule(RangeVar *relation, const char *oldName,
const char *newName); const char *newName);
extern void setRuleCheckAsUser(Node *node, Oid userid); extern void setRuleCheckAsUser(Node *node, Oid userid);