[Bug] MERGE double-counts updated rows when using Split Merge

Ouverte
#2,429 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 2 jours

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
56/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
c, postgresql

Piste de recherche

Start by tracing how Split Merge represents an UPDATE and how the PostgreSQL planner reports affected rows for MERGE; the issue names no source files or tests, so locate the implementation and existing MERGE regression coverage first. Reproduce the supplied SQL with the PostgreSQL planner on a three-segment cluster, then add regression coverage showing that 20 logical updates report MERGE 20, not MERGE 40.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

type: Bug
Apache Cloudberry version

Reported during review of PR #2374, with the PostgreSQL planner on a three-segment cluster.

What happened

A MERGE that updates a distribution key uses Split Merge and reports MERGE 40, although only 20 target rows are updated.

Each target row matches exactly one source row. The reported count appears to include both the DELETE and INSERT halves of each split UPDATE.

What you think should happen instead

No response

How to reproduce
SET optimizer = off;

CREATE TABLE mg AS
SELECT a, 5 b FROM generate_series(1, 20) a
DISTRIBUTED BY (a);

CREATE TABLE mg_ref AS
SELECT generate_series(1, 20) a
DISTRIBUTED BY (a);

EXPLAIN (COSTS OFF)
MERGE INTO mg
USING mg_ref s ON mg.b = s.a
WHEN MATCHED THEN UPDATE SET a = 15;

MERGE INTO mg
USING mg_ref s ON mg.b = s.a
WHEN MATCHED THEN UPDATE SET a = 15;

Both CREATE TABLE statements report:

SELECT 20

The execution plan is:

                               QUERY PLAN
------------------------------------------------------------------------
 Merge on mg
   ->  Explicit Redistribute Motion 3:3  (slice1; segments: 3)
         ->  Split Merge
               ->  Hash Join
                     Hash Cond: (mg.b = s.a)
                     ->  Redistribute Motion 3:3  (slice2; segments: 3)
                           Hash Key: mg.b
                           ->  Seq Scan on mg
                     ->  Hash
                           ->  Seq Scan on mg_ref s
 Optimizer: Postgres query optimizer
(11 rows)

The MERGE command reports:

MERGE 40

should be:

MERGE 20

All 20 target rows have b = 5 and match the single source row with a = 5. Each logical UPDATE should contribute one affected row, regardless of whether execution splits it into DELETE and INSERT operations.

Operating System

any

Anything else

No response

Are you willing to submit PR?
  • Yes, I am willing to submit a PR!
Code of Conduct
Langage dominant
C
Étoiles
1.5k
Forks
280
Merge moyen
5 j 35 min
PR mergées (30 j)
128

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de apache/cloudberry

Toutes les issues de apache/cloudberry

Issues similaires

Plus d'issues C

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.