pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #8152: strange behavior regarding after triggers and inheritance
3+ messages / 3 participants
[nested] [flat]

* BUG #8152: strange behavior regarding after triggers and inheritance
@ 2013-05-12 01:02  hcurti@exa.unicen.edu.ar
  0 siblings, 1 reply; 3+ messages in thread

From: hcurti@exa.unicen.edu.ar @ 2013-05-12 01:02 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      8152
Logged by:          Hugo J. Curti
Email address:      hcurti@exa.unicen.edu.ar
PostgreSQL version: 8.4.17
Operating system:   Debian GNU/Linux 6.0.7 (squeeze)
Description:        

I don't know if this is really a bug, but it is at least a strange /
undocumented behavior.

After statments triggers on child tables are sometimes executed and
sometimes are not. As I far as I could see, when the after trigger is
defined in only one of the tables it may not get executed, wether when it is
defined in every inherited table it does, but
which one is undetermined.

this is a simple example:

> CREATE FUNCTION test() returns trigger as $$ BEGIN RAISE NOTICE 'Trigger
executed' ; RETURN NULL ; END $$ LANGUAGE 'plpgsql' ;
CREATE FUNCTION

> CREATE TABLE a ( a integer ) ;
CREATE TABLE

>CREATE TABLE b ( b integer ) INHERITS( a ) ;
CREATE TABLE

> CREATE TRIGGER ta AFTER UPDATE ON a FOR EACH STATEMENT EXECUTE PROCEDURE
test() ;
CREATE TRIGGER

> CREATE TRIGGER tb AFTER UPDATE ON b FOR EACH STATEMENT EXECUTE PROCEDURE
test() ;
CREATE TRIGGER

INSERT INTO b VALUES( 1 , 2 ) ;
INSERT 0 1

EXPLAIN ANALYZE update a set a=1 ;
NOTICE:  Trigger executed
                                        QUERY PLAN
--------------------------------------------------------------------------------------------------------
 Append  (cost=0.00..65.40 rows=4540 width=8) (actual time=0.035..0.040
rows=1 loops=1)
   ->  Seq Scan on a  (cost=0.00..34.00 rows=2400 width=6) (actual
time=0.005..0.005 rows=0 loops=1)
   ->  Seq Scan on b a  (cost=0.00..31.40 rows=2140 width=10) (actual
time=0.025..0.028 rows=1 loops=1)
 Trigger tb on b: time=0.869 calls=1
 Total runtime: 1.117 ms
(5 filas)

-- Here trigger tb gets executed. That
-- might be correct, but since it is a
-- an 'AFTER STATEMENT' trigger I think,
-- ta would be a better candidate...

-- The strange behavior starts here:

> CREATE TABLE c ( c integer ) INHERITS( a ) ;
CREATE TABLE

> EXPLAIN ANALYZE update a set a=1 ;
                                        QUERY PLAN
--------------------------------------------------------------------------------------------------------
 Append  (cost=0.00..96.80 rows=6680 width=9) (actual time=0.021..0.028
rows=1 loops=1)
   ->  Seq Scan on a  (cost=0.00..34.00 rows=2400 width=6) (actual
time=0.005..0.005 rows=0 loops=1)
   ->  Seq Scan on b a  (cost=0.00..31.40 rows=2140 width=10) (actual
time=0.013..0.016 rows=1 loops=1)
   ->  Seq Scan on c a  (cost=0.00..31.40 rows=2140 width=10) (actual
time=0.001..0.001 rows=0 loops=1)
 Total runtime: 0.188 ms
(5 filas)

-- The trigger does not get executed
-- any more!

-- Now, adding the trigger to table c:

> CREATE TRIGGER tc AFTER UPDATE ON c FOR EACH STATEMENT EXECUTE PROCEDURE
test() ;
CREATE TRIGGER

> EXPLAIN ANALYZE update a set a=1 ;
NOTICE:  Trigger executed
                                        QUERY PLAN
--------------------------------------------------------------------------------------------------------
 Append  (cost=0.00..96.80 rows=6680 width=9) (actual time=0.041..0.050
rows=1 loops=1)
   ->  Seq Scan on a  (cost=0.00..34.00 rows=2400 width=6) (actual
time=0.004..0.004 rows=0 loops=1)
   ->  Seq Scan on b a  (cost=0.00..31.40 rows=2140 width=10) (actual
time=0.032..0.036 rows=1 loops=1)
   ->  Seq Scan on c a  (cost=0.00..31.40 rows=2140 width=10) (actual
time=0.001..0.001 rows=0 loops=1)
 Trigger tc on c: time=1.002 calls=1
 Total runtime: 1.314 ms
(6 filas)

-- Now the trigger tc gets executed.
-- This is strange. I might expect ta
-- because it is an 'AFTER STATEMENT'
-- trigger, or tb because the affected
-- rows are on table b, but why tc?

The workarround I found is to define the after statement trigger in EVERY
child table.

I hope this helps.

Regards,

    Hugo J. Curti



-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #8152: strange behavior regarding after triggers and inheritance
@ 2013-05-13 20:06  Tom Lane <tgl@sss.pgh.pa.us>
  parent: hcurti@exa.unicen.edu.ar
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Lane @ 2013-05-13 20:06 UTC (permalink / raw)
  To: hcurti@exa.unicen.edu.ar; +Cc: pgsql-bugs

hcurti@exa.unicen.edu.ar writes:
> PostgreSQL version: 8.4.17

> After statments triggers on child tables are sometimes executed and
> sometimes are not. As I far as I could see, when the after trigger is
> defined in only one of the tables it may not get executed, wether when it is
> defined in every inherited table it does, but
> which one is undetermined.

This test case appears to work the way you're expecting in 9.0 and
later.  I didn't immediately find a mention of such a change in the
commit logs; perhaps it got fixed as a side-effect of the changes that
moved trigger processing into ModifyTable plan nodes.  Anyway, I doubt
we'd consider changing trigger behavior in 8.4.x at this late date.
You should update to a newer release series if this is a problem for you.

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #8152: strange behavior regarding after triggers and inheritance
@ 2013-05-13 22:09  Hugo J. Curti <hcurti@exa.unicen.edu.ar>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 3+ messages in thread

From: Hugo J. Curti @ 2013-05-13 22:09 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-bugs

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

El 13/05/13 17:06, Tom Lane escribió:
> hcurti@exa.unicen.edu.ar writes:
>> PostgreSQL version: 8.4.17
> 
>> After statments triggers on child tables are sometimes executed and
>> sometimes are not. As I far as I could see, when the after trigger is
>> defined in only one of the tables it may not get executed, wether when it is
>> defined in every inherited table it does, but
>> which one is undetermined.
> 
> This test case appears to work the way you're expecting in 9.0 and
> later.  I didn't immediately find a mention of such a change in the
> commit logs; perhaps it got fixed as a side-effect of the changes that
> moved trigger processing into ModifyTable plan nodes.  Anyway, I doubt
> we'd consider changing trigger behavior in 8.4.x at this late date.
> You should update to a newer release series if this is a problem for you.
> 
> 			regards, tom lane

Thank you Tom,

   The update to 9.x is already planned, and the workaround I mentioned
in the post works for me.

   regards,

        Hugo

- -- 
mailto:hcurti@exa.unicen.edu.ar
http://www.exa.unicen.edu.ar/~hcurti
Firma digital GPG/PGP: http://www.exa.unicen.edu.ar/~hcurti/firma_hcurti.asc

Puede hacer una donación indirecta (gratis) de un plato de comida
para un niño de la Argentina ahora mismo ingresando a
http://www.porloschicos.com/servlet/PorLosChicos?comando=donar
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlGRZLEACgkQy9s+D7eSFvn2uwCeL3v4sQpkLgvN3xmHIVYN/2Ic
NEcAoOrR+NXMzfarmgKxjDSun2docaC5
=6buB
-----END PGP SIGNATURE-----


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2013-05-13 22:09 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-05-12 01:02 BUG #8152: strange behavior regarding after triggers and inheritance hcurti@exa.unicen.edu.ar
2013-05-13 20:06 ` Tom Lane <tgl@sss.pgh.pa.us>
2013-05-13 22:09   ` Hugo J. Curti <hcurti@exa.unicen.edu.ar>

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