summaryrefslogtreecommitdiff
path: root/src/include/catalog/objectaccess.h
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2013-03-17 22:55:14 -0400
committerRobert Haas <rhaas@postgresql.org>2013-03-17 22:57:26 -0400
commit05f3f9c7b2922b2a064418b5cd87b372d1b73412 (patch)
tree7532a7b338b36b659ddcfba50ebfcad22852e946 /src/include/catalog/objectaccess.h
parent6ac7facdd3990baf47efc124e9d7229422a06452 (diff)
downloadpostgresql-05f3f9c7b2922b2a064418b5cd87b372d1b73412.tar.gz
Extend object-access hook machinery to support post-alter events.
This also slightly widens the scope of what we support in terms of post-create events. KaiGai Kohei, with a few changes, mostly to the comments, by me
Diffstat (limited to 'src/include/catalog/objectaccess.h')
-rw-r--r--src/include/catalog/objectaccess.h49
1 files changed, 48 insertions, 1 deletions
diff --git a/src/include/catalog/objectaccess.h b/src/include/catalog/objectaccess.h
index b9bb1bcd2f..25f963b074 100644
--- a/src/include/catalog/objectaccess.h
+++ b/src/include/catalog/objectaccess.h
@@ -22,6 +22,11 @@
* OAT_DROP should be invoked just before deletion of objects; typically
* deleteOneObject(). Its arguments are packed within ObjectAccessDrop.
*
+ * OAT_POST_ALTER should be invoked just after the object is altered,
+ * but before the command counter is incremented. An extension using the
+ * hook can use SnapshotNow and SnapshotSelf to get the old and new
+ * versions of the tuple.
+ *
* Other types may be added in the future.
*/
typedef enum ObjectAccessType
@@ -57,20 +62,51 @@ typedef struct
} ObjectAccessDrop;
/*
- * Hook, and a macro to invoke it.
+ * Arguments of OAT_POST_ALTER event
*/
+typedef struct
+{
+ /*
+ * This identifier is used when system catalog takes two IDs
+ * to identify a particular tuple of the catalog.
+ * It is only used when the caller want to identify an entry
+ * of pg_inherits, pg_db_role_setting or pg_user_mapping.
+ * Elsewhere, InvalidOid should be set.
+ */
+ Oid auxiliary_id;
+
+ /*
+ * If this flag is set, the user hasn't requested that the object be
+ * altered, but we're doing it anyway for some internal reason.
+ * Permissions-checking hooks may want to skip checks if, say, we're
+ * alter the constraints of a temporary heap during CLUSTER.
+ */
+ bool is_internal;
+} ObjectAccessPostAlter;
+
+/* Plugin provides a hook function matching this signature. */
typedef void (*object_access_hook_type) (ObjectAccessType access,
Oid classId,
Oid objectId,
int subId,
void *arg);
+/* Plugin sets this variable to a suitable hook function. */
extern PGDLLIMPORT object_access_hook_type object_access_hook;
+/* Core code uses these functions to call the hook (see macros below). */
extern void RunObjectPostCreateHook(Oid classId, Oid objectId, int subId,
bool is_internal);
extern void RunObjectDropHook(Oid classId, Oid objectId, int subId,
int dropflags);
+extern void RunObjectPostAlterHook(Oid classId, Oid objectId, int subId,
+ Oid auxiliaryId, bool is_internal);
+
+/*
+ * The following macros are wrappers around the functions above; these should
+ * normally be used to invoke the hook in lieu of calling the above functions
+ * directly.
+ */
#define InvokeObjectPostCreateHook(classId,objectId,subId) \
InvokeObjectPostCreateHookArg((classId),(objectId),(subId),false)
@@ -90,4 +126,15 @@ extern void RunObjectDropHook(Oid classId, Oid objectId, int subId,
(dropflags)); \
} while(0)
+#define InvokeObjectPostAlterHook(classId,objectId,subId) \
+ InvokeObjectPostAlterHookArg((classId),(objectId),(subId), \
+ InvalidOid,false)
+#define InvokeObjectPostAlterHookArg(classId,objectId,subId, \
+ auxiliaryId,is_internal) \
+ do { \
+ if (object_access_hook) \
+ RunObjectPostAlterHook((classId),(objectId),(subId), \
+ (auxiliaryId),(is_internal)); \
+ } while(0)
+
#endif /* OBJECTACCESS_H */