Bug Report: Issues with IF function

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

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
25/100
Tipo de issue
Bug
Clareza
Precisa de esclarecimento
Status de atividade
Estagnada
Stack de tecnologia
sql
Domínio
databases

Direção de pesquisa

Comece carregando os dados anexados de tidb/tpcd.sql e executando ambas as consultas SQL no TiDB 8.3.0, comparando seus conjuntos de resultados e o comportamento das expressões IF/IN. A tarefa estará concluída quando for identificado por que consultas logicamente equivalentes diferem e for confirmado que o mesmo caso produz resultados consistentes após a correção.

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

Descrição

BugReport: Issues with IF function

version

8.3.0

Original sql

SELECT 
    O_CUSTKEY 
FROM 
    orders
WHERE 
    (
        O_COMMENT   IN (
            IF(
                -1801656545 IS NOT NULL, 
                -1801656545, 

            )
        )
    ) = 0.24036834733741486
GROUP BY 
    O_CUSTKEY ;

return 0 row

Rewritten sql

SELECT  O_CUSTKEY 
FROM orders
WHERE NOT EXISTS (
    SELECT 1
    WHERE O_COMMENT <> -1801656545 OR O_COMMENT IS NULL
) = 0.24036834733741486
GROUP BY  O_CUSTKEY ;

return 101 row

Analysis

These two queries are logically equivalent, although they are written differently.

Original Query: The original query uses the IF function to check if -1801656545 is not NULL. If it is not NULL, it returns -1801656545; otherwise, it would return NULL (though in this specific query, -1801656545 is never NULL). It then uses IN to check if O_COMMENT matches the returned value and compares the result with 0.24036834733741486 to filter rows.

Rewritten Query: In the rewritten query, the NOT EXISTS subquery is used to check if O_COMMENT is not equal to -1801656545 or is NULL, which is logically equivalent to the IN check in the original query. The final result of the NOT EXISTS subquery is then compared with 0.24036834733741486 to filter the rows.

The two SQL queries are logically equivalent, but they return different results, indicating the presence of a bug.

How to repeat

The exported file for the database is in the attachment. : (https://github.com/LLuopeiqi/newtpcd/blob/main/tidb/tpcd.sql) .

Linguagem predominante
Python
Estrelas
616
Forks
724
Merge médio
2d 5h
PRs com merge (30d)
168

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 pingcap/docs

Todas as issues de pingcap/docs

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

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