Details
-
Bug
-
Status: Closed (View Workflow)
-
Critical
-
Resolution: Not a Bug
-
11.5.2
-
None
Description
*The exported file for the database is in the attachment.
--orignal 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 rows
--rewritten sql
|
SELECT ALL LINEITEM.L_SHIPMODE AS REF0, LINEITEM.L_TAX AS REF1 |
FROM LINEITEM |
WHERE (LINEITEM.L_SHIPINSTRUCT) > |
COALESCE(100, LINEITEM.L_DISCOUNT, LINEITEM.L_COMMITDATE) |
GROUP BY LINEITEM.L_SHIPMODE, LINEITEM.L_TAX; |
return 72 row
These two queries are logically equivalent, though they use different syntax to handle the comparison value.
In the original query, LINEITEM.L_SHIPINSTRUCT is compared to the constant 100, filtering rows where LINEITEM.L_SHIPINSTRUCT is greater than 100.
In the rewritten query, the COALESCE(100, LINEITEM.L_DISCOUNT, LINEITEM.L_COMMITDATE) function is used to select the first non-NULL value from 100, LINEITEM.L_DISCOUNT, and LINEITEM.L_COMMITDATE. This value is then compared with LINEITEM.L_SHIPINSTRUCT. And the result of COALESCE is still 100.
The two SQL queries are logically equivalent, but they return different results, indicating the presence of a bug.
Attachments
Issue Links
- is duplicated by
-
MDEV-35453 The issue with combining IFNULL function
-
- Closed
-
-
MDEV-35455 Issues with combining coalesce function
-
- Closed
-
This queries are not equivalent because of type conversions (https://mariadb.com/kb/en/type-conversion/):
1) char(25) > 100 --> string and int, they are compared as decimals. --> results in 0 rows in set, 6005 warnings: Truncated incorrect DECIMAL value
2) coalesce(100, decimal, date) --> the result is string
and then we compare 2 strings -> rows are returned, no warnings