Incorrect command tag row count for MERGE with a cross-partition update

From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Incorrect command tag row count for MERGE with a cross-partition update
Date: 2023-02-20 15:56:27
Message-ID: CAEZATCWRMG7XX2QEsVL1LswmNo2d_YG8tKTLkpD3=Lp644S7rg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Playing around with MERGE some more, I noticed that the command tag
row count is wrong if it does a cross-partition update:

CREATE TABLE target (a int, b int) PARTITION BY LIST (b);
CREATE TABLE target_p1 PARTITION OF target FOR VALUES IN (1);
CREATE TABLE target_p2 PARTITION OF target FOR VALUES IN (2);
INSERT INTO target VALUES (1,1);

MERGE INTO target t USING (VALUES (1)) v(a) ON t.a = v.a
WHEN MATCHED THEN UPDATE SET b = 2;

which returns "MERGE 2" when only 1 row was updated, because
ExecUpdateAct() will update estate->es_processed for a cross-partition
update (but not for a normal update), and then ExecMergeMatched() will
update it again.

I think the best fix is to have ExecMergeMatched() pass canSetTag =
false to ExecUpdateAct(), so that ExecMergeMatched() takes
responsibility for updating estate->es_processed in all cases.

Regards,
Dean

Attachment Content-Type Size
merge-cp-update-command-tag-fix.patch text/x-patch 620 bytes

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Markur Sens 2023-02-20 16:05:40 Re: pg_crc32c_armv8.c:35:9: error: implicit declaration of function '__crc32cb' is invalid in C99
Previous Message Tom Lane 2023-02-20 15:47:13 Re: pg_crc32c_armv8.c:35:9: error: implicit declaration of function '__crc32cb' is invalid in C99