Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UbyRl-0001u8-7k for pgsql-bugs@arkaria.postgresql.org; Mon, 13 May 2013 19:30:09 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UbyRk-00005a-Bm for pgsql-bugs@arkaria.postgresql.org; Mon, 13 May 2013 19:30:08 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UbKgR-0003oz-Gk for pgsql-bugs@postgresql.org; Sun, 12 May 2013 01:02:39 +0000 Received: from mahout.postgresql.org ([2001:4800:7903:4::123]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UbKgP-0007L2-1M for pgsql-bugs@postgresql.org; Sun, 12 May 2013 01:02:38 +0000 Received: from [204.145.124.246] (helo=wrigleys.postgresql.org) by mahout.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UbKgL-0007qY-7O for pgsql-bugs@postgresql.org; Sun, 12 May 2013 01:02:35 +0000 Received: from www-data by wrigleys.postgresql.org with local (Exim 4.72) (envelope-from ) id 1UbKgF-0000xi-OY for pgsql-bugs@postgresql.org; Sun, 12 May 2013 01:02:27 +0000 Date: Sun, 12 May 2013 01:02:27 +0000 Message-Id: Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #8152: strange behavior regarding after triggers and inheritance To: pgsql-bugs@postgresql.org From: hcurti@exa.unicen.edu.ar X-Pg-Spam-Score: -3.4 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org 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:=20=20=20=20=20=20=20=20 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=3D1 ; NOTICE: Trigger executed QUERY PLAN ---------------------------------------------------------------------------= ----------------------------- Append (cost=3D0.00..65.40 rows=3D4540 width=3D8) (actual time=3D0.035..0= .040 rows=3D1 loops=3D1) -> Seq Scan on a (cost=3D0.00..34.00 rows=3D2400 width=3D6) (actual time=3D0.005..0.005 rows=3D0 loops=3D1) -> Seq Scan on b a (cost=3D0.00..31.40 rows=3D2140 width=3D10) (actual time=3D0.025..0.028 rows=3D1 loops=3D1) Trigger tb on b: time=3D0.869 calls=3D1 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=3D1 ; QUERY PLAN ---------------------------------------------------------------------------= ----------------------------- Append (cost=3D0.00..96.80 rows=3D6680 width=3D9) (actual time=3D0.021..0= .028 rows=3D1 loops=3D1) -> Seq Scan on a (cost=3D0.00..34.00 rows=3D2400 width=3D6) (actual time=3D0.005..0.005 rows=3D0 loops=3D1) -> Seq Scan on b a (cost=3D0.00..31.40 rows=3D2140 width=3D10) (actual time=3D0.013..0.016 rows=3D1 loops=3D1) -> Seq Scan on c a (cost=3D0.00..31.40 rows=3D2140 width=3D10) (actual time=3D0.001..0.001 rows=3D0 loops=3D1) 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=3D1 ; NOTICE: Trigger executed QUERY PLAN ---------------------------------------------------------------------------= ----------------------------- Append (cost=3D0.00..96.80 rows=3D6680 width=3D9) (actual time=3D0.041..0= .050 rows=3D1 loops=3D1) -> Seq Scan on a (cost=3D0.00..34.00 rows=3D2400 width=3D6) (actual time=3D0.004..0.004 rows=3D0 loops=3D1) -> Seq Scan on b a (cost=3D0.00..31.40 rows=3D2140 width=3D10) (actual time=3D0.032..0.036 rows=3D1 loops=3D1) -> Seq Scan on c a (cost=3D0.00..31.40 rows=3D2140 width=3D10) (actual time=3D0.001..0.001 rows=3D0 loops=3D1) Trigger tc on c: time=3D1.002 calls=3D1 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 --=20 Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs