refactor: simplify 2-stage, remove duplicates
- Refactor 2-stage aggregation pipeline, so it is easier to read and work with
- add logic for removing duplicate grouping expressions and
aggregates from local stage:
select sum(a), sum(a) from t
We should compute only one aggregate at local stage.
The same goes for grouping expressions:
select sum(distinct a) from t group by a
At local stage we must use a
only once in projection.
This refactoring is a part of larger having
mr. You can take a look how having is handled in the 2-stage pipeline there
Edited by Arseniy Volynets