Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a2e35b5

Browse files
committed
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
1 parent 6f9d799 commit a2e35b5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+840
-558
lines changed

src/backend/bootstrap/bootparse.y

+2-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,8 @@ Boot_CreateStmt:
251251
(Datum) 0,
252252
false,
253253
true,
254-
false);
254+
false,
255+
NULL);
255256
elog(DEBUG4, "relation created with OID %u", id);
256257
}
257258
do_end();

src/backend/catalog/heap.c

+18-10
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ static void AddNewRelationTuple(Relation pg_class_desc,
8989
char relkind,
9090
Datum relacl,
9191
Datum reloptions);
92-
static Oid AddNewRelationType(const char *typeName,
92+
static ObjectAddress AddNewRelationType(const char *typeName,
9393
Oid typeNamespace,
9494
Oid new_rel_oid,
9595
char new_rel_kind,
@@ -935,7 +935,7 @@ AddNewRelationTuple(Relation pg_class_desc,
935935
* define a composite type corresponding to the new relation
936936
* --------------------------------
937937
*/
938-
static Oid
938+
static ObjectAddress
939939
AddNewRelationType(const char *typeName,
940940
Oid typeNamespace,
941941
Oid new_rel_oid,
@@ -1006,6 +1006,9 @@ AddNewRelationType(const char *typeName,
10061006
* allow_system_table_mods: TRUE to allow creation in system namespaces
10071007
* is_internal: is this a system-generated catalog?
10081008
*
1009+
* Output parameters:
1010+
* typaddress: if not null, gets the object address of the new pg_type entry
1011+
*
10091012
* Returns the OID of the new relation
10101013
* --------------------------------
10111014
*/
@@ -1029,14 +1032,16 @@ heap_create_with_catalog(const char *relname,
10291032
Datum reloptions,
10301033
bool use_user_acl,
10311034
bool allow_system_table_mods,
1032-
bool is_internal)
1035+
bool is_internal,
1036+
ObjectAddress *typaddress)
10331037
{
10341038
Relation pg_class_desc;
10351039
Relation new_rel_desc;
10361040
Acl *relacl;
10371041
Oid existing_relid;
10381042
Oid old_type_oid;
10391043
Oid new_type_oid;
1044+
ObjectAddress new_type_addr;
10401045
Oid new_array_oid = InvalidOid;
10411046

10421047
pg_class_desc = heap_open(RelationRelationId, RowExclusiveLock);
@@ -1187,13 +1192,16 @@ heap_create_with_catalog(const char *relname,
11871192
* creating the same type name in parallel but hadn't committed yet when
11881193
* we checked for a duplicate name above.
11891194
*/
1190-
new_type_oid = AddNewRelationType(relname,
1191-
relnamespace,
1192-
relid,
1193-
relkind,
1194-
ownerid,
1195-
reltypeid,
1196-
new_array_oid);
1195+
new_type_addr = AddNewRelationType(relname,
1196+
relnamespace,
1197+
relid,
1198+
relkind,
1199+
ownerid,
1200+
reltypeid,
1201+
new_array_oid);
1202+
new_type_oid = new_type_addr.objectId;
1203+
if (typaddress)
1204+
*typaddress = new_type_addr;
11971205

11981206
/*
11991207
* Now make the array type if wanted.

src/backend/catalog/objectaddress.c

+6
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,12 @@ ObjectTypeMap[] =
531531
{ "policy", OBJECT_POLICY }
532532
};
533533

534+
const ObjectAddress InvalidObjectAddress =
535+
{
536+
InvalidOid,
537+
InvalidOid,
538+
0
539+
};
534540

535541
static ObjectAddress get_object_address_unqualified(ObjectType objtype,
536542
List *qualname, bool missing_ok);

src/backend/catalog/pg_aggregate.c

+27-29
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static Oid lookup_agg_function(List *fnName, int nargs, Oid *input_types,
4343
/*
4444
* AggregateCreate
4545
*/
46-
Oid
46+
ObjectAddress
4747
AggregateCreate(const char *aggName,
4848
Oid aggNamespace,
4949
char aggKind,
@@ -522,32 +522,33 @@ AggregateCreate(const char *aggName,
522522
* aggregate. (This could fail if there's already a conflicting entry.)
523523
*/
524524

525-
procOid = ProcedureCreate(aggName,
526-
aggNamespace,
527-
false, /* no replacement */
528-
false, /* doesn't return a set */
529-
finaltype, /* returnType */
530-
GetUserId(), /* proowner */
531-
INTERNALlanguageId, /* languageObjectId */
532-
InvalidOid, /* no validator */
533-
"aggregate_dummy", /* placeholder proc */
534-
NULL, /* probin */
535-
true, /* isAgg */
536-
false, /* isWindowFunc */
537-
false, /* security invoker (currently not
525+
myself = ProcedureCreate(aggName,
526+
aggNamespace,
527+
false, /* no replacement */
528+
false, /* doesn't return a set */
529+
finaltype, /* returnType */
530+
GetUserId(), /* proowner */
531+
INTERNALlanguageId, /* languageObjectId */
532+
InvalidOid, /* no validator */
533+
"aggregate_dummy", /* placeholder proc */
534+
NULL, /* probin */
535+
true, /* isAgg */
536+
false, /* isWindowFunc */
537+
false, /* security invoker (currently not
538538
* definable for agg) */
539-
false, /* isLeakProof */
540-
false, /* isStrict (not needed for agg) */
541-
PROVOLATILE_IMMUTABLE, /* volatility (not
539+
false, /* isLeakProof */
540+
false, /* isStrict (not needed for agg) */
541+
PROVOLATILE_IMMUTABLE, /* volatility (not
542542
* needed for agg) */
543-
parameterTypes, /* paramTypes */
544-
allParameterTypes, /* allParamTypes */
545-
parameterModes, /* parameterModes */
546-
parameterNames, /* parameterNames */
547-
parameterDefaults, /* parameterDefaults */
548-
PointerGetDatum(NULL), /* proconfig */
549-
1, /* procost */
550-
0); /* prorows */
543+
parameterTypes, /* paramTypes */
544+
allParameterTypes, /* allParamTypes */
545+
parameterModes, /* parameterModes */
546+
parameterNames, /* parameterNames */
547+
parameterDefaults, /* parameterDefaults */
548+
PointerGetDatum(NULL), /* proconfig */
549+
1, /* procost */
550+
0); /* prorows */
551+
procOid = myself.objectId;
551552

552553
/*
553554
* Okay to create the pg_aggregate entry.
@@ -599,9 +600,6 @@ AggregateCreate(const char *aggName,
599600
* on aggTransType since we depend on it indirectly through transfn.
600601
* Likewise for aggmTransType if any.
601602
*/
602-
myself.classId = ProcedureRelationId;
603-
myself.objectId = procOid;
604-
myself.objectSubId = 0;
605603

606604
/* Depends on transition function */
607605
referenced.classId = ProcedureRelationId;
@@ -654,7 +652,7 @@ AggregateCreate(const char *aggName,
654652
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
655653
}
656654

657-
return procOid;
655+
return myself;
658656
}
659657

660658
/*

src/backend/catalog/pg_conversion.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
* Add a new tuple to pg_conversion.
3939
*/
40-
Oid
40+
ObjectAddress
4141
ConversionCreate(const char *conname, Oid connamespace,
4242
Oid conowner,
4343
int32 conforencoding, int32 contoencoding,
@@ -141,7 +141,7 @@ ConversionCreate(const char *conname, Oid connamespace,
141141
heap_freetuple(tup);
142142
heap_close(rel, RowExclusiveLock);
143143

144-
return oid;
144+
return myself;
145145
}
146146

147147
/*

src/backend/catalog/pg_operator.c

+8-5
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static Oid get_other_operator(List *otherOp,
6161
Oid leftTypeId, Oid rightTypeId,
6262
bool isCommutator);
6363

64-
static void makeOperatorDependencies(HeapTuple tuple);
64+
static ObjectAddress makeOperatorDependencies(HeapTuple tuple);
6565

6666

6767
/*
@@ -325,7 +325,7 @@ OperatorShellMake(const char *operatorName,
325325
* Forward declaration is used only for this purpose, it is
326326
* not available to the user as it is for type definition.
327327
*/
328-
Oid
328+
ObjectAddress
329329
OperatorCreate(const char *operatorName,
330330
Oid operatorNamespace,
331331
Oid leftTypeId,
@@ -352,6 +352,7 @@ OperatorCreate(const char *operatorName,
352352
NameData oname;
353353
TupleDesc tupDesc;
354354
int i;
355+
ObjectAddress address;
355356

356357
/*
357358
* Sanity checks
@@ -540,7 +541,7 @@ OperatorCreate(const char *operatorName,
540541
CatalogUpdateIndexes(pg_operator_desc, tup);
541542

542543
/* Add dependencies for the entry */
543-
makeOperatorDependencies(tup);
544+
address = makeOperatorDependencies(tup);
544545

545546
/* Post creation hook for new operator */
546547
InvokeObjectPostCreateHook(OperatorRelationId, operatorObjectId, 0);
@@ -564,7 +565,7 @@ OperatorCreate(const char *operatorName,
564565
if (OidIsValid(commutatorId) || OidIsValid(negatorId))
565566
OperatorUpd(operatorObjectId, commutatorId, negatorId);
566567

567-
return operatorObjectId;
568+
return address;
568569
}
569570

570571
/*
@@ -764,7 +765,7 @@ OperatorUpd(Oid baseId, Oid commId, Oid negId)
764765
* NB: the OidIsValid tests in this routine are necessary, in case
765766
* the given operator is a shell.
766767
*/
767-
static void
768+
static ObjectAddress
768769
makeOperatorDependencies(HeapTuple tuple)
769770
{
770771
Form_pg_operator oper = (Form_pg_operator) GETSTRUCT(tuple);
@@ -860,4 +861,6 @@ makeOperatorDependencies(HeapTuple tuple)
860861

861862
/* Dependency on extension */
862863
recordDependencyOnCurrentExtension(&myself, true);
864+
865+
return myself;
863866
}

src/backend/catalog/pg_proc.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static bool match_prosrc_to_literal(const char *prosrc, const char *literal,
6464
* not "ArrayType *", to avoid importing array.h into pg_proc_fn.h.
6565
* ----------------------------------------------------------------
6666
*/
67-
Oid
67+
ObjectAddress
6868
ProcedureCreate(const char *procedureName,
6969
Oid procNamespace,
7070
bool replace,
@@ -703,7 +703,7 @@ ProcedureCreate(const char *procedureName,
703703
AtEOXact_GUC(true, save_nestlevel);
704704
}
705705

706-
return retval;
706+
return myself;
707707
}
708708

709709

src/backend/catalog/pg_type.c

+13-7
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Oid binary_upgrade_next_pg_type_oid = InvalidOid;
5252
* with correct ones, and "typisdefined" will be set to true.
5353
* ----------------------------------------------------------------
5454
*/
55-
Oid
55+
ObjectAddress
5656
TypeShellMake(const char *typeName, Oid typeNamespace, Oid ownerId)
5757
{
5858
Relation pg_type_desc;
@@ -63,6 +63,7 @@ TypeShellMake(const char *typeName, Oid typeNamespace, Oid ownerId)
6363
bool nulls[Natts_pg_type];
6464
Oid typoid;
6565
NameData name;
66+
ObjectAddress address;
6667

6768
Assert(PointerIsValid(typeName));
6869

@@ -171,26 +172,28 @@ TypeShellMake(const char *typeName, Oid typeNamespace, Oid ownerId)
171172
/* Post creation hook for new shell type */
172173
InvokeObjectPostCreateHook(TypeRelationId, typoid, 0);
173174

175+
ObjectAddressSet(address, TypeRelationId, typoid);
176+
174177
/*
175178
* clean up and return the type-oid
176179
*/
177180
heap_freetuple(tup);
178181
heap_close(pg_type_desc, RowExclusiveLock);
179182

180-
return typoid;
183+
return address;
181184
}
182185

183186
/* ----------------------------------------------------------------
184187
* TypeCreate
185188
*
186189
* This does all the necessary work needed to define a new type.
187190
*
188-
* Returns the OID assigned to the new type. If newTypeOid is
189-
* zero (the normal case), a new OID is created; otherwise we
190-
* use exactly that OID.
191+
* Returns the ObjectAddress assigned to the new type.
192+
* If newTypeOid is zero (the normal case), a new OID is created;
193+
* otherwise we use exactly that OID.
191194
* ----------------------------------------------------------------
192195
*/
193-
Oid
196+
ObjectAddress
194197
TypeCreate(Oid newTypeOid,
195198
const char *typeName,
196199
Oid typeNamespace,
@@ -233,6 +236,7 @@ TypeCreate(Oid newTypeOid,
233236
NameData name;
234237
int i;
235238
Acl *typacl = NULL;
239+
ObjectAddress address;
236240

237241
/*
238242
* We assume that the caller validated the arguments individually, but did
@@ -488,12 +492,14 @@ TypeCreate(Oid newTypeOid,
488492
/* Post creation hook for new type */
489493
InvokeObjectPostCreateHook(TypeRelationId, typeObjectId, 0);
490494

495+
ObjectAddressSet(address, TypeRelationId, typeObjectId);
496+
491497
/*
492498
* finish up
493499
*/
494500
heap_close(pg_type_desc, RowExclusiveLock);
495501

496-
return typeObjectId;
502+
return address;
497503
}
498504

499505
/*

src/backend/catalog/toasting.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,8 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
289289
reloptions,
290290
false,
291291
true,
292-
true);
292+
true,
293+
NULL);
293294
Assert(toast_relid != InvalidOid);
294295

295296
/* make the toast relation visible, else heap_open will fail */

src/backend/commands/aggregatecmds.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
* isn't an ordered-set aggregate.
5252
* "parameters" is a list of DefElem representing the agg's definition clauses.
5353
*/
54-
Oid
54+
ObjectAddress
5555
DefineAggregate(List *name, List *args, bool oldstyle, List *parameters,
5656
const char *queryString)
5757
{

0 commit comments

Comments
 (0)