pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #6511: calling spi_exec_query from non-main package, results in: couldn't fetch $_TD
7+ messages / 5 participants
[nested] [flat]
* BUG #6511: calling spi_exec_query from non-main package, results in: couldn't fetch $_TD
@ 2012-03-03 19:19 marko@kobaz.net
2012-03-07 04:08 ` Re: BUG #6511: calling spi_exec_query from non-main package, results in: couldn't fetch $_TD Alex Hunsaker <badalex@gmail.com>
0 siblings, 1 reply; 7+ messages in thread
From: marko@kobaz.net @ 2012-03-03 19:19 UTC (permalink / raw)
To: pgsql-bugs
The following bug has been logged on the website:
Bug reference: 6511
Logged by: Mark Murawski
Email address: marko@kobaz.net
PostgreSQL version: 9.1.3
Operating system: Linux - Debian Squeeze postgres 9.1 from backports
Description:
create table mytable ( id integer );
--
CREATE OR REPLACE FUNCTION mytrigger() RETURNS trigger AS $BODY$
return undef
$BODY$ LANGUAGE plperlu VOLATILE COST 100;
--
CREATE TRIGGER "insert" BEFORE INSERT ON mytable FOR EACH ROW EXECUTE
PROCEDURE mytrigger();
--
CREATE OR REPLACE FUNCTION myfunc() RETURNS text AS $BODY$
package foo;
sub foo {
main::spi_exec_query(q{INSERT INTO mytable VALUES (1) RETURNING id});
};
package main;
foo::foo();
return;
$BODY$ LANGUAGE plperlu VOLATILE COST 100;
--
pbx=# select * from myfunc();
ERROR: couldn't fetch $_TD at line 4.
CONTEXT: PL/Perl function "myfunc"
-- this works:
CREATE OR REPLACE FUNCTION myfunc() RETURNS text AS $BODY$
package foo;
sub foo {
package main;
spi_exec_query(q{INSERT INTO mytable VALUES (1) RETURNING id});
};
package main;
foo::foo();
return;
$BODY$ LANGUAGE plperlu VOLATILE COST 100;
select * from myfunc();
myfunc
--------
(1 row)
drop table mytable;
drop function mytrigger();
drop function myfunc();
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: BUG #6511: calling spi_exec_query from non-main package, results in: couldn't fetch $_TD
2012-03-03 19:19 BUG #6511: calling spi_exec_query from non-main package, results in: couldn't fetch $_TD marko@kobaz.net
@ 2012-03-07 04:08 ` Alex Hunsaker <badalex@gmail.com>
2012-03-15 22:13 ` Re: BUG #6511: calling spi_exec_query from non-main package, results in: couldn't fetch $_TD Bruce Momjian <bruce@momjian.us>
2012-03-19 20:40 ` Re: BUG #6511: calling spi_exec_query from non-main package, results in: couldn't fetch $_TD Alvaro Herrera <alvherre@commandprompt.com>
0 siblings, 2 replies; 7+ messages in thread
From: Alex Hunsaker @ 2012-03-07 04:08 UTC (permalink / raw)
To: marko@kobaz.net; +Cc: pgsql-bugs
On Sat, Mar 3, 2012 at 12:19, <marko@kobaz.net> wrote:
> The following bug has been logged on the website:
>
> Bug reference: 6511
> Logged by: Mark Murawski
> Email address: marko@kobaz.net
> PostgreSQL version: 9.1.3
> Operating system: Linux - Debian Squeeze postgres 9.1 from backports
> Description:
>
> CREATE OR REPLACE FUNCTION myfunc() RETURNS text AS $BODY$
> package foo;
> sub foo {
> main::spi_exec_query(q{INSERT INTO mytable VALUES (1) RETURNING id});
> };
>
> package main;
> foo::foo();
> return;
> $BODY$ LANGUAGE plperlu VOLATILE COST 100;
>
> --
>
> pbx=# select * from myfunc();
> ERROR: couldn't fetch $_TD at line 4.
> CONTEXT: PL/Perl function "myfunc"
[ Calling a plperl trigger function from a plperl function ]
Yeah, there were some optimization done for 9.1 to try and make calls
a bit faster. The problem is we are fetching "_TD" not "main::_TD",
which means we try to find and use $_TD from whatever the current
package is. This should only happen from a nested plperl to plperl
trigger where the outer call was in a different package, otherwise the
package is always main.
The attached fixes it for me, It would be great if you could confirm that.
Thanks for the report!
Attachments:
plperl_nested_pkg_trigger.patch (text/x-patch, 419B) download
*** a/src/pl/plperl/plperl.c
--- b/src/pl/plperl/plperl.c
***************
*** 2062,2068 **** plperl_call_perl_trigger_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo,
ENTER;
SAVETMPS;
! TDsv = get_sv("_TD", 0);
if (!TDsv)
elog(ERROR, "couldn't fetch $_TD");
--- 2062,2068 ----
ENTER;
SAVETMPS;
! TDsv = get_sv("main::_TD", 0);
if (!TDsv)
elog(ERROR, "couldn't fetch $_TD");
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: BUG #6511: calling spi_exec_query from non-main package, results in: couldn't fetch $_TD
2012-03-03 19:19 BUG #6511: calling spi_exec_query from non-main package, results in: couldn't fetch $_TD marko@kobaz.net
2012-03-07 04:08 ` Re: BUG #6511: calling spi_exec_query from non-main package, results in: couldn't fetch $_TD Alex Hunsaker <badalex@gmail.com>
@ 2012-03-15 22:13 ` Bruce Momjian <bruce@momjian.us>
2012-03-16 17:48 ` Re: BUG #6511: calling spi_exec_query from non-main package, results in: couldn't fetch $_TD Alex Hunsaker <badalex@gmail.com>
1 sibling, 1 reply; 7+ messages in thread
From: Bruce Momjian @ 2012-03-15 22:13 UTC (permalink / raw)
To: Alex Hunsaker <badalex@gmail.com>; +Cc: marko@kobaz.net; pgsql-bugs
On Tue, Mar 06, 2012 at 09:08:25PM -0700, Alex Hunsaker wrote:
> [ Calling a plperl trigger function from a plperl function ]
>
> Yeah, there were some optimization done for 9.1 to try and make calls
> a bit faster. The problem is we are fetching "_TD" not "main::_TD",
> which means we try to find and use $_TD from whatever the current
> package is. This should only happen from a nested plperl to plperl
> trigger where the outer call was in a different package, otherwise the
> package is always main.
>
> The attached fixes it for me, It would be great if you could confirm that.
>
> Thanks for the report!
So, should this be applied?
---------------------------------------------------------------------------
> *** a/src/pl/plperl/plperl.c
> --- b/src/pl/plperl/plperl.c
> ***************
> *** 2062,2068 **** plperl_call_perl_trigger_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo,
> ENTER;
> SAVETMPS;
>
> ! TDsv = get_sv("_TD", 0);
> if (!TDsv)
> elog(ERROR, "couldn't fetch $_TD");
>
> --- 2062,2068 ----
> ENTER;
> SAVETMPS;
>
> ! TDsv = get_sv("main::_TD", 0);
> if (!TDsv)
> elog(ERROR, "couldn't fetch $_TD");
>
>
> --
> Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-bugs
--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com
+ It's impossible for everything to be true. +
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: BUG #6511: calling spi_exec_query from non-main package, results in: couldn't fetch $_TD
2012-03-03 19:19 BUG #6511: calling spi_exec_query from non-main package, results in: couldn't fetch $_TD marko@kobaz.net
2012-03-07 04:08 ` Re: BUG #6511: calling spi_exec_query from non-main package, results in: couldn't fetch $_TD Alex Hunsaker <badalex@gmail.com>
2012-03-15 22:13 ` Re: BUG #6511: calling spi_exec_query from non-main package, results in: couldn't fetch $_TD Bruce Momjian <bruce@momjian.us>
@ 2012-03-16 17:48 ` Alex Hunsaker <badalex@gmail.com>
2012-03-18 04:11 ` Re: BUG #6511: calling spi_exec_query from non-main package, results in: couldn't fetch $_TD Mark M. <marko@kobaz.net>
0 siblings, 1 reply; 7+ messages in thread
From: Alex Hunsaker @ 2012-03-16 17:48 UTC (permalink / raw)
To: Bruce Momjian <bruce@momjian.us>; +Cc: marko@kobaz.net; pgsql-bugs
On Thu, Mar 15, 2012 at 16:13, Bruce Momjian <bruce@momjian.us> wrote:
> On Tue, Mar 06, 2012 at 09:08:25PM -0700, Alex Hunsaker wrote:
>> [ Calling a plperl trigger function from a plperl function ]
>>
>> Yeah, there were some optimization done for 9.1 to try and make calls
>> a bit faster. The problem is we are fetching "_TD" not "main::_TD",
>> which means we try to find and use $_TD from whatever the current
>> package is. This should only happen from a nested plperl to plperl
>> trigger where the outer call was in a different package, otherwise the
>> package is always main.
>>
>> The attached fixes it for me, It would be great if you could confirm that.
>>
>> Thanks for the report!
>
> So, should this be applied?
Yes, but I would like to get conformation that it fixes the issue.
Either way Ill probably just end up submitting it to the next commit
fest. (I know most commiters are still busy with the current one).
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: BUG #6511: calling spi_exec_query from non-main package, results in: couldn't fetch $_TD
2012-03-03 19:19 BUG #6511: calling spi_exec_query from non-main package, results in: couldn't fetch $_TD marko@kobaz.net
2012-03-07 04:08 ` Re: BUG #6511: calling spi_exec_query from non-main package, results in: couldn't fetch $_TD Alex Hunsaker <badalex@gmail.com>
2012-03-15 22:13 ` Re: BUG #6511: calling spi_exec_query from non-main package, results in: couldn't fetch $_TD Bruce Momjian <bruce@momjian.us>
2012-03-16 17:48 ` Re: BUG #6511: calling spi_exec_query from non-main package, results in: couldn't fetch $_TD Alex Hunsaker <badalex@gmail.com>
@ 2012-03-18 04:11 ` Mark M. <marko@kobaz.net>
0 siblings, 0 replies; 7+ messages in thread
From: Mark M. @ 2012-03-18 04:11 UTC (permalink / raw)
To: Alex Hunsaker <badalex@gmail.com>; +Cc: Bruce Momjian <bruce@momjian.us>; pgsql-bugs
On 03/16/12 13:48, Alex Hunsaker wrote:
> On Thu, Mar 15, 2012 at 16:13, Bruce Momjian<bruce@momjian.us> wrote:
>> On Tue, Mar 06, 2012 at 09:08:25PM -0700, Alex Hunsaker wrote:
>>> [ Calling a plperl trigger function from a plperl function ]
>>>
>>> Yeah, there were some optimization done for 9.1 to try and make calls
>>> a bit faster. The problem is we are fetching "_TD" not "main::_TD",
>>> which means we try to find and use $_TD from whatever the current
>>> package is. This should only happen from a nested plperl to plperl
>>> trigger where the outer call was in a different package, otherwise the
>>> package is always main.
>>>
>>> The attached fixes it for me, It would be great if you could confirm that.
>>>
>>> Thanks for the report!
>> So, should this be applied?
> Yes, but I would like to get conformation that it fixes the issue.
> Either way Ill probably just end up submitting it to the next commit
> fest. (I know most commiters are still busy with the current one).
Fixes the problem. Thanks. I always like one line fixes.
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: BUG #6511: calling spi_exec_query from non-main package, results in: couldn't fetch $_TD
2012-03-03 19:19 BUG #6511: calling spi_exec_query from non-main package, results in: couldn't fetch $_TD marko@kobaz.net
2012-03-07 04:08 ` Re: BUG #6511: calling spi_exec_query from non-main package, results in: couldn't fetch $_TD Alex Hunsaker <badalex@gmail.com>
@ 2012-03-19 20:40 ` Alvaro Herrera <alvherre@commandprompt.com>
2012-03-21 18:16 ` Re: BUG #6511: calling spi_exec_query from non-main package, results in: couldn't fetch $_TD Alex Hunsaker <badalex@gmail.com>
1 sibling, 1 reply; 7+ messages in thread
From: Alvaro Herrera @ 2012-03-19 20:40 UTC (permalink / raw)
To: Alex Hunsaker <badalex@gmail.com>; +Cc: marko <marko@kobaz.net>; pgsql-bugs
Excerpts from Alex Hunsaker's message of mié mar 07 01:08:25 -0300 2012:
> On Sat, Mar 3, 2012 at 12:19, <marko@kobaz.net> wrote:
> Yeah, there were some optimization done for 9.1 to try and make calls
> a bit faster. The problem is we are fetching "_TD" not "main::_TD",
> which means we try to find and use $_TD from whatever the current
> package is. This should only happen from a nested plperl to plperl
> trigger where the outer call was in a different package, otherwise the
> package is always main.
>
> The attached fixes it for me, It would be great if you could confirm that.
Thanks -- applied to 9.1 and master.
--
Álvaro Herrera <alvherre@commandprompt.com>
The PostgreSQL Company - Command Prompt, Inc.
PostgreSQL Replication, Consulting, Custom Development, 24x7 support
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: BUG #6511: calling spi_exec_query from non-main package, results in: couldn't fetch $_TD
2012-03-03 19:19 BUG #6511: calling spi_exec_query from non-main package, results in: couldn't fetch $_TD marko@kobaz.net
2012-03-07 04:08 ` Re: BUG #6511: calling spi_exec_query from non-main package, results in: couldn't fetch $_TD Alex Hunsaker <badalex@gmail.com>
2012-03-19 20:40 ` Re: BUG #6511: calling spi_exec_query from non-main package, results in: couldn't fetch $_TD Alvaro Herrera <alvherre@commandprompt.com>
@ 2012-03-21 18:16 ` Alex Hunsaker <badalex@gmail.com>
0 siblings, 0 replies; 7+ messages in thread
From: Alex Hunsaker @ 2012-03-21 18:16 UTC (permalink / raw)
To: Alvaro Herrera <alvherre@commandprompt.com>; +Cc: marko <marko@kobaz.net>; pgsql-bugs
On Mon, Mar 19, 2012 at 14:40, Alvaro Herrera
<alvherre@commandprompt.com> wrote:
>
> Excerpts from Alex Hunsaker's message of mié mar 07 01:08:25 -0300 2012:
>> The attached fixes it for me, It would be great if you could confirm that.
>
> Thanks -- applied to 9.1 and master.
Thanks!
^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2012-03-21 18:16 UTC | newest]
Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2012-03-03 19:19 BUG #6511: calling spi_exec_query from non-main package, results in: couldn't fetch $_TD marko@kobaz.net
2012-03-07 04:08 ` Alex Hunsaker <badalex@gmail.com>
2012-03-15 22:13 ` Bruce Momjian <bruce@momjian.us>
2012-03-16 17:48 ` Alex Hunsaker <badalex@gmail.com>
2012-03-18 04:11 ` Mark M. <marko@kobaz.net>
2012-03-19 20:40 ` Alvaro Herrera <alvherre@commandprompt.com>
2012-03-21 18:16 ` Alex Hunsaker <badalex@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox