Skip to content

subquery unnesting duplicate row bug #858

@skyzh

Description

@skyzh
> create table t1(v1 int, v2 int);
created
in 0.028s
> create table t2(v3 int, v4 int);
created
in 0.009s
> insert into t1 values (1, 100), (2, 200), (3, 300), (3, 300);
2024-12-01T06:02:14.883496Z  INFO executor: risinglight::storage::secondary::transaction: RowSet #0 flushed, DV  flushed id=14 name="insert"
4 rows inserted
in 0.047s
> insert into t2 values (2, 200), (3, 300);
2024-12-01T06:02:29.516292Z  INFO executor: risinglight::storage::secondary::transaction: RowSet #1 flushed, DV  flushed id=11 name="insert"
2 rows inserted
in 0.044s
> select * from t1 where (select sum(v4) from t2 where v3 = v1) > 100;
+---+-----+
| 2 | 200 |
| 3 | 300 |
+---+-----+
in 0.038s

The result should be

2 200
3 300
3 300

which means that rule 8/9 doesn't seem correct.

// Figure 4 Rule (8)
rw!("pushdown-apply-group-agg";
"(apply inner ?left (hashagg ?keys ?aggs ?right))" =>
// ?new_keys = ?left || ?keys
{ extract_key("(hashagg ?new_keys ?aggs (apply inner ?left ?right))") }
// FIXME: this rule is correct only if
// 1. all aggregate functions satisfy: agg({}) = agg({null})
// 2. the left table has a key
),
// Figure 4 Rule (9)
rw!("pushdown-apply-scalar-agg";
"(apply inner ?left (agg ?aggs ?right))" =>
// ?new_keys = ?left
{ extract_key("(hashagg ?new_keys ?aggs (apply left_outer ?left ?right))") }
// FIXME: this rule is correct only if
// 1. all aggregate functions satisfy: agg({}) = agg({null})
// 2. the left table has a key
),

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions