Bug Report: Issues with CASE operation

Aperta
#19,474 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
sql
Ambito
databases

Direzione di ricerca

Inizia caricando il database tidpcd.sql allegato ed eseguendo entrambe le query su TiDB 8.3.0, confrontando i relativi risultati e il comportamento della riscrittura di CASE. Il lavoro è completato quando la discrepanza nel numero di righe è riproducibile, la causa è stata identificata e il risultato atteso o la correzione sono documentati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

BugReport: Issues with CASE operation

version

8.3.0

Original sql

select all lineitem.l_shipmode as ref0, lineitem.l_tax as ref1 from lineitem 
where (lineitem.l_shipinstruct) > 100
group by lineitem.l_shipmode, lineitem.l_tax;

return 0 row

Rewritten sql

SELECT l_extendedprice, l_orderkey, l_discount FROM lineitem 
WHERE CASE 
  WHEN l_quantity IS NOT NULL THEN CAST(l_quantity AS decimal(15,2)) 
  WHEN l_suppkey IS NOT NULL THEN CAST(l_suppkey AS unsigned) 
  else 0.21501538554113775  
END <= l_returnflag 
GROUP BY l_orderkey, l_extendedprice, l_discount

return 72 row

Analysis

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

Original Query: The original query filters rows using the condition lineitem.l_shipinstruct > 100 and groups them by lineitem.l_shipmode and lineitem.l_tax. Since 100 is a constant, it is directly used to compare with lineitem.l_shipinstruct.

Rewritten Query: In the rewritten query, a CASE expression is used for conditional checking. It first checks if 100 is NULL, which it isn't, so it directly returns 100. If 100 were NULL (which is not the case here), it would perform further checks and ultimately choose lineitem.l_discount or lineitem.l_commitdate. Therefore, although the rewritten query introduces the CASE statement, the logic is equivalent to the original query, as both compare lineitem.l_shipinstruct with 100.

The two SQL queries are logically equivalent. Unexpectedly, the number of returned rows is different, 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) .

Lingua principale
Python
Stelle
616
Fork
724
Merge medio
2g 5h
PR unite (30g)
168

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di pingcap/docs

Tutte le issue di pingcap/docs

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.