Re: Unexpected behavior with transition tables in update statement trigger

From: Tom Kazimiers <tom(at)voodoo-arts(dot)net>
To: Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Unexpected behavior with transition tables in update statement trigger
Date: 2018-02-27 20:08:30
Message-ID: 20180227200830.ctzfnqrczzn5ijer@dewberry.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

On Tue, Feb 27, 2018 at 02:52:02PM +1300, Thomas Munro wrote:
>On Tue, Feb 27, 2018 at 4:18 AM, Tom Kazimiers <tom(at)voodoo-arts(dot)net> wrote:
>> It would be great if this or a similar fix would make it into the
>> next official release.
>
>Here's a new version with tuplestore_select_read_pointer() added in
>another place where it was lacking, and commit message. Moving to
>-hackers, where patches go.

Thanks and just to confirm the obvious: the new patch still fixes this
bug in both my test trigger function and my real trigger function.

>Here's a shorter repro. On master it prints:
>
>NOTICE: count = 1
>NOTICE: count union = 1
>
>With the patch the second number is 2, as it should be.
>
>CREATE TABLE test (i int);
>INSERT INTO test VALUES (1);
>
>CREATE OR REPLACE FUNCTION my_trigger_fun() RETURNS trigger
>LANGUAGE plpgsql AS
>$$
> BEGIN
> RAISE NOTICE 'count = %', (SELECT COUNT(*) FROM new_test);
> RAISE NOTICE 'count union = %', (SELECT COUNT(*)
> FROM (SELECT * FROM new_test UNION ALL SELECT * FROM new_test) ss);
> RETURN NULL;
> END;
>$$;
>
>CREATE TRIGGER my_trigger AFTER UPDATE ON test
>REFERENCING NEW TABLE AS new_test OLD TABLE as old_test
>FOR EACH STATEMENT EXECUTE PROCEDURE my_trigger_fun();
>
>UPDATE test SET i = i;

That's a much cleaner repro (and test case I suppose), thanks.

Tom

In response to

Browse pgsql-general by date

  From Date Subject
Next Message chris 2018-02-27 20:16:37 selecting timestamp
Previous Message Greg Stark 2018-02-27 11:40:04 Re: Feature request: separate logging

Browse pgsql-hackers by date

  From Date Subject
Next Message David Steele 2018-02-27 20:52:32 Re: PATCH: Configurable file mode mask
Previous Message Tom Lane 2018-02-27 19:53:55 Re: Let's remove DSM_INPL_NONE.