1 /*-------------------------------------------------------------------------
2  *
3  * objectaddress.h
4  *	  functions for working with object addresses
5  *
6  * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  * src/include/catalog/objectaddress.h
10  *
11  *-------------------------------------------------------------------------
12  */
13 #ifndef OBJECTADDRESS_H
14 #define OBJECTADDRESS_H
15 
16 #include "access/htup.h"
17 #include "nodes/parsenodes.h"
18 #include "storage/lockdefs.h"
19 #include "utils/relcache.h"
20 
21 /*
22  * An ObjectAddress represents a database object of any type.
23  */
24 typedef struct ObjectAddress
25 {
26 	Oid			classId;		/* Class Id from pg_class */
27 	Oid			objectId;		/* OID of the object */
28 	int32		objectSubId;	/* Subitem within object (eg column), or 0 */
29 } ObjectAddress;
30 
31 extern const ObjectAddress InvalidObjectAddress;
32 
33 #define ObjectAddressSubSet(addr, class_id, object_id, object_sub_id) \
34 	do { \
35 		(addr).classId = (class_id); \
36 		(addr).objectId = (object_id); \
37 		(addr).objectSubId = (object_sub_id); \
38 	} while (0)
39 
40 #define ObjectAddressSet(addr, class_id, object_id) \
41 	ObjectAddressSubSet(addr, class_id, object_id, 0)
42 
43 extern ObjectAddress get_object_address(ObjectType objtype, Node *object,
44 										Relation *relp,
45 										LOCKMODE lockmode, bool missing_ok);
46 
47 extern ObjectAddress get_object_address_rv(ObjectType objtype, RangeVar *rel,
48 										   List *object, Relation *relp,
49 										   LOCKMODE lockmode, bool missing_ok);
50 
51 extern void check_object_ownership(Oid roleid,
52 								   ObjectType objtype, ObjectAddress address,
53 								   Node *object, Relation relation);
54 
55 extern Oid	get_object_namespace(const ObjectAddress *address);
56 
57 extern bool is_objectclass_supported(Oid class_id);
58 extern const char *get_object_class_descr(Oid class_id);
59 extern Oid	get_object_oid_index(Oid class_id);
60 extern int	get_object_catcache_oid(Oid class_id);
61 extern int	get_object_catcache_name(Oid class_id);
62 extern AttrNumber get_object_attnum_oid(Oid class_id);
63 extern AttrNumber get_object_attnum_name(Oid class_id);
64 extern AttrNumber get_object_attnum_namespace(Oid class_id);
65 extern AttrNumber get_object_attnum_owner(Oid class_id);
66 extern AttrNumber get_object_attnum_acl(Oid class_id);
67 extern ObjectType get_object_type(Oid class_id, Oid object_id);
68 extern bool get_object_namensp_unique(Oid class_id);
69 
70 extern HeapTuple get_catalog_object_by_oid(Relation catalog,
71 										   AttrNumber oidcol, Oid objectId);
72 
73 extern char *getObjectDescription(const ObjectAddress *object,
74 								  bool missing_ok);
75 extern char *getObjectDescriptionOids(Oid classid, Oid objid);
76 
77 extern int	read_objtype_from_string(const char *objtype);
78 extern char *getObjectTypeDescription(const ObjectAddress *object,
79 									  bool missing_ok);
80 extern char *getObjectIdentity(const ObjectAddress *address,
81 							   bool missing_ok);
82 extern char *getObjectIdentityParts(const ObjectAddress *address,
83 									List **objname, List **objargs,
84 									bool missing_ok);
85 extern struct ArrayType *strlist_to_textarray(List *list);
86 
87 extern ObjectType get_relkind_objtype(char relkind);
88 
89 #endif							/* OBJECTADDRESS_H */
90