pingcap / pingcap/tidb

Eliminate the agg if possible when it's built

Open
#45,193 2 comments 0 reactions 1 assignee Claimed by @hawkingrei View on GitHub
sig/planner type/enhancement
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Enhancement

Currently, we eliminate the aggregation after it's built.

So consider the following case:
`select max(a) from t group by b`
The `b` is a unique & not null column. So the aggregation can be eliminated. But we will allocate a new column for `max(a)`(such as col#x, for example). Then we get a projection `proj(a->col#x(which is max(a))` This projection cannot be eliminated in the whole optimization phase because we'll need to re-construct the output columns for the whole parent plan operators of the projection to replace the column `col#x` to column `a`.
This breaks the rule that an optimization rule should only affect a small part of the plan tree.

This projection might block other optimizations, such as that this projection cuts a join tree into two parts, so the join reorder cannot be performed as much as we can.

We need to eliminate the aggregation as early as possible to avoid such cases.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.