Re: BUG #18238: Cross-partitition MERGE/UPDATE with delete-preventing trigger leads to incorrect memory access

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Richard Guo <guofenglinux(at)gmail(dot)com>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, exclusion(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18238: Cross-partitition MERGE/UPDATE with delete-preventing trigger leads to incorrect memory access
Date: 2023-12-13 03:36:03
Message-ID: CACJufxFAq+d6oEC0QKHdi8t_8=9nWDRjNLG=ZrGGumLA3A=rYw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

sorry for the noise.
generally I only do regress tests, I should do regress and isolation tests.
your patch is correct, especially ExecCrossPartitionUpdate canSetTag
logic is very intuitive to me.

The test example is so good. Maybe it takes a bit of time for people
to comprehend. (i think)

+-- as above, but blocked by BEFORE DELETE ROW trigger
+BEGIN;
+CREATE FUNCTION trig_fn() RETURNS trigger LANGUAGE plpgsql AS
+ $$ BEGIN RETURN NULL; END; $$;
+CREATE TRIGGER del_trig BEFORE DELETE ON pa_target
+ FOR EACH ROW EXECUTE PROCEDURE trig_fn();
+DO $$
+DECLARE
+ result integer;
+BEGIN
+MERGE INTO pa_target t
+ USING pa_source s
+ ON t.tid = s.sid
+ WHEN MATCHED THEN
+ UPDATE SET tid = tid + 1, balance = balance + delta, val = val ||
' updated by merge'
+ WHEN NOT MATCHED THEN
+ INSERT VALUES (sid, delta, 'inserted by merge');
+GET DIAGNOSTICS result := ROW_COUNT;
+RAISE NOTICE 'ROW_COUNT = %', result;
+END;
+$$;
+SELECT * FROM pa_target ORDER BY tid;
+ROLLBACK;

in
+SELECT * FROM pa_target ORDER BY tid;
I would change to

SELECT pt.*, pg_get_expr(pc.relpartbound, pt.tableoid, TRUE)
FROM pa_target pt
JOIN pg_class pc ON pc.oid = pt.tableoid
ORDER BY val,tid;

that would make the result more understandable, maybe i am over engineering.
Anyway, that's my personal preference.

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2023-12-13 03:39:58 BUG #18245: pg_restore accepts same output file name as input file name
Previous Message Richard Guo 2023-12-13 01:40:53 Re: BUG #18238: Cross-partitition MERGE/UPDATE with delete-preventing trigger leads to incorrect memory access