aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2010-11-03 12:26:55 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2010-11-03 12:26:55 -0400
commit70a0160b07b66dc7fa1555c489330ea8fb58f8fe (patch)
tree6a01c5e3a8b809b87f48a95c784f37c0d3e3bbd9 /src
parentdd21f0b047078ae724c0de4bc87b175154a83707 (diff)
downloadpostgresql-70a0160b07b66dc7fa1555c489330ea8fb58f8fe.tar.gz
postgresql-70a0160b07b66dc7fa1555c489330ea8fb58f8fe.zip
Use only one hash entry for all instances of a pltcl trigger function.
Like plperl and unlike plpgsql, there isn't any cached state that could depend on exactly which relation the trigger is being fired for. So we can use just one hash entry for all relations, which might save a little something. Alex Hunsaker
Diffstat (limited to 'src')
-rw-r--r--src/pl/tcl/pltcl.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/pl/tcl/pltcl.c b/src/pl/tcl/pltcl.c
index 2f0108c3d4c..6e8c5c05b5a 100644
--- a/src/pl/tcl/pltcl.c
+++ b/src/pl/tcl/pltcl.c
@@ -137,7 +137,7 @@ typedef struct pltcl_query_desc
/**********************************************************************
* For speedy lookup, we maintain a hash table mapping from
- * function OID + trigger OID + user OID to pltcl_proc_desc pointers.
+ * function OID + trigger flag + user OID to pltcl_proc_desc pointers.
* The reason the pltcl_proc_desc struct isn't directly part of the hash
* entry is to simplify recovery from errors during compile_pltcl_function.
*
@@ -149,7 +149,11 @@ typedef struct pltcl_query_desc
typedef struct pltcl_proc_key
{
Oid proc_id; /* Function OID */
- Oid trig_id; /* Trigger OID, or 0 if not trigger */
+ /*
+ * is_trigger is really a bool, but declare as Oid to ensure this struct
+ * contains no padding
+ */
+ Oid is_trigger; /* is it a trigger function? */
Oid user_id; /* User calling the function, or 0 */
} pltcl_proc_key;
@@ -1172,7 +1176,7 @@ compile_pltcl_function(Oid fn_oid, Oid tgreloid, bool pltrusted)
/* Try to find function in pltcl_proc_htab */
proc_key.proc_id = fn_oid;
- proc_key.trig_id = tgreloid;
+ proc_key.is_trigger = OidIsValid(tgreloid);
proc_key.user_id = pltrusted ? GetUserId() : InvalidOid;
proc_ptr = hash_search(pltcl_proc_htab, &proc_key,
@@ -1228,14 +1232,16 @@ compile_pltcl_function(Oid fn_oid, Oid tgreloid, bool pltrusted)
int tcl_rc;
/************************************************************
- * Build our internal proc name from the functions Oid + trigger Oid
+ * Build our internal proc name from the function's Oid. Append
+ * "_trigger" when appropriate to ensure the normal and trigger
+ * cases are kept separate.
************************************************************/
if (!is_trigger)
snprintf(internal_proname, sizeof(internal_proname),
"__PLTcl_proc_%u", fn_oid);
else
snprintf(internal_proname, sizeof(internal_proname),
- "__PLTcl_proc_%u_trigger_%u", fn_oid, tgreloid);
+ "__PLTcl_proc_%u_trigger", fn_oid);
/************************************************************
* Allocate a new procedure description block