diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2008-03-28 00:21:56 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2008-03-28 00:21:56 +0000 |
commit | 7692d8d5b72f510bd84f708d0a8e53c548f71adc (patch) | |
tree | 2db349ab412c7353734bfd232fbba8c5261913a0 /src/include | |
parent | 107b3d0c23b52cf20b705d00200211d8cc341f52 (diff) | |
download | postgresql-7692d8d5b72f510bd84f708d0a8e53c548f71adc.tar.gz postgresql-7692d8d5b72f510bd84f708d0a8e53c548f71adc.zip |
Support statement-level ON TRUNCATE triggers. Simon Riggs
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/catalog/pg_trigger.h | 5 | ||||
-rw-r--r-- | src/include/commands/trigger.h | 21 | ||||
-rw-r--r-- | src/include/executor/executor.h | 7 | ||||
-rw-r--r-- | src/include/utils/rel.h | 7 |
4 files changed, 32 insertions, 8 deletions
diff --git a/src/include/catalog/pg_trigger.h b/src/include/catalog/pg_trigger.h index 84d3f69ce53..f6e1675b05f 100644 --- a/src/include/catalog/pg_trigger.h +++ b/src/include/catalog/pg_trigger.h @@ -8,7 +8,7 @@ * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/catalog/pg_trigger.h,v 1.31 2008/03/27 03:57:34 tgl Exp $ + * $PostgreSQL: pgsql/src/include/catalog/pg_trigger.h,v 1.32 2008/03/28 00:21:56 tgl Exp $ * * NOTES * the genbki.sh script reads this file and generates .bki @@ -89,6 +89,7 @@ typedef FormData_pg_trigger *Form_pg_trigger; #define TRIGGER_TYPE_INSERT (1 << 2) #define TRIGGER_TYPE_DELETE (1 << 3) #define TRIGGER_TYPE_UPDATE (1 << 4) +#define TRIGGER_TYPE_TRUNCATE (1 << 5) /* Macros for manipulating tgtype */ #define TRIGGER_CLEAR_TYPE(type) ((type) = 0) @@ -98,11 +99,13 @@ typedef FormData_pg_trigger *Form_pg_trigger; #define TRIGGER_SETT_INSERT(type) ((type) |= TRIGGER_TYPE_INSERT) #define TRIGGER_SETT_DELETE(type) ((type) |= TRIGGER_TYPE_DELETE) #define TRIGGER_SETT_UPDATE(type) ((type) |= TRIGGER_TYPE_UPDATE) +#define TRIGGER_SETT_TRUNCATE(type) ((type) |= TRIGGER_TYPE_TRUNCATE) #define TRIGGER_FOR_ROW(type) ((type) & TRIGGER_TYPE_ROW) #define TRIGGER_FOR_BEFORE(type) ((type) & TRIGGER_TYPE_BEFORE) #define TRIGGER_FOR_INSERT(type) ((type) & TRIGGER_TYPE_INSERT) #define TRIGGER_FOR_DELETE(type) ((type) & TRIGGER_TYPE_DELETE) #define TRIGGER_FOR_UPDATE(type) ((type) & TRIGGER_TYPE_UPDATE) +#define TRIGGER_FOR_TRUNCATE(type) ((type) & TRIGGER_TYPE_TRUNCATE) #endif /* PG_TRIGGER_H */ diff --git a/src/include/commands/trigger.h b/src/include/commands/trigger.h index 5e0dda4744d..174b6507d1a 100644 --- a/src/include/commands/trigger.h +++ b/src/include/commands/trigger.h @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/commands/trigger.h,v 1.66 2008/01/02 23:34:42 tgl Exp $ + * $PostgreSQL: pgsql/src/include/commands/trigger.h,v 1.67 2008/03/28 00:21:56 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -38,11 +38,18 @@ typedef struct TriggerData Buffer tg_newtuplebuf; } TriggerData; -/* TriggerEvent bit flags */ - +/* + * TriggerEvent bit flags + * + * Note that we assume different event types (INSERT/DELETE/UPDATE/TRUNCATE) + * can't be OR'd together in a single TriggerEvent. This is unlike the + * situation for pg_trigger rows, so pg_trigger.tgtype uses a different + * representation! + */ #define TRIGGER_EVENT_INSERT 0x00000000 #define TRIGGER_EVENT_DELETE 0x00000001 #define TRIGGER_EVENT_UPDATE 0x00000002 +#define TRIGGER_EVENT_TRUNCATE 0x00000003 #define TRIGGER_EVENT_OPMASK 0x00000003 #define TRIGGER_EVENT_ROW 0x00000004 #define TRIGGER_EVENT_BEFORE 0x00000008 @@ -66,6 +73,10 @@ typedef struct TriggerData (((TriggerEvent) (event) & TRIGGER_EVENT_OPMASK) == \ TRIGGER_EVENT_UPDATE) +#define TRIGGER_FIRED_BY_TRUNCATE(event) \ + (((TriggerEvent) (event) & TRIGGER_EVENT_OPMASK) == \ + TRIGGER_EVENT_TRUNCATE) + #define TRIGGER_FIRED_FOR_ROW(event) \ ((TriggerEvent) (event) & TRIGGER_EVENT_ROW) @@ -140,6 +151,10 @@ extern void ExecARUpdateTriggers(EState *estate, ResultRelInfo *relinfo, ItemPointer tupleid, HeapTuple newtuple); +extern void ExecBSTruncateTriggers(EState *estate, + ResultRelInfo *relinfo); +extern void ExecASTruncateTriggers(EState *estate, + ResultRelInfo *relinfo); extern void AfterTriggerBeginXact(void); extern void AfterTriggerBeginQuery(void); diff --git a/src/include/executor/executor.h b/src/include/executor/executor.h index 7dc8b8d63a8..2a920cebb9a 100644 --- a/src/include/executor/executor.h +++ b/src/include/executor/executor.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/executor/executor.h,v 1.146 2008/01/01 19:45:57 momjian Exp $ + * $PostgreSQL: pgsql/src/include/executor/executor.h,v 1.147 2008/03/28 00:21:56 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -138,6 +138,11 @@ extern TupleTableSlot *ExecutorRun(QueryDesc *queryDesc, ScanDirection direction, long count); extern void ExecutorEnd(QueryDesc *queryDesc); extern void ExecutorRewind(QueryDesc *queryDesc); +extern void InitResultRelInfo(ResultRelInfo *resultRelInfo, + Relation resultRelationDesc, + Index resultRelationIndex, + CmdType operation, + bool doInstrument); extern ResultRelInfo *ExecGetTriggerResultRel(EState *estate, Oid relid); extern bool ExecContextForcesOids(PlanState *planstate, bool *hasoids); extern void ExecConstraints(ResultRelInfo *resultRelInfo, diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 340b24a77f3..f7d46193de5 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/utils/rel.h,v 1.104 2008/01/01 19:45:59 momjian Exp $ + * $PostgreSQL: pgsql/src/include/utils/rel.h,v 1.105 2008/03/28 00:21:56 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -71,9 +71,10 @@ typedef struct TriggerDesc /* * Index data to identify which triggers are which. Since each trigger * can appear in more than one class, for each class we provide a list of - * integer indexes into the triggers array. + * integer indexes into the triggers array. The class codes are defined + * by TRIGGER_EVENT_xxx macros in commands/trigger.h. */ -#define TRIGGER_NUM_EVENT_CLASSES 3 +#define TRIGGER_NUM_EVENT_CLASSES 4 uint16 n_before_statement[TRIGGER_NUM_EVENT_CLASSES]; uint16 n_before_row[TRIGGER_NUM_EVENT_CLASSES]; |