UPDATE / DELETE fail with "No field named __common_expr_1" when SET or WHERE repeats an expression

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

Mantenedores costumam responder em até 1 dia

@v28k já está trabalhando nisso.

Desde 8/11/2026.

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
20/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Estagnada
Stack de tecnologia
rust

Direção de pesquisa

Start by tracing extract_update_assignments and extract_dml_filters in the physical planner, then follow how common subexpression elimination moves expressions into projections. Check the UPDATE and DELETE planning paths against the table provider's schema. Done means the three reproduced statements execute without the missing __common_expr_N schema error and produce the expected row changes.

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

Descrição

bug
Describe the bug

An UPDATE or DELETE on an in-memory table fails at planning time with a schema error regarding an internal column when its SET expressions or WHERE clause contain the same expression more than once (for example, COALESCE(c0, 0) on an INT column, where the column is coerced/cast to Int64 twice to match the integer literal):

UPDATE operation on table 't' caused by Schema error: No field named __common_expr_1. Valid fields are c0, c1.

Common subexpression elimination moves the repeated expression into an underlying projection below the UPDATE assignment projection (or below the Filter node). When the physical planner extracts the assignments (extract_update_assignments) and filters (extract_dml_filters) and hands them to the table provider, the provider evaluates them directly against the table's schema, where __common_expr_1 does not exist.

To Reproduce

CREATE TABLE t (c0 INT, c1 VARCHAR);
INSERT INTO t VALUES (1, 'a'), (NULL, 'b');

UPDATE t SET c0 = COALESCE(c0, 0); -- Schema error: No field named __common_expr_1
UPDATE t SET c1 = 'z' WHERE COALESCE(c0, 0) > 0 AND COALESCE(c0, 0) < 5; -- Schema error: No field named __common_expr_N
DELETE FROM t WHERE COALESCE(c0, 0) > 0 AND COALESCE(c0, 0) < 5; -- Schema error: No field named __common_expr_N

Expected behavior

The first UPDATE should update 2 rows ((1, 'a'), (0, 'b')). The second UPDATE should update 1 row, and the DELETE should delete 1 row. The same expressions execute without error in a SELECT.

Additional context

Reproduced on main at commit bc86321 (57.0.0-dev) and with datafusion-python 55.0.0. Found via an automated SQL fuzzer comparing execution plans.

Willingness to contribute

I plan to contribute a fix for this bug independently

Linguagem predominante
Rust
Estrelas
9.6k
Forks
2.6k
Merge médio
3d 4h
PRs com merge (30d)
345

Preparar o ambiente

Abrir no Codespaces

Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.

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/datafusion

Todas as issues de apache/datafusion

Issues semelhantes

Mais issues de Rust

Receba novas issues na sua caixa de entrada

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