Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0441e26

Browse files
committed
Make pltcl create separate function objects when the same function is
used as trigger on different relations. I am not convinced that Tcl actually has to have this, but it seems a good idea to make it be parallel to the other PLs that definitely do need it.
1 parent 96e6319 commit 0441e26

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/pl/tcl/pltcl.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* ENHANCEMENTS, OR MODIFICATIONS.
3232
*
3333
* IDENTIFICATION
34-
* $Header: /cvsroot/pgsql/src/pl/tcl/pltcl.c,v 1.77 2003/09/04 15:10:10 tgl Exp $
34+
* $Header: /cvsroot/pgsql/src/pl/tcl/pltcl.c,v 1.78 2003/09/14 17:25:54 tgl Exp $
3535
*
3636
**********************************************************************/
3737

@@ -156,7 +156,7 @@ static Datum pltcl_func_handler(PG_FUNCTION_ARGS);
156156

157157
static HeapTuple pltcl_trigger_handler(PG_FUNCTION_ARGS);
158158

159-
static pltcl_proc_desc *compile_pltcl_function(Oid fn_oid, bool is_trigger);
159+
static pltcl_proc_desc *compile_pltcl_function(Oid fn_oid, Oid tgreloid);
160160

161161
static int pltcl_elog(ClientData cdata, Tcl_Interp *interp,
162162
int argc, CONST84 char *argv[]);
@@ -462,7 +462,7 @@ pltcl_func_handler(PG_FUNCTION_ARGS)
462462
sigjmp_buf save_restart;
463463

464464
/* Find or compile the function */
465-
prodesc = compile_pltcl_function(fcinfo->flinfo->fn_oid, false);
465+
prodesc = compile_pltcl_function(fcinfo->flinfo->fn_oid, InvalidOid);
466466

467467
if (prodesc->lanpltrusted)
468468
interp = pltcl_safe_interp;
@@ -648,7 +648,8 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS)
648648
sigjmp_buf save_restart;
649649

650650
/* Find or compile the function */
651-
prodesc = compile_pltcl_function(fcinfo->flinfo->fn_oid, true);
651+
prodesc = compile_pltcl_function(fcinfo->flinfo->fn_oid,
652+
RelationGetRelid(trigdata->tg_relation));
652653

653654
if (prodesc->lanpltrusted)
654655
interp = pltcl_safe_interp;
@@ -956,13 +957,17 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS)
956957

957958
/**********************************************************************
958959
* compile_pltcl_function - compile (or hopefully just look up) function
960+
*
961+
* tgreloid is the OID of the relation when compiling a trigger, or zero
962+
* (InvalidOid) when compiling a plain function.
959963
**********************************************************************/
960964
static pltcl_proc_desc *
961-
compile_pltcl_function(Oid fn_oid, bool is_trigger)
965+
compile_pltcl_function(Oid fn_oid, Oid tgreloid)
962966
{
967+
bool is_trigger = OidIsValid(tgreloid);
963968
HeapTuple procTup;
964969
Form_pg_proc procStruct;
965-
char internal_proname[64];
970+
char internal_proname[128];
966971
Tcl_HashEntry *hashent;
967972
pltcl_proc_desc *prodesc = NULL;
968973
Tcl_Interp *interp;
@@ -986,7 +991,7 @@ compile_pltcl_function(Oid fn_oid, bool is_trigger)
986991
"__PLTcl_proc_%u", fn_oid);
987992
else
988993
snprintf(internal_proname, sizeof(internal_proname),
989-
"__PLTcl_proc_%u_trigger", fn_oid);
994+
"__PLTcl_proc_%u_trigger_%u", fn_oid, tgreloid);
990995

991996
/************************************************************
992997
* Lookup the internal proc name in the hashtable

0 commit comments

Comments
 (0)