summaryrefslogtreecommitdiff
path: root/src/pl/plpython/plpy_main.c
diff options
context:
space:
mode:
authorTom Lane2013-01-25 21:58:55 +0000
committerTom Lane2013-01-25 21:59:36 +0000
commit08be00fabebfa5efb843c9464d994891d80121f5 (patch)
tree6a0716181c814d904b927cecc5c0f84d4e7feb55 /src/pl/plpython/plpy_main.c
parentbb1e504951bbdb1931365b1c6d1b4e5f3a3043d1 (diff)
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
Diffstat (limited to 'src/pl/plpython/plpy_main.c')
-rw-r--r--src/pl/plpython/plpy_main.c10
1 files changed, 7 insertions, 3 deletions
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);
}