Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Report #19473

Open
MyKWK opened this issue Nov 20, 2024 · 0 comments
Open

Bug Report #19473

MyKWK opened this issue Nov 20, 2024 · 0 comments

Comments

@MyKWK
Copy link

MyKWK commented Nov 20, 2024

BUG Report

TiDB 8.3.0

Original Query

select all l_extendedprice , l_orderkey , l_discount
from lineitem
where (coalesce(l_quantity,
l_suppkey,
0.21501538554113775,
l_receiptdate) )
<= l_returnflag
group by l_extendedprice, l_orderkey, l_discount;
return : 6005 rows

Rewritten Query

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 0 rows

Analysis

In the rewritten query, the COALESCE function is replaced with a CASE expression without altering its semantics. In the original query, COALESCE filters through values to identify the first non-NULL value. Due to the presence of a constant before the final parameter, the last argument in the original expression is redundant. This behavior aligns with the semantics conveyed by the equivalent CASE expression. Furthermore, the use of the CAST function within the CASE expression does not introduce any semantic changes. As such, the two formulations are logically equivalent.

How to repeat ?

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant