Skip to content

Incorrect query results for GROUP BY with UNIQUE constraint #21507

@neilconway

Description

@neilconway

Describe the bug

$ cat ~/groupby_unique_repro.sql
CREATE TABLE t(a INT, b INT, c INT, UNIQUE(a));
INSERT INTO t VALUES (1, 10, 100), (NULL, 20, 200), (NULL, 30, 300);
SELECT a, SUM(c) AS total FROM t GROUP BY a, b ORDER BY a;
DROP TABLE t;

$ cargo run --bin datafusion-cli -- -f ~/groupby_unique_repro.sql
    Finished [`dev` profile [unoptimized + debuginfo]](https://doc.rust-lang.org/cargo/reference/profiles.html#default-profiles) target(s) in 0.16s
     Running `target/debug/datafusion-cli -f /Users/neilconway/groupby_unique_repro.sql`
DataFusion CLI v53.0.0
0 row(s) fetched.
Elapsed 0.044 seconds.

+-------+
| count |
+-------+
| 3     |
+-------+
1 row(s) fetched.
Elapsed 0.034 seconds.

+------+-------+
| a    | total |
+------+-------+
| 1    | 100   |
| NULL | 500   |
+------+-------+
2 row(s) fetched.
Elapsed 0.027 seconds.

$ duckdb -f ~/groupby_unique_repro.sql
┌───────┬────────┐
│   a   │ total  │
│ int32 │ int128 │
├───────┼────────┤
│     1 │    100 │
│  NULL │    200 │
│  NULL │    300 │
└───────┴────────┘

To Reproduce

No response

Expected behavior

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions