1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-03 15:22:11 +03:00

Make new event trigger facility actually do something.

Commit 3855968f32 added syntax, pg_dump,
psql support, and documentation, but the triggers didn't actually fire.
With this commit, they now do.  This is still a pretty basic facility
overall because event triggers do not get a whole lot of information
about what the user is trying to do unless you write them in C; and
there's still no option to fire them anywhere except at the very
beginning of the execution sequence, but it's better than nothing,
and a good building block for future work.

Along the way, add a regression test for ALTER LARGE OBJECT, since
testing of event triggers reveals that we haven't got one.

Dimitri Fontaine and Robert Haas
This commit is contained in:
Robert Haas
2012-07-20 11:38:47 -04:00
parent be86e3dd5b
commit 3a0e4d36eb
28 changed files with 1087 additions and 197 deletions

View File

@@ -16,6 +16,21 @@
#include "catalog/pg_event_trigger.h"
#include "nodes/parsenodes.h"
typedef struct EventTriggerData
{
NodeTag type;
char *event; /* event name */
Node *parsetree; /* parse tree */
const char *tag; /* command tag */
} EventTriggerData;
/*
* EventTriggerData is the node type that is passed as fmgr "context" info
* when a function is called by the event trigger manager.
*/
#define CALLED_AS_EVENT_TRIGGER(fcinfo) \
((fcinfo)->context != NULL && IsA((fcinfo)->context, EventTriggerData))
extern void CreateEventTrigger(CreateEventTrigStmt *stmt);
extern void RemoveEventTriggerById(Oid ctrigOid);
extern Oid get_event_trigger_oid(const char *trigname, bool missing_ok);
@@ -25,4 +40,7 @@ extern void RenameEventTrigger(const char* trigname, const char *newname);
extern void AlterEventTriggerOwner(const char *name, Oid newOwnerId);
extern void AlterEventTriggerOwner_oid(Oid, Oid newOwnerId);
extern bool EventTriggerSupportsObjectType(ObjectType obtype);
extern void EventTriggerDDLCommandStart(Node *parsetree);
#endif /* EVENT_TRIGGER_H */

View File

@@ -415,6 +415,7 @@ typedef enum NodeTag
* pass multiple object types through the same pointer).
*/
T_TriggerData = 950, /* in commands/trigger.h */
T_EventTriggerData, /* in commands/event_trigger.h */
T_ReturnSetInfo, /* in nodes/execnodes.h */
T_WindowObjectData, /* private in nodeWindowAgg.c */
T_TIDBitmap, /* in nodes/tidbitmap.h */

View File

@@ -443,6 +443,7 @@ extern int pqGethostbyname(const char *name,
extern void pg_qsort(void *base, size_t nel, size_t elsize,
int (*cmp) (const void *, const void *));
extern int pg_qsort_strcmp(const void *a, const void *b);
#define qsort(a,b,c,d) pg_qsort(a,b,c,d)

View File

@@ -16,19 +16,27 @@
#include "tcop/tcopprot.h"
typedef enum
{
PROCESS_UTILITY_TOPLEVEL, /* toplevel interactive command */
PROCESS_UTILITY_QUERY, /* a complete query, but not toplevel */
PROCESS_UTILITY_SUBCOMMAND, /* a piece of a query */
PROCESS_UTILITY_GENERATED /* internally generated node query node */
} ProcessUtilityContext;
/* Hook for plugins to get control in ProcessUtility() */
typedef void (*ProcessUtility_hook_type) (Node *parsetree,
const char *queryString, ParamListInfo params, bool isTopLevel,
DestReceiver *dest, char *completionTag);
const char *queryString, ParamListInfo params,
DestReceiver *dest, char *completionTag,
ProcessUtilityContext context);
extern PGDLLIMPORT ProcessUtility_hook_type ProcessUtility_hook;
extern void ProcessUtility(Node *parsetree, const char *queryString,
ParamListInfo params, bool isTopLevel,
DestReceiver *dest, char *completionTag);
ParamListInfo params, DestReceiver *dest, char *completionTag,
ProcessUtilityContext context);
extern void standard_ProcessUtility(Node *parsetree, const char *queryString,
ParamListInfo params, bool isTopLevel,
DestReceiver *dest, char *completionTag);
ParamListInfo params, DestReceiver *dest,
char *completionTag, ProcessUtilityContext context);
extern bool UtilityReturnsTuples(Node *parsetree);

View File

@@ -0,0 +1,34 @@
/*-------------------------------------------------------------------------
*
* evtcache.c
* Special-purpose cache for event trigger data.
*
* Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* src/backend/utils/cache/evtcache.c
*
*-------------------------------------------------------------------------
*/
#ifndef EVTCACHE_H
#define EVTCACHE_H
#include "nodes/pg_list.h"
typedef enum
{
EVT_DDLCommandStart
} EventTriggerEvent;
typedef struct
{
Oid fnoid; /* function to be called */
char enabled; /* as SESSION_REPLICATION_ROLE_* */
int ntags; /* number of command tags */
char **tag; /* command tags in SORTED order */
} EventTriggerCacheItem;
extern List *EventCacheLookup(EventTriggerEvent event);
#endif /* EVTCACHE_H */