Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit23e1084

Browse files
committed
When compiling a plpgsql trigger function, include the OID of the table
the trigger is attached to in the hashkey. This ensures that we willcreate separate compiled trees for each table the trigger is used with,avoiding possible datatype-mismatch problems if the tables have differentrowtypes. This is essentially the same bug recently identified in plpython--- though plpgsql doesn't seem as prone to crash when the rowtype changesunderneath it. But failing robustly is no substitute for just working.
1 parent1414903 commit23e1084

File tree

2 files changed

+37
-20
lines changed

2 files changed

+37
-20
lines changed

‎src/pl/plpgsql/src/pl_comp.c

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* procedural language
44
*
55
* IDENTIFICATION
6-
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.66 2003/08/08 19:19:32 tgl Exp $
6+
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.67 2003/08/18 19:16:02 tgl Exp $
77
*
88
* This software is copyrighted by Jan Wieck - Hamburg.
99
*
@@ -100,16 +100,16 @@ typedef struct plpgsql_hashent
100100
*/
101101
staticPLpgSQL_function*do_compile(FunctionCallInfofcinfo,
102102
HeapTupleprocTup,
103-
PLpgSQL_func_hashkey*hashkey);
103+
PLpgSQL_func_hashkey*hashkey);
104104
staticvoidplpgsql_compile_error_callback(void*arg);
105105
staticPLpgSQL_type*build_datatype(HeapTupletypeTup,int32typmod);
106-
staticvoidcompute_function_hashkey(FmgrInfo*flinfo,
106+
staticvoidcompute_function_hashkey(FunctionCallInfofcinfo,
107107
Form_pg_procprocStruct,
108-
PLpgSQL_func_hashkey*hashkey);
109-
staticPLpgSQL_function*plpgsql_HashTableLookup(PLpgSQL_func_hashkey*func_key);
110-
staticvoidplpgsql_HashTableInsert(PLpgSQL_function*function,
111-
PLpgSQL_func_hashkey*func_key);
112-
staticvoidplpgsql_HashTableDelete(PLpgSQL_function*function);
108+
PLpgSQL_func_hashkey*hashkey);
109+
staticPLpgSQL_function*plpgsql_HashTableLookup(PLpgSQL_func_hashkey*func_key);
110+
staticvoidplpgsql_HashTableInsert(PLpgSQL_function*function,
111+
PLpgSQL_func_hashkey*func_key);
112+
staticvoidplpgsql_HashTableDelete(PLpgSQL_function*function);
113113

114114
/*
115115
* This routine is a crock, and so is everyplace that calls it. The problem
@@ -169,7 +169,7 @@ plpgsql_compile(FunctionCallInfo fcinfo)
169169
plpgsql_HashTableInit();
170170

171171
/* Compute hashkey using function signature and actual arg types */
172-
compute_function_hashkey(fcinfo->flinfo,procStruct,&hashkey);
172+
compute_function_hashkey(fcinfo,procStruct,&hashkey);
173173
hashkey_valid= true;
174174

175175
/* And do the lookup */
@@ -203,7 +203,7 @@ plpgsql_compile(FunctionCallInfo fcinfo)
203203
* the completed function.
204204
*/
205205
if (!hashkey_valid)
206-
compute_function_hashkey(fcinfo->flinfo,procStruct,&hashkey);
206+
compute_function_hashkey(fcinfo,procStruct,&hashkey);
207207

208208
/*
209209
* Do the hard part.
@@ -230,7 +230,7 @@ plpgsql_compile(FunctionCallInfo fcinfo)
230230
staticPLpgSQL_function*
231231
do_compile(FunctionCallInfofcinfo,
232232
HeapTupleprocTup,
233-
PLpgSQL_func_hashkey*hashkey)
233+
PLpgSQL_func_hashkey*hashkey)
234234
{
235235
Form_pg_procprocStruct= (Form_pg_proc)GETSTRUCT(procTup);
236236
intfunctype=CALLED_AS_TRIGGER(fcinfo) ?T_TRIGGER :T_FUNCTION;
@@ -1711,16 +1711,25 @@ plpgsql_yyerror(const char *s)
17111711
* The hashkey is returned into the caller-provided storage at *hashkey.
17121712
*/
17131713
staticvoid
1714-
compute_function_hashkey(FmgrInfo*flinfo,
1714+
compute_function_hashkey(FunctionCallInfofcinfo,
17151715
Form_pg_procprocStruct,
1716-
PLpgSQL_func_hashkey*hashkey)
1716+
PLpgSQL_func_hashkey*hashkey)
17171717
{
17181718
inti;
17191719

17201720
/* Make sure any unused bytes of the struct are zero */
17211721
MemSet(hashkey,0,sizeof(PLpgSQL_func_hashkey));
17221722

1723-
hashkey->funcOid=flinfo->fn_oid;
1723+
/* get function OID */
1724+
hashkey->funcOid=fcinfo->flinfo->fn_oid;
1725+
1726+
/* if trigger, get relation OID */
1727+
if (CALLED_AS_TRIGGER(fcinfo))
1728+
{
1729+
TriggerData*trigdata= (TriggerData*)fcinfo->context;
1730+
1731+
hashkey->trigrelOid=RelationGetRelid(trigdata->tg_relation);
1732+
}
17241733

17251734
/* get the argument types */
17261735
for (i=0;i<procStruct->pronargs;i++)
@@ -1737,7 +1746,7 @@ compute_function_hashkey(FmgrInfo *flinfo,
17371746
if (argtypeid==ANYARRAYOID||argtypeid==ANYELEMENTOID||
17381747
argtypeid==ANYOID)
17391748
{
1740-
argtypeid=get_fn_expr_argtype(flinfo,i);
1749+
argtypeid=get_fn_expr_argtype(fcinfo->flinfo,i);
17411750
if (!OidIsValid(argtypeid))
17421751
ereport(ERROR,
17431752
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
@@ -1767,7 +1776,7 @@ plpgsql_HashTableInit(void)
17671776
}
17681777

17691778
staticPLpgSQL_function*
1770-
plpgsql_HashTableLookup(PLpgSQL_func_hashkey*func_key)
1779+
plpgsql_HashTableLookup(PLpgSQL_func_hashkey*func_key)
17711780
{
17721781
plpgsql_HashEnt*hentry;
17731782

@@ -1782,8 +1791,8 @@ plpgsql_HashTableLookup(PLpgSQL_func_hashkey * func_key)
17821791
}
17831792

17841793
staticvoid
1785-
plpgsql_HashTableInsert(PLpgSQL_function*function,
1786-
PLpgSQL_func_hashkey*func_key)
1794+
plpgsql_HashTableInsert(PLpgSQL_function*function,
1795+
PLpgSQL_func_hashkey*func_key)
17871796
{
17881797
plpgsql_HashEnt*hentry;
17891798
boolfound;
@@ -1805,7 +1814,7 @@ plpgsql_HashTableInsert(PLpgSQL_function * function,
18051814
}
18061815

18071816
staticvoid
1808-
plpgsql_HashTableDelete(PLpgSQL_function*function)
1817+
plpgsql_HashTableDelete(PLpgSQL_function*function)
18091818
{
18101819
plpgsql_HashEnt*hentry;
18111820

‎src/pl/plpgsql/src/plpgsql.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* procedural language
44
*
55
* IDENTIFICATION
6-
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/plpgsql.h,v 1.39 2003/08/04 00:43:33 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/plpgsql.h,v 1.40 2003/08/18 19:16:02 tgl Exp $
77
*
88
* This software is copyrighted by Jan Wieck - Hamburg.
99
*
@@ -491,6 +491,14 @@ typedef struct PLpgSQL_func_hashkey
491491
{/* Hash lookup key for functions */
492492
OidfuncOid;
493493

494+
/*
495+
* For a trigger function, the OID of the relation triggered on is part
496+
* of the hashkey --- we want to compile the trigger separately for each
497+
* relation it is used with, in case the rowtype is different. Zero if
498+
* not called as a trigger.
499+
*/
500+
OidtrigrelOid;
501+
494502
/*
495503
* We include actual argument types in the hash key to support
496504
* polymorphic PLpgSQL functions. Be careful that extra positions are

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp