@@ -450,17 +450,28 @@ static void getRelationIdentity(StringInfo buffer, Oid relid);
450
450
* sub-object is looked up, the parent object will be locked instead.
451
451
*
452
452
* If the object is a relation or a child object of a relation (e.g. an
453
- * attribute or contraint ), the relation is also opened and *relp receives
453
+ * attribute or constraint ), the relation is also opened and *relp receives
454
454
* the open relcache entry pointer; otherwise, *relp is set to NULL. This
455
455
* is a bit grotty but it makes life simpler, since the caller will
456
456
* typically need the relcache entry too. Caller must close the relcache
457
457
* entry when done with it. The relation is locked with the specified lockmode
458
458
* if the target object is the relation itself or an attribute, but for other
459
459
* child objects, only AccessShareLock is acquired on the relation.
460
460
*
461
+ * If the object is not found, an error is thrown, unless missing_ok is
462
+ * true. In this case, no lock is acquired, relp is set to NULL, and the
463
+ * returned address has objectId set to InvalidOid.
464
+ *
461
465
* We don't currently provide a function to release the locks acquired here;
462
466
* typically, the lock must be held until commit to guard against a concurrent
463
467
* drop operation.
468
+ *
469
+ * Note: If the object is not found, we don't give any indication of the
470
+ * reason. (It might have been a missing schema if the name was qualified, or
471
+ * an inexistant type name in case of a cast, function or operator; etc).
472
+ * Currently there is only one caller that might be interested in such info, so
473
+ * we don't spend much effort here. If more callers start to care, it might be
474
+ * better to add some support for that in this function.
464
475
*/
465
476
ObjectAddress
466
477
get_object_address (ObjectType objtype , List * objname , List * objargs ,
@@ -580,9 +591,11 @@ get_object_address(ObjectType objtype, List *objname, List *objargs,
580
591
{
581
592
TypeName * sourcetype = (TypeName * ) linitial (objname );
582
593
TypeName * targettype = (TypeName * ) linitial (objargs );
583
- Oid sourcetypeid = typenameTypeId ( NULL , sourcetype ) ;
584
- Oid targettypeid = typenameTypeId ( NULL , targettype ) ;
594
+ Oid sourcetypeid ;
595
+ Oid targettypeid ;
585
596
597
+ sourcetypeid = LookupTypeNameOid (NULL , sourcetype , missing_ok );
598
+ targettypeid = LookupTypeNameOid (NULL , targettype , missing_ok );
586
599
address .classId = CastRelationId ;
587
600
address .objectId =
588
601
get_cast_oid (sourcetypeid , targettypeid , missing_ok );
@@ -942,26 +955,31 @@ get_object_address_relobject(ObjectType objtype, List *objname,
942
955
943
956
/* Extract relation name and open relation. */
944
957
relname = list_truncate (list_copy (objname ), nnames - 1 );
945
- relation = heap_openrv (makeRangeVarFromNameList (relname ),
946
- AccessShareLock );
947
- reloid = RelationGetRelid (relation );
958
+ relation = heap_openrv_extended (makeRangeVarFromNameList (relname ),
959
+ AccessShareLock ,
960
+ missing_ok );
961
+
962
+ reloid = relation ? RelationGetRelid (relation ) : InvalidOid ;
948
963
949
964
switch (objtype )
950
965
{
951
966
case OBJECT_RULE :
952
967
address .classId = RewriteRelationId ;
953
- address .objectId = get_rewrite_oid (reloid , depname , missing_ok );
968
+ address .objectId = relation ?
969
+ get_rewrite_oid (reloid , depname , missing_ok ) : InvalidOid ;
954
970
address .objectSubId = 0 ;
955
971
break ;
956
972
case OBJECT_TRIGGER :
957
973
address .classId = TriggerRelationId ;
958
- address .objectId = get_trigger_oid (reloid , depname , missing_ok );
974
+ address .objectId = relation ?
975
+ get_trigger_oid (reloid , depname , missing_ok ) : InvalidOid ;
959
976
address .objectSubId = 0 ;
960
977
break ;
961
978
case OBJECT_CONSTRAINT :
962
979
address .classId = ConstraintRelationId ;
963
- address .objectId =
964
- get_relation_constraint_oid (reloid , depname , missing_ok );
980
+ address .objectId = relation ?
981
+ get_relation_constraint_oid (reloid , depname , missing_ok ) :
982
+ InvalidOid ;
965
983
address .objectSubId = 0 ;
966
984
break ;
967
985
default :
@@ -975,7 +993,9 @@ get_object_address_relobject(ObjectType objtype, List *objname,
975
993
/* Avoid relcache leak when object not found. */
976
994
if (!OidIsValid (address .objectId ))
977
995
{
978
- heap_close (relation , AccessShareLock );
996
+ if (relation != NULL )
997
+ heap_close (relation , AccessShareLock );
998
+
979
999
relation = NULL ; /* department of accident prevention */
980
1000
return address ;
981
1001
}
@@ -1008,6 +1028,7 @@ get_object_address_attribute(ObjectType objtype, List *objname,
1008
1028
errmsg ("column name must be qualified" )));
1009
1029
attname = strVal (lfirst (list_tail (objname )));
1010
1030
relname = list_truncate (list_copy (objname ), list_length (objname ) - 1 );
1031
+ /* XXX no missing_ok support here */
1011
1032
relation = relation_openrv (makeRangeVarFromNameList (relname ), lockmode );
1012
1033
reloid = RelationGetRelid (relation );
1013
1034
@@ -1053,7 +1074,7 @@ get_object_address_type(ObjectType objtype,
1053
1074
address .objectId = InvalidOid ;
1054
1075
address .objectSubId = 0 ;
1055
1076
1056
- tup = LookupTypeName (NULL , typename , NULL );
1077
+ tup = LookupTypeName (NULL , typename , NULL , missing_ok );
1057
1078
if (!HeapTupleIsValid (tup ))
1058
1079
{
1059
1080
if (!missing_ok )
@@ -1090,6 +1111,7 @@ get_object_address_opcf(ObjectType objtype,
1090
1111
ObjectAddress address ;
1091
1112
1092
1113
Assert (list_length (objargs ) == 1 );
1114
+ /* XXX no missing_ok support here */
1093
1115
amoid = get_am_oid (strVal (linitial (objargs )), false);
1094
1116
1095
1117
switch (objtype )
0 commit comments