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

Aberta
#2,429 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 2 dias

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
56/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
c, postgresql

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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
Linguagem predominante
C
Estrelas
1.5k
Forks
280
Merge médio
5d 35min
PRs com merge (30d)
128

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de apache/cloudberry

Todas as issues de apache/cloudberry

Issues semelhantes

Mais issues de C

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.