Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: incorrect batch query result when grouping by a non-continuous subset of table pk #14620

Closed
stdrc opened this issue Jan 17, 2024 · 0 comments · Fixed by #14621
Closed

bug: incorrect batch query result when grouping by a non-continuous subset of table pk #14620

stdrc opened this issue Jan 17, 2024 · 0 comments · Fixed by #14621
Labels
type/bug Something isn't working
Milestone

Comments

@stdrc
Copy link
Member

stdrc commented Jan 17, 2024

Describe the bug

No response

Error message/log

No response

To Reproduce

create table t (a int, b int, c int, primary key (a, b, c));
insert into t values (1, 1, 1), (1, 2, 3), (1, 3, 1);

select count(*) from t group by a, c; -- correct
select a, c, count(*) from t group by a, c; -- correct
select a, c, first_value(b order by b), count(*) from t group by a, c; -- correct
select a, c, first_value(b order by b), count(*) from t group by a, c having a = 1; -- incorrect!!!

Explain messages of the last two queries above:

 BatchExchange { order: [], dist: Single }
 └─BatchSortAgg { group_key: [t.a, t.c], aggs: [first_value(t.b order_by(t.b ASC)), count] }
   └─BatchExchange { order: [t.a ASC, t.c ASC], dist: HashShard(t.a, t.c) }
     └─BatchSort { order: [t.a ASC, t.c ASC] }
       └─BatchScan { table: t, columns: [a, b, c] }
 BatchSortAgg { group_key: [t.a, t.c], aggs: [first_value(t.b order_by(t.b ASC)), count] }
 └─BatchExchange { order: [t.a ASC, t.b ASC, t.c ASC], dist: Single }
   └─BatchScan { table: t, columns: [a, b, c], scan_ranges: [a = Int32(1)] }

It seems that the LogicalAgg is wrongly converted to BatchSortAgg when group by column is a non-continuous subset of table pk (input order), and when having clause is added, the optimizer generates a local batch plan without the BatchSort before Exchange.

Expected behavior

No response

How did you deploy RisingWave?

No response

The version of RisingWave

No response

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something isn't working
Projects
None yet
1 participant