Skip to content

Incorrect result returned by UNION ALL (SQLancer-TLP) #11742

@2010YOUY01

Description

@2010YOUY01

Describe the bug

Here is Q1 select nvl(v1, 0.5) from tt;
then let Q1 union a empty set, two queries should have the same result, but it's returning a different result.
Looks like it's an incorrect casting (cast double to int), since double has higher precision, it should cast in the opposite direction

Reproducer in datafusion-cli

DataFusion CLI v40.0.0
> create table tt(v1 int);

0 row(s) fetched.
Elapsed 0.072 seconds.

> insert into tt values (1),(null);

+-------+
| count |
+-------+
| 2     |
+-------+
1 row(s) fetched.
Elapsed 0.051 seconds.

> select nvl(v1, 0.5) from tt;

+-------------------------+
| nvl(tt.v1,Float64(0.5)) |
+-------------------------+
| 1.0                     |
| 0.5                     |
+-------------------------+
2 row(s) fetched.
Elapsed 0.015 seconds.

> select nvl(v1, 0.5) from tt
union all
select null where false;

+-------------------------+
| nvl(tt.v1,Float64(0.5)) |
+-------------------------+
| 1                       |
| 0                       |
+-------------------------+
2 row(s) fetched.
Elapsed 0.007 seconds.

// Example: two number have different type, cast to the type with higher precision/range
> select 1 + 0.5;
+-------------------------+
| Int64(1) + Float64(0.5) |
+-------------------------+
| 1.5                     |
+-------------------------+
1 row(s) fetched.
Elapsed 0.008 seconds.

To Reproduce

No response

Expected behavior

No response

Additional context

Found by SQLancer #11030

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions