pingcap / pingcap/tidb

If group by key contains constant columns, the constant columns should be removed from group by key

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

Description

## Enhancement
Consider the following cases
```
1. select count(*), id from test where id = 1 group by id
2. select count(*), id, value from test where id = 1 group by id, value
```
If there is no implict cast in expr `id = 1`, then `id` should be a constant column after filter, it can be removed from the group by keys, that is the optimizer should rewrite the sql to
```
1. select count(*), first_row(id) from test where id = 1
2. select count(*), first_row(id), value from test where id = 1 group by value
```

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.