External triggers
This commit is contained in:
parent
5a31d7a9ad
commit
0be0a58bc9
4 changed files with 11 additions and 7 deletions
|
|
@ -747,6 +747,8 @@ CreateIvmTrigger(Oid relOid, ImmvAddress immv_addr, int16 type, int16 timing, bo
|
||||||
if (type == TRIGGER_TYPE_DELETE || type == TRIGGER_TYPE_UPDATE)
|
if (type == TRIGGER_TYPE_DELETE || type == TRIGGER_TYPE_UPDATE)
|
||||||
ex_lock = true;
|
ex_lock = true;
|
||||||
|
|
||||||
|
ivm_trigger->trigname = psprintf("%s_%d_%d", ivm_trigger->trigname, relOid,
|
||||||
|
immv_addr.address.objectId);
|
||||||
ivm_trigger->funcname =
|
ivm_trigger->funcname =
|
||||||
(timing == TRIGGER_TYPE_BEFORE ?
|
(timing == TRIGGER_TYPE_BEFORE ?
|
||||||
PgIvmFuncName("IVM_immediate_before") : PgIvmFuncName("IVM_immediate_maintenance"));
|
PgIvmFuncName("IVM_immediate_before") : PgIvmFuncName("IVM_immediate_maintenance"));
|
||||||
|
|
@ -759,12 +761,12 @@ CreateIvmTrigger(Oid relOid, ImmvAddress immv_addr, int16 type, int16 timing, bo
|
||||||
ivm_trigger->initdeferred = false;
|
ivm_trigger->initdeferred = false;
|
||||||
ivm_trigger->constrrel = NULL;
|
ivm_trigger->constrrel = NULL;
|
||||||
ivm_trigger->args = list_make2(
|
ivm_trigger->args = list_make2(
|
||||||
makeString(DatumGetPointer(UUIDPGetDatum(&immv_addr.immv_uuid))),
|
makeString(DatumGetPointer(DirectFunctionCall1(uuid_out, UUIDPGetDatum(&immv_addr.immv_uuid)))),
|
||||||
makeString(DatumGetPointer(DirectFunctionCall1(boolout, BoolGetDatum(ex_lock))))
|
makeString(DatumGetPointer(DirectFunctionCall1(boolout, BoolGetDatum(ex_lock))))
|
||||||
);
|
);
|
||||||
|
|
||||||
address = CreateTrigger(ivm_trigger, NULL, relOid, InvalidOid, InvalidOid,
|
address = CreateTrigger(ivm_trigger, NULL, relOid, InvalidOid, InvalidOid,
|
||||||
InvalidOid, InvalidOid, InvalidOid, NULL, true, false);
|
InvalidOid, InvalidOid, InvalidOid, NULL, false, false);
|
||||||
|
|
||||||
recordDependencyOn(&address, &refaddr, DEPENDENCY_AUTO);
|
recordDependencyOn(&address, &refaddr, DEPENDENCY_AUTO);
|
||||||
|
|
||||||
|
|
@ -1733,7 +1735,7 @@ StoreImmvQuery(ImmvAddress immv_addr, Query *viewQuery)
|
||||||
*/
|
*/
|
||||||
save_nestlevel = NewGUCNestLevel();
|
save_nestlevel = NewGUCNestLevel();
|
||||||
RestrictSearchPath();
|
RestrictSearchPath();
|
||||||
matviewRel = table_open(viewOid, AccessShareLock);
|
matviewRel = table_open(immv_addr.address.objectId, AccessShareLock);
|
||||||
querystring = pg_ivm_get_viewdef_internal(viewQuery, matviewRel, true);
|
querystring = pg_ivm_get_viewdef_internal(viewQuery, matviewRel, true);
|
||||||
table_close(matviewRel, NoLock);
|
table_close(matviewRel, NoLock);
|
||||||
/* Roll back the search_path change. */
|
/* Roll back the search_path change. */
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#include "postgres.h"
|
#include "postgres.h"
|
||||||
#include "pg_ivm.h"
|
#include "pg_ivm.h"
|
||||||
|
|
||||||
|
#include "access/genam.h"
|
||||||
#include "access/table.h"
|
#include "access/table.h"
|
||||||
#include "catalog/indexing.h"
|
#include "catalog/indexing.h"
|
||||||
#include "commands/event_trigger.h"
|
#include "commands/event_trigger.h"
|
||||||
|
|
|
||||||
|
|
@ -857,7 +857,7 @@ IVM_immediate_before(PG_FUNCTION_ARGS)
|
||||||
bool found;
|
bool found;
|
||||||
bool ex_lock;
|
bool ex_lock;
|
||||||
|
|
||||||
immv_uuid = DatumGetUUIDP(CStringGetDatum(immv_uuid_text));
|
immv_uuid = DatumGetUUIDP(DirectFunctionCall1(uuid_in, (CStringGetDatum(immv_uuid_text))));
|
||||||
ex_lock = DatumGetBool(DirectFunctionCall1(boolin, CStringGetDatum(ex_lock_text)));
|
ex_lock = DatumGetBool(DirectFunctionCall1(boolin, CStringGetDatum(ex_lock_text)));
|
||||||
matviewOid = GetImmvRelid(immv_uuid);
|
matviewOid = GetImmvRelid(immv_uuid);
|
||||||
|
|
||||||
|
|
@ -1006,7 +1006,7 @@ IVM_immediate_maintenance(PG_FUNCTION_ARGS)
|
||||||
rel = trigdata->tg_relation;
|
rel = trigdata->tg_relation;
|
||||||
relid = rel->rd_id;
|
relid = rel->rd_id;
|
||||||
|
|
||||||
immv_uuid = DatumGetUUIDP(CStringGetDatum(immv_uuid_text));
|
immv_uuid = DatumGetUUIDP(DirectFunctionCall1(uuid_in, (CStringGetDatum(immv_uuid_text))));
|
||||||
matviewOid = GetImmvRelid(immv_uuid);
|
matviewOid = GetImmvRelid(immv_uuid);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
5
pg_ivm.c
5
pg_ivm.c
|
|
@ -320,7 +320,6 @@ CreateChangePreventTrigger(Oid matviewOid)
|
||||||
ivm_trigger->row = false;
|
ivm_trigger->row = false;
|
||||||
|
|
||||||
ivm_trigger->timing = TRIGGER_TYPE_BEFORE;
|
ivm_trigger->timing = TRIGGER_TYPE_BEFORE;
|
||||||
ivm_trigger->trigname = "IVM_prevent_immv_change";
|
|
||||||
ivm_trigger->funcname = PgIvmFuncName("IVM_prevent_immv_change");
|
ivm_trigger->funcname = PgIvmFuncName("IVM_prevent_immv_change");
|
||||||
ivm_trigger->columns = NIL;
|
ivm_trigger->columns = NIL;
|
||||||
ivm_trigger->transitionRels = NIL;
|
ivm_trigger->transitionRels = NIL;
|
||||||
|
|
@ -334,8 +333,10 @@ CreateChangePreventTrigger(Oid matviewOid)
|
||||||
for (i = 0; i < 4; i++)
|
for (i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
ivm_trigger->events = types[i];
|
ivm_trigger->events = types[i];
|
||||||
|
ivm_trigger->trigname = psprintf("IVM_prevent_immv_change_%d_%d",
|
||||||
|
matviewOid, i + 1);
|
||||||
address = CreateTrigger(ivm_trigger, NULL, matviewOid, InvalidOid, InvalidOid,
|
address = CreateTrigger(ivm_trigger, NULL, matviewOid, InvalidOid, InvalidOid,
|
||||||
InvalidOid, InvalidOid, InvalidOid, NULL, true, false);
|
InvalidOid, InvalidOid, InvalidOid, NULL, false, false);
|
||||||
|
|
||||||
recordDependencyOn(&address, &refaddr, DEPENDENCY_AUTO);
|
recordDependencyOn(&address, &refaddr, DEPENDENCY_AUTO);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue