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

Abierto
#2,429 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
56/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
c, postgresql

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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
Lenguaje dominante
C
Estrellas
1.5k
Forks
280
Merge medio
4 d 21 h
PR fusionados (30 d)
122

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de apache/cloudberry

Todos los issues de apache/cloudberry

Issues similares

Más issues de C

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.