You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While updating DataFusion in InfluxDB we found what appears to be a bug in common_subexpr_eliminate that causes incorrect answers that seems to have come in via the TreeNode refactor in #8891
To Reproduce
> create table m(f64 double) asvalues (10.1);
0 rows inset. Query took 0.038 seconds.
-- This query is correct (note that acos is 1.471623942988976)
❯ select f64, coalesce(1.0/ f64, 0.0), acos(coalesce(1.0/ f64, 0.0)) from m;
+------+-----------------------------------------+-----------------------------------------------+
| f64 | coalesce(Float64(1) /m.f64,Float64(0)) | acos(coalesce(Float64(1) /m.f64,Float64(0))) |
+------+-----------------------------------------+-----------------------------------------------+
| 10.1 | 0.09900990099009901 | 1.471623942988976 |
+------+-----------------------------------------+-----------------------------------------------+1 row inset. Query took 0.001 seconds.
-- However, when I add an alias `as f64_1` to the second argument the query is now incorrect (the acos ...) term now is `0.09900990099009901 which is the same as 1/10.1`)
❯ select f64, coalesce(1.0/ f64, 0.0) as f64_1, acos(coalesce(1.0/ f64, 0.0)) from m;
+------+---------------------+-----------------------------------------------+
| f64 | f64_1 | acos(coalesce(Float64(1) /m.f64,Float64(0))) |
+------+---------------------+-----------------------------------------------+
| 10.1 | 0.09900990099009901 | 0.09900990099009901 |
+------+---------------------+-----------------------------------------------+1 row inset. Query took 0.002 seconds.
Expected behavior
The correct answer is:
❯ select f64, coalesce(1.0/ f64, 0.0) as f64_1, acos(coalesce(1.0/ f64, 0.0)) from m;
+------+---------------------+-----------------------------------------------+
| f64 | f64_1 | acos(coalesce(Float64(1) /m.f64,Float64(0))) |
+------+---------------------+-----------------------------------------------+
| 10.1 | 0.09900990099009901 | 1.471623942988976 |
+------+---------------------+-----------------------------------------------+1 row inset. Query took 0.008 seconds.
Additional context
coalesce seems to be required to trigger the bug. Removing it from the query results in
❯ select f64, 1.0/f64 as f64_1, acos(1.0/ f64) from m;
+------+---------------------+--------------------------+
| f64 | f64_1 | acos(Float64(1) /m.f64) |
+------+---------------------+--------------------------+
| 10.1 | 0.09900990099009901 | 1.471623942988976 |
+------+---------------------+--------------------------+1 row inset. Query took 0.003 seconds.
Describe the bug
While updating DataFusion in InfluxDB we found what appears to be a bug in common_subexpr_eliminate that causes incorrect answers that seems to have come in via the
TreeNode
refactor in #8891To Reproduce
Expected behavior
The correct answer is:
Additional context
coalesce
seems to be required to trigger the bug. Removing it from the query results inTreeNode
transform and rewrite APIs #8891The bug happens in a84e5f8, but does not happen in 684b4fa (the commit right before #8891)
cos
) even though we only saw it foracos
in IOxI tracked the issue down to a problem in common_subexpr_eliminate. You can see the issue via
explain verbose
:You can see
coalesce(Float64(1) / m.f64, Float64(0)) AS acos(coalesce(Float64(1) / m.f64,Float64(0)))
shows clearly theacos
was removedThe text was updated successfully, but these errors were encountered: