pingcap / pingcap/tidb

suboptimal plan for mpp semi-join

Open
#64,118 1 comment 0 reactions 0 assignees 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

Please answer these questions before submitting your issue. Thanks!

### 1. Minimal reproduce step (Required)
data of big table, and you can use load data in the following sql to import. [3k.sql](https://github.com/user-attachments/files/23122702/3k.sql)

```
drop table if exists tbig, tsmall;
create table tsmall(c1 int, c2 int);
create table tbig(c1 int, c2 int);
load data local infile '/home/guojiangtao/tmp/3k.sql' into table tbig fields terminated by ' ';
insert into tsmall values(1, 1);
alter table tbig set tiflash replica 1;
alter table tsmall set tiflash replica 1;
set tidb_isolation_read_engines = 'tiflash';
explain select * from tsmall where exists (select 1 from tbig where tbig.c1 = tsmall.c1);
```

### 2. What did you expect to see? (Required)
the small table should be broadcasted to compute the hashjoin instead of the big table.

### 3. What did you see instead (Required)
```
mysql> explain select * from tsmall where exists (select 1 from tbig where tbig.c1 = tsmall.c1);
+--------------------------------------+----------+--------------+---------------+-----------------------------------------------------------------------------+
| id | estRows | task | access object | operator info |
+--------------------------------------+----------+--------------+---------------+-----------------------------------------------------------------------------+
| TableReader_37 | 7992.00 | root | | MppVersion: 3, data:ExchangeSender_36 |
| └─ExchangeSender_36 | 7992.00 | mpp[tiflash] | | ExchangeType: PassThrough |
| └─HashJoin_35 | 7992.00 | mpp[tiflash] | | semi join, left side:Selection_20, equal:[eq(test.tsmall.c1, test.tbig.c1)] |
| ├─ExchangeReceiver_24(Build) | 9990.00 | mpp[tiflash] | | |
| │ └─ExchangeSender_23 | 9990.00 | mpp[tiflash] | | ExchangeType: Broadcast, Compression: FAST |
| │ └─Selection_22 | 9990.00 | mpp[tiflash] | | not(isnull(test.tbig.c1)) |
| │ └─TableFullScan_21 | 10000.00 | mpp[tiflash] | table:tbig | keep order:false, stats:pseudo |
| └─Selection_20(Probe) | 9990.00 | mpp[tiflash] | | not(isnull(test.tsmall.c1)) |
| └─TableFullScan_19 | 10000.00 | mpp[tiflash] | table:tsmall | keep order:false, stats:pseudo |
+--------------------------------------+----------+--------------+---------------+-----------------------------------------------------------------------------+
9 rows in set (0.00 sec)
```
### 4. What is your TiDB version? (Required)
```
mysql> select tidb_version();
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version() |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v9.0.0-beta.2.pre-510-gc37a89f
Edition: Community
Git Commit Hash: c37a89fa7bca2f34aeff7d46df07a1c21cc094c2
Git Branch: HEAD
UTC Build Time: 2025-09-17 03:01:26
GoVersion: go1.23.12
Race Enabled: false
Check Table Before Drop: false
Store: tikv
Kernel Type: Classic |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
```

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.