pingcap / pingcap/tidb

Planner generated plan that shuffles on single agg key

Open
#35,417 0 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

## Bug Report

```sql
create table foo(a int, b int, c int, d int);
alter table foo set tiflash replica 2;
explain select b*10 as e, c, count(d) from foo group by e,c;
+----------------------------------------+----------+-------------------+---------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
| id | estRows | task | access object | operator info |
+----------------------------------------+----------+-------------------+---------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Projection_4 | 8000.00 | root | | mul(tpch_100.foo.b, 10)->Column#7, tpch_100.foo.c, Column#6 |
| └─TableReader_31 | 8000.00 | root | | data:ExchangeSender_30 |
| └─ExchangeSender_30 | 8000.00 | batchCop[tiflash] | | ExchangeType: PassThrough |
| └─Projection_26 | 8000.00 | batchCop[tiflash] | | Column#6, tpch_100.foo.b, tpch_100.foo.c |
| └─HashAgg_27 | 8000.00 | batchCop[tiflash] | | group by:Column#13, tpch_100.foo.c, funcs:sum(Column#14)->Column#6, funcs:firstrow(Column#15)->tpch_100.foo.b, funcs:firstrow(tpch_100.foo.c)->tpch_100.foo.c |
| └─ExchangeReceiver_29 | 8000.00 | batchCop[tiflash] | | |
| └─ExchangeSender_28 | 8000.00 | batchCop[tiflash] | | ExchangeType: HashPartition, Hash Cols: [name: tpch_100.foo.c, collate: binary] |
| └─HashAgg_9 | 8000.00 | batchCop[tiflash] | | group by:Column#23, Column#24, funcs:count(Column#21)->Column#14, funcs:firstrow(Column#22)->Column#15 |
| └─Projection_35 | 10000.00 | batchCop[tiflash] | | tpch_100.foo.d, tpch_100.foo.b, mul(tpch_100.foo.b, 10)->Column#23, tpch_100.foo.c |
| └─TableFullScan_25 | 10000.00 | batchCop[tiflash] | table:foo | keep order:false, stats:pseudo |
+----------------------------------------+----------+-------------------+---------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
10 rows in set (0.16 sec)
```

The exchange `ExchangeType: HashPartition, Hash Cols: [name: tpch_100.foo.c, collate: binary]`. The hash cols should be 2 columns instead of a single column `c`.

It is not wrong plan, but an inefficient plan, which may generate data skew.

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.