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

Reuse order by columns for ARRAY_AGG #55496

Open
k-lukas opened this issue Jan 27, 2025 · 2 comments
Open

Reuse order by columns for ARRAY_AGG #55496

k-lukas opened this issue Jan 27, 2025 · 2 comments
Labels
type/enhancement Make an enhancement to StarRocks

Comments

@k-lukas
Copy link
Contributor

k-lukas commented Jan 27, 2025

Enhancement

Given a query like this:

select
array_agg(col1 order by colx,coly,colz),
array_agg(col2 order by colx,coly,colz),
...
array_agg(coln order by colx,coly,colz)
from table
group by id

Notice array_agg is called N times with the same ordering columns colx, coly, colz.

Currently, in the pre-aggregation the ordering columns are copied into each array_agg result, then exchanged to other nodes, then sorted and then the ordering columns are deleted. This leads to high memory consumption since the ordering columns are duplicated for each invocation of array_agg (N times in the example).

SR should reuse the ordering columns if they are reused for multiple array_agg calls. I believe this is already done for window aggregations.

@k-lukas k-lukas added the type/enhancement Make an enhancement to StarRocks label Jan 27, 2025
@LiShuMing
Copy link
Contributor

Yep, it's a good idea.

Maybe we can add one rule in optimizer to transform the expected plan for reducing the repeated order by

@k-lukas
Copy link
Contributor Author

k-lukas commented Feb 5, 2025

Interesting, how would this work in the optimizer? I mainly looked at the aggregation implementation in the BE and there it looked quite hard to have some shared aggregation state between multiple array_agg functions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement Make an enhancement to StarRocks
Projects
None yet
Development

No branches or pull requests

2 participants