mirror of
https://github.com/postgres/postgres.git
synced 2025-06-16 06:01:02 +03:00
Fix plpython's handling of functions used as triggers on multiple tables.
plpython tried to use a single cache entry for a trigger function, but it
needs a separate cache entry for each table the trigger is applied to,
because there is table-dependent data in there. This was done correctly
before 9.1, but commit 46211da1b8
broke it
by simplifying the lookup key from "function OID and triggered table OID"
to "function OID and is-trigger boolean". Go back to using both OIDs
as the lookup key. Per bug report from Sandro Santilli.
Andres Freund
This commit is contained in:
@ -14,6 +14,7 @@
|
||||
#include "miscadmin.h"
|
||||
#include "utils/guc.h"
|
||||
#include "utils/memutils.h"
|
||||
#include "utils/rel.h"
|
||||
#include "utils/syscache.h"
|
||||
|
||||
#include "plpython.h"
|
||||
@ -174,7 +175,8 @@ plpython_validator(PG_FUNCTION_ARGS)
|
||||
|
||||
ReleaseSysCache(tuple);
|
||||
|
||||
PLy_procedure_get(funcoid, is_trigger);
|
||||
/* We can't validate triggers against any particular table ... */
|
||||
PLy_procedure_get(funcoid, InvalidOid, is_trigger);
|
||||
|
||||
PG_RETURN_VOID();
|
||||
}
|
||||
@ -215,20 +217,22 @@ plpython_call_handler(PG_FUNCTION_ARGS)
|
||||
|
||||
PG_TRY();
|
||||
{
|
||||
Oid funcoid = fcinfo->flinfo->fn_oid;
|
||||
PLyProcedure *proc;
|
||||
|
||||
if (CALLED_AS_TRIGGER(fcinfo))
|
||||
{
|
||||
Relation tgrel = ((TriggerData *) fcinfo->context)->tg_relation;
|
||||
HeapTuple trv;
|
||||
|
||||
proc = PLy_procedure_get(fcinfo->flinfo->fn_oid, true);
|
||||
proc = PLy_procedure_get(funcoid, RelationGetRelid(tgrel), true);
|
||||
exec_ctx->curr_proc = proc;
|
||||
trv = PLy_exec_trigger(fcinfo, proc);
|
||||
retval = PointerGetDatum(trv);
|
||||
}
|
||||
else
|
||||
{
|
||||
proc = PLy_procedure_get(fcinfo->flinfo->fn_oid, false);
|
||||
proc = PLy_procedure_get(funcoid, InvalidOid, false);
|
||||
exec_ctx->curr_proc = proc;
|
||||
retval = PLy_exec_function(fcinfo, proc);
|
||||
}
|
||||
|
Reference in New Issue
Block a user