Skip to content

Incorrect result returned by a group by query (SQLancer-TLP) #11748

@2010YOUY01

Description

@2010YOUY01

Describe the bug

The below query should return an empty set, since having is evaluated after aggregation, when it's predicate is false, the final result should always be empty.
I have also checked in DuckDB and PostgreSQL, and they all return an empty set.

Reproducer in datafusion-cli

DataFusion CLI v40.0.0
> create table t1(v1 int);
0 row(s) fetched.
Elapsed 0.085 seconds.

> SELECT AVG(v1) FROM t1 GROUP BY false having false;
+------------+
| avg(t1.v1) |
+------------+
|            |
+------------+
1 row(s) fetched.
Elapsed 0.095 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
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions