From 08be00fabebfa5efb843c9464d994891d80121f5 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 25 Jan 2013 16:58:55 -0500 Subject: 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 46211da1b84bc3537e799ee1126098e71c2428e8 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 --- src/pl/plpython/plpy_main.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/pl/plpython/plpy_main.c') diff --git a/src/pl/plpython/plpy_main.c b/src/pl/plpython/plpy_main.c index 8b61f1a972f..0dad8439565 100644 --- a/src/pl/plpython/plpy_main.c +++ b/src/pl/plpython/plpy_main.c @@ -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); } -- cgit v1.2.3