pingcap / pingcap/tidb

use pk info to reduce redundant group by columns

Open
#55,203 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
Consider the case that
`select a.pk, a.col1, a.col2, a.col3, count(*) from a join b where a.id = b.id group by a.pk, a.col1, a.col2, a.col3`

TiDB will generate a plan that use `a.pk, a.col1, a.col2, a.col3` as the group by key. In fact since a.pk is pk from table a, the sql can be optimized as
`select a.pk, first_row(a.col1), first_row(a.col2), first_row(a.col3), count(*) from a join b where a.id = b.id group by a.pk`

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.