pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feed9.1 plperlu bug with null rows in trigger hash
8+ messages / 4 participants
[nested] [flat]
* 9.1 plperlu bug with null rows in trigger hash
@ 2011-05-23 20:59 Greg Sabino Mullane <greg@endpoint.com>
0 siblings, 1 reply; 8+ messages in thread
From: Greg Sabino Mullane @ 2011-05-23 20:59 UTC (permalink / raw)
To: pgsql-bugs
I've not been able to duplicate this in a standalone script yet,
but in the guts of Bucardo is a trigger function called validate_goat()
that is giving this error on 9.1 HEAD, but not on previous versions:
"Failed to add table "public.pgbench_tellers": DBD::Pg::st execute
failed: ERROR: Modification of non-creatable hash value attempted,
subscript "pkey" at line 4."
I was able to simplify the function to just this and still produce
the error:
CREATE OR REPLACE FUNCTION bucardo.validate_goat()
RETURNS TRIGGER
LANGUAGE plperlu
AS
$bc$
my $new = $_TD->{new};
$new->{pkey} = 'foobar';
return 'MODIFY';
$bc$;
It's used like this:
CREATE TRIGGER validate_goat
BEFORE INSERT OR UPDATE ON bucardo.goat
FOR EACH ROW EXECUTE PROCEDURE bucardo.validate_goat();
The goat table has many text fields, of which one is
pkey. Setting it to any of those other columns will cause the error.
However, setting it to a text field that is NOT NULL DEFAULT will
*not* produce the error, so obviously something is setting
$_TD->{new}{somecol} to undef in the wrong way. I'm baffled as
to why I cannot reproduce it standalone, but wanted to get the
bug out there so I don't forget about it and in case anyone
wants to take a swing at it. Some Googling suggests it might
be because we are using &PL_sv_undef instead of a proper
newSV(0).
--
Greg Sabino Mullane greg@endpoint.com
End Point Corporation
PGP Key: 0x14964AC8
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: 9.1 plperlu bug with null rows in trigger hash
@ 2011-05-23 23:04 Alex Hunsaker <badalex@gmail.com>
parent: Greg Sabino Mullane <greg@endpoint.com>
0 siblings, 1 reply; 8+ messages in thread
From: Alex Hunsaker @ 2011-05-23 23:04 UTC (permalink / raw)
To: Greg Sabino Mullane <greg@endpoint.com>; +Cc: pgsql-bugs
On Mon, May 23, 2011 at 14:59, Greg Sabino Mullane <greg@endpoint.com> wrote:
> I've not been able to duplicate this in a standalone script yet,
> but in the guts of Bucardo is a trigger function called validate_goat()
> that is giving this error on 9.1 HEAD, but not on previous versions:
>
> "Failed to add table "public.pgbench_tellers": DBD::Pg::st execute
> failed: ERROR: Modification of non-creatable hash value attempted,
> subscript "pkey" at line 4."
> ...
> Some Googling suggests it might
> be because we are using &PL_sv_undef instead of a proper
> newSV(0).
Yep. Per http://search.cpan.org/~jesse/perl-5.14.0/pod/perlguts.pod#AVs,_HVs_and_undefined_values
|...For example, intuition tells you that this XS code:
|
| AV *av = newAV();
| av_store( av, 0, &PL_sv_undef );
|
| is equivalent to this Perl code:
|
| my @av;
| $av[0] = undef;
| Unfortunately, this isn't true. AVs use &PL_sv_undef as a marker for
indicating that an array element has not yet been initialized.
We have a few places that have that pattern :-(.
I was able to reproduce it fairly easily(1) by passing in NULL values
explicitly. Fixed in the attached.
I looked at 9.0 and below and they did this correctly. This code path
was heavily re-factored in 9.1 for better array and composite type
support . As noted in perlguts using &PL_sv_undef follows your
intuition, but its wrong :-(. Classic perl xs I suppose.
Greg, can you confirm the attached fixes it for you?
--
[1]
=> create or replace function td() returns trigger language plperlu as
$bc$
$_TD->{new}{a} = 1;
return 'MODIFY';
$bc$;
CREATE FUNCTION
=> create table trig_test(a int);
CREATE TABLE
=> create trigger test_trig before insert on trig_test for each row
execute procedure td();
CREATE TRIGGER
=> insert into trig_test values (NULL);
CONTEXT: PL/Perl function "td"
ERROR: Modification of non-creatable hash value attempted, subscript
"a" at line 2.
Attachments:
plperl_td_undef.patch (text/x-patch, 1.0K) download
*** a/src/pl/plperl/plperl.c
--- b/src/pl/plperl/plperl.c
***************
*** 1357,1363 **** make_array_ref(plperl_array_info *info, int first, int last)
for (i = first; i < last; i++)
{
if (info->nulls[i])
! av_push(result, &PL_sv_undef);
else
{
Datum itemvalue = info->elements[i];
--- 1357,1366 ----
for (i = first; i < last; i++)
{
if (info->nulls[i])
! {
! /* We cant use &PL_sv_undef here... see perlguts */
! av_push(result, newSV(0));
! }
else
{
Datum itemvalue = info->elements[i];
***************
*** 2639,2646 **** plperl_hash_from_tuple(HeapTuple tuple, TupleDesc tupdesc)
if (isnull)
{
! /* Store (attname => undef) and move on. */
! hv_store_string(hv, attname, &PL_sv_undef);
continue;
}
--- 2642,2652 ----
if (isnull)
{
! /*
! * Store (attname => undef) and move on. Note, we cant use
! * &PL_sv_undef here... see perlguts for more
! */
! hv_store_string(hv, attname, newSV(0));
continue;
}
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: 9.1 plperlu bug with null rows in trigger hash
@ 2011-05-24 02:08 Greg Sabino Mullane <greg@endpoint.com>
parent: Alex Hunsaker <badalex@gmail.com>
0 siblings, 1 reply; 8+ messages in thread
From: Greg Sabino Mullane @ 2011-05-24 02:08 UTC (permalink / raw)
To: Alex Hunsaker <badalex@gmail.com>; +Cc: pgsql-bugs
On Mon, May 23, 2011 at 05:04:40PM -0600, Alex Hunsaker wrote:
...
> Greg, can you confirm the attached fixes it for you?
Yes, seems to have done the job, thank you.
--
Greg Sabino Mullane greg@endpoint.com
End Point Corporation
PGP Key: 0x14964AC8
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: 9.1 plperlu bug with null rows in trigger hash
@ 2011-05-27 16:14 Alex Hunsaker <badalex@gmail.com>
parent: Greg Sabino Mullane <greg@endpoint.com>
0 siblings, 2 replies; 8+ messages in thread
From: Alex Hunsaker @ 2011-05-27 16:14 UTC (permalink / raw)
To: pgsql-bugs; +Cc: Greg Sabino Mullane <greg@endpoint.com>
On Mon, May 23, 2011 at 20:08, Greg Sabino Mullane <greg@endpoint.com> wrote:
> On Mon, May 23, 2011 at 05:04:40PM -0600, Alex Hunsaker wrote:
> ...
>> Greg, can you confirm the attached fixes it for you?
>
> Yes, seems to have done the job, thank you.
Thanks for testing!
[ Does a little dance to try and attract a -commiter ]
This was broken as part of:
commit 87bb2ade2ce646083f39d5ab3e3307490211ad04
Author: Alvaro Herrera <alvherre@alvh.no-ip.org>
Date: Thu Feb 17 22:11:50 2011 -0300
Convert Postgres arrays to Perl arrays on PL/perl input arguments
More generally, arrays are turned in Perl array references, and row and
composite types are turned into Perl hash references. This is done
recursively, in a way that's natural to every Perl programmer.
To avoid a backwards compatibility hit, the string representation of
each structure is also available if the function requests it.
Authors: Alexey Klyukin and Alex Hunsaker.
Some code cleanups by me.
Which also means it only breaks HEAD/9.1 (I did test and review 9.0 and down.)
Per http://search.cpan.org/~jesse/perl-5.14.0/pod/perlguts.pod#AVs,_HVs_and_undefined_values,
we do not want to use &PL_sv_undef for undef values in hashes and
arrays. I (inadvertently) broke this in the above commit. As perldoc
mentions &PL_sv_undef seems like the intuitive thing to use. But its
wrong in certain cases.
We have 6 other uses of &PL_sv_undef, 2 &PL_sv_no and 1 &PL_sv_yes.
These are all ok as none of them use the HV/AV store interface.
I elected _not_ to add any regression tests. (If we forget about this
in the future, it will likely be in other code paths). Instead I added
comments to the places that used &PL_sv_undef noting that we
explicitly avoid it on purpose.
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: 9.1 plperlu bug with null rows in trigger hash
@ 2011-05-27 20:43 Alexey Klyukin <alexk@commandprompt.com>
parent: Alex Hunsaker <badalex@gmail.com>
1 sibling, 0 replies; 8+ messages in thread
From: Alexey Klyukin @ 2011-05-27 20:43 UTC (permalink / raw)
To: Alex Hunsaker <badalex@gmail.com>; +Cc: pgsql-bugs; Greg Sabino Mullane <greg@endpoint.com>
On May 27, 2011, at 7:14 PM, Alex Hunsaker wrote:
> On Mon, May 23, 2011 at 20:08, Greg Sabino Mullane <greg@endpoint.com> wrote:
>> On Mon, May 23, 2011 at 05:04:40PM -0600, Alex Hunsaker wrote:
>> ...
>>> Greg, can you confirm the attached fixes it for you?
>>
>> Yes, seems to have done the job, thank you.
>
> Thanks for testing!
>
> [ Does a little dance to try and attract a -commiter ]
>
> This was broken as part of:
> commit 87bb2ade2ce646083f39d5ab3e3307490211ad04
> Author: Alvaro Herrera <alvherre@alvh.no-ip.org>
> Date: Thu Feb 17 22:11:50 2011 -0300
>
> Convert Postgres arrays to Perl arrays on PL/perl input arguments
>
> More generally, arrays are turned in Perl array references, and row and
> composite types are turned into Perl hash references. This is done
> recursively, in a way that's natural to every Perl programmer.
>
> To avoid a backwards compatibility hit, the string representation of
> each structure is also available if the function requests it.
>
> Authors: Alexey Klyukin and Alex Hunsaker.
> Some code cleanups by me.
>
> Which also means it only breaks HEAD/9.1 (I did test and review 9.0 and down.)
>
> Per http://search.cpan.org/~jesse/perl-5.14.0/pod/perlguts.pod#AVs,_HVs_and_undefined_values,
> we do not want to use &PL_sv_undef for undef values in hashes and
> arrays. I (inadvertently) broke this in the above commit. As perldoc
> mentions &PL_sv_undef seems like the intuitive thing to use. But its
> wrong in certain cases.
Yeah, per the link above the problem is evident and after a little testing
I think your patch fixed the problem. Thank you for tracking down this!
>
> We have 6 other uses of &PL_sv_undef, 2 &PL_sv_no and 1 &PL_sv_yes.
> These are all ok as none of them use the HV/AV store interface.
>
> I elected _not_ to add any regression tests. (If we forget about this
> in the future, it will likely be in other code paths). Instead I added
> comments to the places that used &PL_sv_undef noting that we
> explicitly avoid it on purpose.
+1.
--
Alexey Klyukin
The PostgreSQL Company - Command Prompt, Inc.
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: 9.1 plperlu bug with null rows in trigger hash
@ 2011-05-28 05:06 Alvaro Herrera <alvherre@commandprompt.com>
parent: Alex Hunsaker <badalex@gmail.com>
1 sibling, 1 reply; 8+ messages in thread
From: Alvaro Herrera @ 2011-05-28 05:06 UTC (permalink / raw)
To: Alex Hunsaker <badalex@gmail.com>; +Cc: pgsql-bugs; Greg Sabino Mullane <greg@endpoint.com>
Excerpts from Alex Hunsaker's message of vie may 27 12:14:25 -0400 2011:
> On Mon, May 23, 2011 at 20:08, Greg Sabino Mullane <greg@endpoint.com> wrote:
> > On Mon, May 23, 2011 at 05:04:40PM -0600, Alex Hunsaker wrote:
> > ...
> >> Greg, can you confirm the attached fixes it for you?
> >
> > Yes, seems to have done the job, thank you.
>
> Thanks for testing!
>
> [ Does a little dance to try and attract a -commiter ]
Okay, I'll handle it :-)
--
Álvaro Herrera <alvherre@commandprompt.com>
The PostgreSQL Company - Command Prompt, Inc.
PostgreSQL Replication, Consulting, Custom Development, 24x7 support
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: 9.1 plperlu bug with null rows in trigger hash
@ 2011-05-30 17:02 Alvaro Herrera <alvherre@commandprompt.com>
parent: Alvaro Herrera <alvherre@commandprompt.com>
0 siblings, 1 reply; 8+ messages in thread
From: Alvaro Herrera @ 2011-05-30 17:02 UTC (permalink / raw)
To: Alex Hunsaker <badalex@gmail.com>; +Cc: pgsql-bugs; Greg Sabino Mullane <greg@endpoint.com>
Excerpts from Alvaro Herrera's message of sáb may 28 01:06:42 -0400 2011:
> Excerpts from Alex Hunsaker's message of vie may 27 12:14:25 -0400 2011:
> > On Mon, May 23, 2011 at 20:08, Greg Sabino Mullane <greg@endpoint.com> wrote:
> > > On Mon, May 23, 2011 at 05:04:40PM -0600, Alex Hunsaker wrote:
> > > ...
> > >> Greg, can you confirm the attached fixes it for you?
> > >
> > > Yes, seems to have done the job, thank you.
> >
> > Thanks for testing!
> >
> > [ Does a little dance to try and attract a -commiter ]
>
> Okay, I'll handle it :-)
Pushed, thanks.
--
Álvaro Herrera <alvherre@commandprompt.com>
The PostgreSQL Company - Command Prompt, Inc.
PostgreSQL Replication, Consulting, Custom Development, 24x7 support
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: 9.1 plperlu bug with null rows in trigger hash
@ 2011-05-31 02:32 Alex Hunsaker <badalex@gmail.com>
parent: Alvaro Herrera <alvherre@commandprompt.com>
0 siblings, 0 replies; 8+ messages in thread
From: Alex Hunsaker @ 2011-05-31 02:32 UTC (permalink / raw)
To: Alvaro Herrera <alvherre@commandprompt.com>; +Cc: pgsql-bugs; Greg Sabino Mullane <greg@endpoint.com>
On Mon, May 30, 2011 at 11:02, Alvaro Herrera
<alvherre@commandprompt.com> wrote:
> Excerpts from Alvaro Herrera's message of sáb may 28 01:06:42 -0400 2011:
>> Excerpts from Alex Hunsaker's message of vie may 27 12:14:25 -0400 2011:
>> > On Mon, May 23, 2011 at 20:08, Greg Sabino Mullane <greg@endpoint.com> wrote:
>> > > On Mon, May 23, 2011 at 05:04:40PM -0600, Alex Hunsaker wrote:
>> > > ...
>> > >> Greg, can you confirm the attached fixes it for you?
>> > >
>> > > Yes, seems to have done the job, thank you.
>> >
>> > Thanks for testing!
>> >
>> > [ Does a little dance to try and attract a -commiter ]
>>
>> Okay, I'll handle it :-)
>
> Pushed, thanks.
Great thanks!
^ permalink raw reply [nested|flat] 8+ messages in thread
end of thread, other threads:[~2011-05-31 02:32 UTC | newest]
Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-05-23 20:59 9.1 plperlu bug with null rows in trigger hash Greg Sabino Mullane <greg@endpoint.com>
2011-05-23 23:04 ` Alex Hunsaker <badalex@gmail.com>
2011-05-24 02:08 ` Greg Sabino Mullane <greg@endpoint.com>
2011-05-27 16:14 ` Alex Hunsaker <badalex@gmail.com>
2011-05-27 20:43 ` Alexey Klyukin <alexk@commandprompt.com>
2011-05-28 05:06 ` Alvaro Herrera <alvherre@commandprompt.com>
2011-05-30 17:02 ` Alvaro Herrera <alvherre@commandprompt.com>
2011-05-31 02:32 ` 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